I am really struggling with a homework assignment I have regarding LASSO and the ex-post tuning of the hyperparameters. I have decided to use R and specifically the Caret package. My first column represents the actual value for each quarter, whereas the other columns the forecasted values by different people (each column is a different forecaster). I have already split the data set in a training and test set according to a 20-quarters rolling window, and I am now trying to choose the lambda that minimises the RMSE ex-post. I have already defined the grid. I keep getting many mistakes however, especially the following: "Error: index should be lists of integers."
So far I have got this:
X <- selForcsts[, -1]
y <- selForcsts[, 1]
y <- as.numeric(unlist(y))
ctrl <- trainControl(method = "timeslice", index = list(train = train_indexes, test = test_indexes))
model <- train(
x = X,
y = y,
method = "glmnet",
tuneGrid = param_grid,
trControl = ctrl,
metric = "RMSE"
)
I think that's because my training and test indexes are basically a list of vectors, with each vector holding the indices for the respective part of the rolling window at that point in time. Can anybody maybe help a bit?