bob
bob

Reputation: 629

Issue running glmnet() for mtcars dataset

Whenever I run glmnet(mpg ~ ., data = mtcars, alpha=1) (from the glmnet package) I get the following error:

"Error in glmnet(mpg ~ ., data = mtcars, alpha = 1) : unused argument (data = mtcars)"

Any ideas for how to deal with this?

I think its because the glmnet() function is supposed to take in x and y as separate arguments. If I need separate x and y arguments, how would I write the formula so that glmnet::glmnet() runs for all variables of mtcars?

Upvotes: 0

Views: 318

Answers (1)

Zelazny7
Zelazny7

Reputation: 40628

As the commenter suggests you need to use the glmnet method like so:

fit <- glmnet(as.matrix(mtcars[-1]), mtcars$mpg, alpha=1)

plot(fit)

enter image description here

Upvotes: 1

Related Questions