tooty44
tooty44

Reputation: 7089

Why does R return "object not found" error in plot command for glmnet?

I'm very new to R and was playing with the glmnet package. When I try a toy example following the Stanford vignette, I get an error that says:

Error in print(fit) : object 'fit' not found

I've tried two slightly different toy models to the same result, and was wondering if anyone know if I was missing something obvious?

Try 1:

library(glmnet)
data("AirPassengers")
fit = glmnet(x, y)
plot(fit)

Try 2:

library(glmnet)
fit = glmnet(as.matrix(mtcars[-1]), mtcars[,1])
plot(fit, xvar='lambda')

One thing that I've noticed is that the x, y are not explicitly defined in the first case and in the second case, the data is not explicitly loaded. From what I could gather from the vignette, this shouldn't be a problem but if it is, then any suggestions as to what modifications should be made will be immensely helpful!

Upvotes: 0

Views: 2454

Answers (1)

alice m w
alice m w

Reputation: 151

It looks like you are following this vignette: https://web.stanford.edu/~hastie/glmnet/glmnet_alpha.html

In that tutorial, x and y are loaded with: load("QuickStartExample.RData")

However, in your Try 1, you have not defined x and y. Try 2 works for me.

Upvotes: 1

Related Questions