On this page

Fit expanding training windows and score the predictions of the survey index against time steps that the fits did not see.

Usage

hindcast_model(
  x,
  model = c("acl", "alscl"),
  horizon = 1,
  nfolds = 3,
  min_train = 3,
  ncores = 1,
  nstarts = NULL,
  silent = TRUE,
  save_fits = FALSE,
  ...
)

Arguments

ArgumentDefaultDescription
xrequired

The input bundle of the fit, as accepted by run_acl() or run_alscl().

modelc("acl", "alscl")

Model to fit, "acl" (default) or "alscl". Letter case does not matter.

horizon1

Positive integer; number of model time steps predicted from each forecast origin. A time step is a quarter for quarterly inputs.

nfolds3

Number of forecast origins, the last eligible ones. Each origin is the last training time step of its fold and must leave min_train training time steps before it and horizon time steps after it; asking for more origins than are available is an error.

min_train3

Minimum number of training time steps, at least two.

ncores1

Maximum number of socket workers that fit the folds in parallel; each fold uses one worker.

nstartsNULL

Independent starts per fold, run one after another within the fold. NULL uses the setting given in the bundle, otherwise one.

silentTRUE

Suppress the progress messages of the fits; the warnings of each fold are still recorded in diagnostics.

save_fitsFALSE

TRUE returns the training fit of each fold as a saved fit; recipes, training settings and start diagnostics are kept either way.

...…

Named arguments of run_acl() or run_alscl() that override those of the bundle; a list argument replaces the whole corresponding list.

Value

predictions has one row per length bin, time step and fold, with the observed values, the model and naive predictions on the log scale, the errors, the scaling denominators and whether the cell is scored. scores gives, by horizon, the paired log root mean square error (RMSE) and mean absolute error (MAE), the log mean absolute scaled error (MASE) and the counts. diagnostics, recipes, settings, start_diagnostics and process_paths record the status, failures, warnings and the settings needed to reproduce each fold; with save_fits = TRUE, fits holds the training fits.

Details

The folds use the last eligible forecast origins. Each origin is the last time step of its training data and leaves at least min_train training time steps and the full horizon. Each fold fits only the truncated data, and no fit to the full series supplies its starts. Future log recruitment and log F deviations follow the conditional mean of their fitted AR(1) process, and the population projected from them gives plug-in predictions of the survey index; these are not marginal predictive means, and no predictive intervals are given. The projection keeps the weights and maturity of the last training time step and the survey catchability specified for the fit. A natural mortality rate by age and time step is supplied for the complete time grid. Each training fit uses the columns up to its forecast origin, and the prediction uses the columns of the held-out time steps. Survey catchability by length and time step is treated the same way. A map that fixes or ties the time-varying process deviations is rejected. Folds whose fit fails or does not pass the numerical checks stay in the results but are not scored.

Scores use the held-out positive observations that have both a model and a naive prediction. The naive (persistence) forecast holds the last positive training observation of each length bin constant. Log MASE divides each absolute log error by the mean absolute log change between adjacent training time steps of the same length bin, using only pairs of consecutive positive observations, so gaps are not closed up. A zero or undefined denominator leaves the scaled score missing. ncores runs folds in parallel; the starts and the standard errors of a fold are computed one after another. Choose starting values and assumptions without looking at the held-out data.

Additional details from R help

Each fold uses only the data up to its forecast origin, and no fit to the complete data is used to start the folds. The recruitment and F deviations of the predicted time steps are the AR(1) conditional means on the log scale, the last fitted deviation times phi to the power of the forecast horizon, where phi is the fitted AR(1) correlation over time. The predictions keep the scalar parameters of the training fit and the specified survey catchability. A natural mortality rate by age and time step is supplied for the complete time grid. Each training fit uses the columns up to its forecast origin, and the prediction uses the columns of the held-out time steps. The same holds for survey catchability supplied by length and time step. project_model() advances the population, with the weights and maturity of the last training time step repeated; they do not affect the predicted survey numbers. The predictions follow one conditional path of the log processes and are not marginal predictive means, and no predictive intervals or probability scores are given.

Training fits must pass the numerical checks; failed fits and prediction errors stay in diagnostics and are not scored. Maps of dev_log_R and dev_log_F must be absent, NULL or identity factors, because fixed or tied deviations over time do not say how future deviations are constrained; identity maps are cut to each training window. Maps of the initial state are accepted. A map, scalar setting or starting value that was tuned on the held-out data still carries information from it into the validation.

The naive forecast keeps the latest positive training observation of each length bin. The log RMSE and log MAE of the model and of the naive forecast use the same positive held-out cells, those with both predictions. log_MASE divides each absolute log error by the mean absolute log change between adjacent time steps of that length bin in the training window. Only pairs of consecutive positive observations count, and time steps with missing or zero observations are kept, not removed. A zero scale or no such pair gives no scaled score for that cell. Overlapping folds are scored as separate predictions by origin and horizon, which are not independent observations.

Examples

Run the setup before the example. Fitting examples require an R-compatible C++ toolchain; simulation and export examples may write files.

Example setup
library(ALSCL)
library(ggplot2)
library(patchwork)
data("YTF_example")
x <- YTF_example
inputs <- x[c("data.CatL", "data.wgt", "data.mat")]
dat <- x$data.CatL
validation <- hindcast_model(YTF_example, model = "acl", horizon = 1,
  nfolds = 2, min_train = 8, nstarts = 1, ncores = 2)
validation$diagnostics
validation$scores
head(validation$predictions)
Example figure
Example figure: hindcast_model(x, model = "acl", horizon = 1, nfolds = 3)

See also

Search documentation