| predict_multistep | R Documentation |
Generates forward simulations for h future periods from a fitted
bivariate hurdle negative binomial model (I/C), using posterior draws and
dynamically updating the lagged history as new simulated values are added.
predict_multistep(fit_obj, DT, k, Tcut, h, ndraws = 800, seed = NULL)
fit_obj |
A list returned by |
DT |
A |
k |
Integer; lag order used in the fitted model. |
Tcut |
Integer; last time index used as the starting point for
prediction (historical window is |
h |
Integer; forecast horizon (number of steps ahead to simulate). |
ndraws |
Integer; maximum number of posterior draws to use for simulation (default 800). If larger than available draws, it is truncated. |
seed |
Optional integer; random seed passed to |
For each selected posterior draw, the function iteratively simulates
h future values of I and C. At each step:
The covariate vector is built from lagged outcomes
(up to order k) and the corresponding row t of
DT (trend terms, regime dummies, transition variables and
controls).
The hurdle probabilities and negative-binomial means are computed from the draw-specific parameters.
New counts are sampled and appended to the local history so that subsequent steps use the updated lags.
Simulation stops early for a given path if Tcut + step > nrow(DT).
A list with two components:
pred_I |
Numeric matrix of dimension |
pred_C |
Numeric matrix of dimension |
if (interactive() && requireNamespace("cmdstanr", quietly = TRUE)) {
n <- 120
DT <- data.table::data.table(
I = rpois(n, 5), C = rpois(n, 3),
Regime = factor(sample(c("A","B","C"), n, TRUE)),
trans_PS = c(rep(1,5), rep(0,n-5)),
trans_SF = c(rep(0,60), rep(1,5), rep(0,n-65)),
trans_FC = rep(0, n),
log_exposure50 = log(runif(n, 40, 60))
)
fit_obj <- fit_one(DT, k = 1, spec = "C")
pred <- predict_multistep(fit_obj, DT, k = 1, Tcut = 100, h = 12,
ndraws = 500, seed = 123)
str(pred$pred_I)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.