1
$\begingroup$

I am trying to make forecasts for a LASSO model obtained from the cv.glmnet() function ("glmnet" package). I most frequently make forecasts using the predict() function (in the "stats" package). For many different type of fits (like those from the Arima() function in the "forecast" package) you just just add an additional parameter such as n.ahead to get multiple step ahead predictions. I am having trouble finding an analog for glmnet fits.

For example, with some simple data:

train.x <- data.frame(
  x1 = rnorm(n = 100, mean = 0, sd = 2),
  x2 = rnorm(n = 100, mean = 15, sd = 4),
  x3 = runif(n = 100, min = -1, max = 1),
  x4 = runif(n = 100, min = -1, max = 1),
  x5 = runif(n = 100, min = -1, max = 1)
)

train.y <- train.x$x1

test.x <- data.frame(
  x1 = rnorm(n = 5, mean = 0, sd = 2),
  x2 = rnorm(n = 5, mean = 15, sd = 4),
  x3 = runif(n = 5, min = -1, max = 1),
  x4 = runif(n = 5, min = -1, max = 1),
  x5 = runif(n = 5, min = -1, max = 1)
)

I fit a LASSO model:

fit.lasso <- cv.glmnet(x = as.matrix(train.x), y = train.y)

And I make predictions for the out-of-sample observations (test.x):

predictions <- predict(fit.lasso, newx = as.matrix(test.x))

And I try to make predictions for 10 time steps ahead:

predictions_ahead <- predict(fit.lasso, newx = as.matrix(test.x), n.ahead = 10)

But these predictions are identical:

    predictions    predictions_ahead 

    0.5885060      0.5885060
    1.9350460      1.9350460
   -2.2762480     -2.276240
    0.5067405      0.5067405
    0.3846506      0.3846506

Is there a simple way to get predictions for future time steps?

Do I need to change my Xs into ts objects and predict their future values? And then just use the fitted model on those instead of making future predictions directly?

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.