I am attempting to use the lars package with a sparse input feature matrix, but the following fails:
library(Matrix) library(lars) data(diabetes) attach(diabetes) x = as(as.matrix(as.data.frame(x)), 'dgCMatrix') lars(x, y, intercept = FALSE) Error in scale.default(x, FALSE, normx) : > > length of 'scale' must equal the number of columns of 'x' > > More specifically, scale.default fails: normx = new( "dgeMatrix", x = c(1.00000000000004, 1, 1.00000000000009, 1.00000000000001, 1.00000000000001, 0.999999999999992, 1.00000000000004, 0.999999999999975, 1.00000000000006, 1.00000000000006), Dim = c(1L, 10L), Dimnames = list(NULL, c("x.age", "x.sex", "x.bmi", "x.map", "x.tc", "x.ldl", "x.hdl", "x.tch", "x.ltg", "x.glu")), factors = list() ) scale(x, FALSE, normx) The problem is that this check fails because is.numeric(normx) is FALSE: if (is.numeric(scale) && length(scale) == nc) So, the error message is misleading. In fact length(scale) is the same as nc. At a minimum, the error message needs to be repaired; do we also want to attempt as.numeric(normx) (which I believe would have allowed scale to work in this case)? (I'm aware that there's some import issues in lars, as the offending line to create normx *should* work, as is.numeric(sqrt(drop(rep(1, nrow(x)) %*% (x^2)))) is TRUE -- it's simply that lars doesn't import the appropriate S4 methods) Michael Chirico [[alternative HTML version deleted]] ______________________________________________ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel