x
is a numeric matrix and y
is a numeric vector:
x = structure(c(53, 36, 51, 51, 54, 35, 56, 60, 60, 60, 35, 59, 62,
36, 38, 61, 64, 60, 92, 92, 62, 42, 65, 89, 62, 61, 62, 62, 62,
35, 35, 37, 3.32, 3.1, 3.18, 3.39, 3.2, 3.03, 4.78, 4.72, 4.6,
4.53, 2.9, 4.4, 4.31, 4.27, 4.41, 4.39, 7.32, 7.32, 7.45, 7.27,
3.91, 3.75, 6.48, 6.7, 4.3, 4.02, 4.02, 3.98, 4.39, 2.75, 2.59,
2.73, 3.42, 3.26, 3.18, 3.08, 3.41, 3.03, 4.57, 4.72, 4.41, 4.53,
2.95, 4.36, 4.42, 3.94, 3.49, 4.39, 6.7, 7.2, 7.45, 7.26, 4.08,
3.45, 5.8, 6.6, 4.3, 4.1, 3.89, 4.02, 4.53, 2.64, 2.59, 2.59), .Dim = c(32L,
3L), .Dimnames = list(NULL, c("PT", "ITP", "PP")))
y = c(29, 24, 26, 22, 27, 21, 33, 34, 32, 34, 20, 36, 34, 23, 24,
32, 40, 46, 55, 52, 29, 22, 31, 45, 37, 37, 33, 27, 34, 19, 16,
22)
Without intercept
Code:
fit.ridge = glmnet(x, y, alpha = 0, intercept = FALSE)
plot(fit.ridge, xvar = "lambda", label = TRUE)
cv.ridge = cv.glmnet(x, y, alpha = 0, intercept = FALSE)
plot(cv.ridge)
coef(cv.ridge)
#4 x 1 sparse Matrix of class "dgCMatrix"
# 1
#(Intercept) .
#PT 7.877576e-36
#ITP 7.371832e-35
#PP 7.871337e-35
With intercept
Code:
fit.ridge = glmnet(x, y, alpha = 0, intercept = TRUE)
plot(fit.ridge, xvar = "lambda", label = TRUE)
cv.ridge = cv.glmnet(x, y, alpha = 0, intercept = TRUE)
plot(cv.ridge)
coef(cv.ridge)
#4 x 1 sparse Matrix of class "dgCMatrix"
# 1
#(Intercept) 5.821492
#PT 0.194511
#ITP 1.420347
#PP 1.884496
Why do I get these absurd coefficients?
plot(my_glmnet)
when stuff like this happens. Is the optimal lambda from the no-intercept model also equal to the maximum lambda in the path? In other words, ismax(cv.ridge$lambda)
the same ascv.ridge$lambda.1se
? $\endgroup$alpha = 0
you are doing ridge regression (not LASSO), so I replaced the tag. $\endgroup$