简体   繁体   中英

Error in cv.lars in R

I have a question regarding the cv.lars . Bellow there is a description for the data I use:

is.numeric(Y$Y1)
[1] TRUE

length(Y$Y1)
[1] 589


dim(Training_XX[7:ncol(Training_XX)])
[1]  589 5677

I have already run lasso using lars package. My code is as follows:

LASSO_1<-lars(as.matrix(X[7:ncol(X)]), 
              Y$Y1,type=c("lasso"), 
              normalize=TRUE, use.Gram=FALSE).

The above procedure seems to run fine. However, when I'm trying to cross-validate for the lambda value, I get the following error:

Error in if (zmin < gamhat) { : missing value where TRUE/FALSE needed

My code for the cross-validation is:

CV<-cv.lars(as.matrix(X[7:ncol(X)]),Y$Y1,use.Gram=FALSE,max.steps=500)
lambda_Y1=CV$index[which.min(CV$cv)]

Does anyone has any idea what's going on? I really don't know what that error means and what's wrong with my data (and or code).

I got the same error, and the problem (at least in my case) was that two columns of my data matrix were equal. It seems lars doesn't handle this well. Just filter columns with very high correlation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM