0

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!

tooty44
  • 6,829
  • 9
  • 27
  • 39
  • `Try 2` produces a plot for me. (obviously Try 1 will not) – user20650 May 14 '18 at 21:45
  • I don't think you're using the `AirPassengers` data in the first example, you're using whatever `x` and `y` are in your workspace. Are you sure you don't have an error on the `glmnet(x, y)` line? If not, what did you define `x` and `y` as? – Gregor Thomas May 14 '18 at 22:10
  • AirPassengers doesn't have x and y components. What vignette are you working with? – IRTFM May 14 '18 at 23:12
  • This is the vignette I was referring to: https://web.stanford.edu/~hastie/glmnet/glmnet_alpha.html – tooty44 May 15 '18 at 02:10

1 Answers1

1

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.

alice m w
  • 151
  • 6
  • Yes, that was the vignette that I was referring to! I tried "Try 2" with just the command line and it worked. For some reason, running the above code on an RStudio doesn't seem to be working and returns the aforementioned error. – tooty44 May 15 '18 at 02:09