3

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).

agstudy
  • 119,832
  • 17
  • 199
  • 261
Danai C.
  • 125
  • 4
  • 8
  • 1
    Not an answer to your question, but try using [glmnet](http://cran.r-project.org/web/packages/glmnet/index.html), instead. It's got the lasso (as a special case of the elasticnet), and is much faster. – Steve Lianoglou Feb 23 '13 at 17:02
  • You are so right!!! I didn't think about it... – Danai C. Feb 24 '13 at 18:28
  • I just set a=1 and I get lasso, is that right? Do you now if the glmnet lasso and lars lasso give same or very similar results (they should)? And the computational time...lars takes so long!!GLMNET is very fast Thank you so much! – Danai C. Feb 24 '13 at 18:30
  • 1
    Read the docs in `?glmnet`, it is quite specific about the value of `alpha` required to get the lasso. Also, about the similarity between the two algorithms, this can also be easily verified with a few small test examples. It's not that I do not want to answer your questions, but when it's easy to answer them yourself, you should prefer that over trusting some random person over the internet, like me. Enjoy the new found speed! :-) – Steve Lianoglou Feb 25 '13 at 04:58

2 Answers2

1

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.

0

I got the same error when I forgot to scale my predictor variables.

  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 30 '23 at 15:31