EdwinKipruto / mfp2

3 stars 0 forks source link

Bug in predict.mfp? #55

Closed gregorsteiner closed 1 year ago

gregorsteiner commented 1 year ago

I think I found a bug in predict.mfp2(). See the following code:

# load data
data(wage1, package = "wooldridge")
wage <- wage1

# set up model matrix
X <- model.matrix(lwage ~ -1 + educ + exper, data = wage)

# fit with mfp
fit.mfp <- mfp2::mfp2(X, wage$lwage, verbose = FALSE)

d.plot <- expand.grid(exper = mean(wage$exper),
                      educ = 1:20)
d.plot$mfp <- predict(fit.mfp, newdata = d.plot)

Here, I get an error in the predict function. I think the reason is that exper is constant and therefore transform_vector_fp() does not add the second power because it thinks it is a binary variable. Is this intended? I think this check should only be necessary when fitting a model, but not when preparing newdata for prediction.

I think a quick way to fix it could be to add a ... in prepare_newdata_for_predict() so that I could add check_binary = FALSE when calling predict(). But not sure if this is the best way to deal with this.

EdwinKipruto commented 1 year ago

Hi Gregory,

Thanks for noticing the error. prepare_newdata_for_predict() has an argument check_binary and have set it to FALSE.