I'd like to pick the optimal lambda and alpha using the Glmnet package. I'm open to all models (Ridge, Lasso, Elastic). I'm assuming some out of sample error/cross validation is the best model selection criteria.
Macro <- read.csv("P:/Earnest/Old/R/Input.csv")
x <- Macro[1:13,3:21]
x <- as.matrix(x)
y <- Macro[1:13,2:2]
y <- as.matrix(y)
t <- Macro[14:14,3:21]
t <- as.matrix(t)
Right now, I'm using the following code. The below code presupposes alpha = .5 (elastic), and that lambda.min is the ideal lambda.
fit <-glmnet(x, y, alpha = .5, lambda = NULL)
cv.fit=cv.glmnet(x,y, alpha = .5, lambda = NULL)
min <- cv.fit$lambda.min
predict(fit ,t, s = min)
Questions: How do I know what is the ideal alpha and lambda? What code can I use to test various lambda/alpha combinations, to find the best out of sample error. Is this the right approach and utilization of Glmnet? What questions am I not considering that should be?
glmnet
inR
explains rather clearly how to do this, so reading it would be a good place to begin. $\endgroup$