| rolling_oos | R Documentation |
Computes rolling out-of-sample (OOS) forecast accuracy for the
selected bivariate hurdle model by repeatedly truncating the sample
at different cut points Tcut, generating multi-step-ahead
predictive distributions, and summarizing them via RMSE for I
and C.
rolling_oos(
best_fit,
DT,
h = 5,
cuts = seq(round(0.6 * nrow(DT)), round(0.9 * nrow(DT)), length.out = 5),
dir_csv = NULL
)
best_fit |
A fitted model object as returned by
This object is passed directly to |
DT |
A |
h |
Integer; maximum forecast horizon (number of steps ahead)
requested at each cut. For a given |
cuts |
Numeric vector of time indices (training end points) at
which to perform the rolling evaluation. By default, a grid of five
equally spaced cut points between 60\
used:
|
dir_csv |
Character scalar or |
For each Tcut in cuts, the function:
Calls predict_multistep() with
fit_obj = best_fit, the full DT, lag
k = best_fit$k, and horizon
h_eff = min(h, nrow(DT) - Tcut) to obtain posterior
predictive paths pred_I and pred_C.
Computes the posterior-mean forecast for each step
(mI, mC) as the column means of pred_I
and pred_C.
Extracts the realized outcomes
yI = I[(Tcut + 1):(Tcut + h_eff)] and analogously for
yC.
Computes RMSE for each series:
RMSE_I = sqrt(mean((yI - mI)^2)),
RMSE_C = sqrt(mean((yC - mC)^2)).
Progress is reported via progressr. When dir_csv is
supplied, the resulting table is written as "rolling_oos.csv" in
that directory.
A data.frame with one row per Tcut and columns:
Tcut: training end index.
RMSE_I: rolling OOS RMSE for series I.
RMSE_C: rolling OOS RMSE for series C.
# Minimal synthetic example illustrating the expected data structure:
set.seed(123)
DT <- data.frame(
id = rep(1:10, each = 2),
t = rep(1:2, times = 10),
I = rpois(20, lambda = 0.5),
C = rpois(20, lambda = 1.0)
)
# Directory for CSV output (in practice, use a persistent path chosen
# by the user):
dir_csv <- file.path(tempdir(), "bivarhr_oos_csv")
# Typical workflow (commented out to avoid heavy computation and
# external dependencies such as CmdStan during R CMD check):
#
# best_fit <- fit_one(
# data = DT,
# k = 2,
# spec = "C"
# )
#
# oos_res <- rolling_oos(
# fit = best_fit,
# data = DT,
# h = 6,
# dir_csv = dir_csv
# )
# print(oos_res)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.