univariate_forecast_ml vector of responses and dataframe of predictors and automates

univariate_forecast_ml(
  response,
  predictors,
  model_type,
  n_forecast = 10,
  n_years_ahead = 1,
  control = list(alpha = seq(0.1, 0.9, by = 0.05), lambda = seq(0, 2, by = 0.05), ntree =
    seq(300, 2000, by = 100), mtry = seq(2, 10))
)

Arguments

response

A data frame of responses for the modeling (values to be forecast) containing a "time" column and "dev" column

predictors

A data frame of predictors used for forecasting recruitment

model_type

The type of model used to link predictors to forecasted recruitment. Can be "randomForest", "glmnet"

n_forecast

How many years to use as a holdout / test set

n_years_ahead

How many years ahead to forecast (defaults to 1) 1:n_vars variables, and then results are combined and sorted to remove duplicates

control

a list of the range and steps of tuning parameters to perform a grid search over. This includes alpha (defaults from 0.1 to 0.9, by steps of 0.05) and lambda (defaults from 0 to 2, by steps of 0.05) for glmnet; for randomForest this includes ntree (defaults from 300 to 2000, by steps of 100) and mtry (defaults from 2 to 10, by steps of 1)

Value

a list containing predictions, with elements

  • pred: the predictions

  • vars: the variable values used to fit the models

  • coefs: tidy summaries from each year:iteration. Zeros not included for glmnet

#' @examples response <- data.frame(time = 1:40, dev = rnorm(40))

predictors <- matrix(rnorm(400), ncol = 10) #colnames(predictors) = paste0("X",1:ncol(predictors)) predictors <- as.data.frame(predictors) predictors$time <- 1:40 lm_example <- univariate_forecast_ml(response, predictors, model_type = "glmnet", n_forecast = 10, n_years_ahead = 1)