0

I am supposed to find the intercept term using Ridge Regression model.

"Use Ridge Regression with alpha = 0 to and lambda = 0, divorce as the response and all the other variables as predictors."

I know I'm supposed to convert my data to matrix mode and then transform it to fit the glmnet function. I've converted my response to matrix mode, but I'm not sure how to convert all my predictors into matrix mode, too.

set.seed(100)

require(faraway)
require(leaps)
require(glmnet)

mydata = divusa

mymodel = lm(divorce ~ year + unemployed + femlab + marriage + birth + 
military, data=mydata)
summary(mymodel)
.
.
.

y = model.matrix(divorce~.,mydata)

Can anyone help with the code for my x variable? I'm very new to R and finding it very hard to understand it.

delete
  • 75
  • 6

1 Answers1

0

Your y = model.matrix(divorce~.,mydata) actually created your predictor matrix (usually called X). Try

 X = model.matrix(divorce~.,mydata)
 y = mydata$divorce
 glmnet(X,y)
 glmnet(X,y,alpha=0,lambda=0)

I think if you set lambda=0 you're actually doing ordinary regression (i.e., you're setting the penalty to zero, so ridge -> OLS).

Ben Bolker
  • 211,554
  • 25
  • 370
  • 453