When I try to use cv.glmnet to cv.glmnet my data, I got an error
Error in apply(nz, 1, median) : dim(X) must have a positive length
In the line below, y is a level 3 variable (I used as.factor() for the original variable). The predictor x consists of one continuous variable (magician) and some factor variables (again, as.factor() for categorical variables). As suggested by another post on the Internet, my code for collecting all the predictors was as follows:
xfactors <- model.matrix(ANYHEART ~ mrace+frace+sex+smoke+alcohol+bmi+dbt+ben+tol+ xyl+car+chl+met+per+tca+tce+sto+chlor+arom)[,-1] x <- as.matrix(data.frame(mage, xfactors)) y <- as.factor(ANYHEART) fit = glmnet(x, y, family="multinomial", type.multinomial="grouped")
Following cross validation using:
cvfit <- cv.glmnet(x, y, family="multinomial", type.multinomial="grouped")
I was wondering if anyone had encountered this problem before and what could be the possible reasons.
r glmnet
user3723736
source share