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
Error in bl_lin_matrix() for bbs-bl with small number of knots #30
The Kronecker product %O% produces an error for bbs with small number of knots, which happens as Cholesky() is called but XtXis not a sparse matrix, see the following MWE
library(mboost)
### kronecker product for matrix-valued responses
data("volcano", package = "datasets")
## estimate mean of image treating image as matrix
image(volcano, main = "data")
x1 <- 1:nrow(volcano)
x2 <- 1:ncol(volcano)
vol <- as.vector(volcano)
## do the model fit with default number of knots
mod <- mboost(vol ~ bbs(x1, df = 3, knots = 10)%O%
bbs(x2, df = 3, knots = 10),
control = boost_control(nu = 0.25))
## do the model fit with very few knots -> model fit gives error
mod <- mboost(vol ~ bbs(x1, df = 3, knots = 3) %O%
bbs(x2, df = 3, knots = 3),
control = boost_control(nu = 0.25))
## error occurs because class(XtX) is "dsyMatrix" (Symmetric Dense Numeric Matrices),
## usually class(XtX) is "dsCMatrix" (Numeric Symmetric Sparse (column compressed) Matrices)
The Kronecker product
%O%
produces an error forbbs
with small number of knots, which happens asCholesky()
is called butXtX
is not a sparse matrix, see the following MWEI think that the problem can be solved by changing line
if (is(XtX, "Matrix") && !extends(class(XtX), "dgeMatrix")) {
https://github.com/boost-R/mboost/blob/master/pkg/mboostPatch/R/bkronecker.R#L80to
if (is(XtX, "Matrix") && !extends(class(XtX), "dgeMatrix") && !extends(class(XtX), "dsyMatrix")) {
which simply excludes the corresponding Matrix-class.
But I don´t know whether there is a nicer or more general way to fix this.