boost-R / mboost

Boosting algorithms for fitting generalized linear, additive and interaction models to potentially high-dimensional data. The current relase version can be found on CRAN (http://cran.r-project.org/package=mboost).
73 stars 27 forks source link

argument prediction is not passed in %O% #23

Closed sbrockhaus closed 8 years ago

sbrockhaus commented 8 years ago

In the args of hyper_bbs() the argument prediction is used to tell the base-learner when the model is fitted and when it is just used for prediction. I just realized that this argument is not passed when the base-learner is used in combination with %O%, as the argument is not passed in newX1 and newX2, in the code lines https://github.com/hofnerb/mboost/blob/master/pkg/mboostPatch/R/bkronecker.R#L244 https://github.com/hofnerb/mboost/blob/master/pkg/mboostPatch/R/bkronecker.R#L254

I think the bug can be fixed by setting

X1 <- newX1(as.data.frame(mf[bl1$get_names()]), prediction = args$prediction)
X2 <- newX2(as.data.frame(mf[bl2$get_names()]), prediction = args$prediction)

respectively.

In the following, a MWE is given were the problem occurs in predict().

library(mboost)

### kronecker product for matrix-valued responses
data("volcano", package = "datasets")

## estimate mean of image treating image as matrix
x1 <- 1:nrow(volcano)
x2 <- 1:ncol(volcano)

vol <- as.vector(volcano)
mod <- mboost(vol ~ bbs(x1, df = 3, knots = 10)%O%
                bbs(x2, df = 3, knots = 10),
              control = boost_control(nu = 0.25))

## use predict() with newdata that extrapolates the original variables  
## does not work as the arument 'prediciton' is not passed in %O%
temp <- matrix(predict(mod, newdata=list(x1=x1, x2=1:62)), nrow = nrow(volcano))

I suspect, that the same issue applies for %X% and %+%, as in those functions prediction is not passed explicitly either, see e.g. , https://github.com/hofnerb/mboost/blob/master/pkg/mboostPatch/R/bl.R#L1088 However, I did not check in that cases.