Skip to content

Commit

Permalink
fix issue #1547
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-buerkner committed Nov 8, 2023
1 parent 226a95a commit a00c56a
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions R/data-predictor.R
Original file line number Diff line number Diff line change
Expand Up @@ -997,7 +997,7 @@ get_model_matrix <- function(formula, data = environment(formula),

# convenient wrapper around mgcv::PredictMat
PredictMat <- function(object, data, ...) {
data <- rm_attr(data, "terms")
data <- sm_prepare_data(object, data)
out <- mgcv::PredictMat(object, data = data, ...)
if (length(dim(out)) < 2L) {
# fixes issue #494
Expand All @@ -1008,6 +1008,13 @@ PredictMat <- function(object, data, ...) {

# convenient wrapper around mgcv::smoothCon
smoothCon <- function(object, data, ...) {
data <- sm_prepare_data(object, data)
mgcv::smoothCon(object, data = data, ...)
}

# mgcv doesn't handle a lot of special data types well
# need to prepare these variables manually beforehand
sm_prepare_data <- function(object, data) {
data <- rm_attr(data, "terms")
vars <- setdiff(c(object$term, object$by), "NA")
for (v in vars) {
Expand All @@ -1019,7 +1026,7 @@ smoothCon <- function(object, data, ...) {
data[[v]] <- as.numeric(data[[v]])
}
}
mgcv::smoothCon(object, data = data, ...)
data
}

# Aid prediction from smooths represented as 'type = 2'
Expand Down

0 comments on commit a00c56a

Please sign in to comment.