| forecast.dynamic_fit | R Documentation |
Returns posterior predictive forecasts for the H periods after the end of
the series. The forecasts are obtained by forward simulation from the
stored posterior draws, so any horizon can be requested after fitting. If
the model was fitted with horizon >= 1, the forecast draws stored in the
fit are returned unless horizon, forecast_offset or forecast_trials
is supplied.
## S3 method for class 'dynamic_fit'
forecast(
object,
horizon = NULL,
forecast_offset = NULL,
forecast_trials = NULL,
probs = c(0.025, 0.5, 0.975),
seed = NULL,
...
)
object |
A |
horizon |
Forecast horizon |
forecast_offset |
Known offset over the forecast horizon, in the same
format as in |
forecast_trials |
Binomial and multinomial families: the number of
trials (binomial) or the total count per period (multinomial) over the
forecast horizon, of length 1 (recycled) or |
probs |
Quantile probabilities for the summary. Default
|
seed |
Optional random seed for the forward simulation. The previous state of the global random number generator is restored afterwards. |
... |
Unused. |
For every stored posterior draw, the latent path is propagated from the
last in-sample state z_n with
z_{n+h} = \mu + \rho z_{n+h-1} + \varepsilon_{n+h}, drawing the
increments from the fitted innovation structure (Gaussian with the drawn
variance, Student-t with the drawn scale and degrees of freedom, the drawn
scale mixture, or the stochastic-volatility process continued from its last
in-sample log-variance). A response is then drawn from the observation
model at each simulated state. The intervals therefore reflect parameter,
state and innovation uncertainty.
Zero inflation. For fits with zeros = "inflated" the response
forecast is unconditional: each draw includes the zero-inflation
gate, so structural zeros are reproduced and the draws are directly
comparable to future observations (like the in-sample yrep, unlike
yrep_open). The latent forecast summary in $latent is gate-free by
construction.
Multinomial family. Response forecasts are multinomial draws with
the totals given by forecast_trials. The summaries are in long format
with a category column. summary and final cover all K categories on
the count scale, prob gives the forecast category shares, and latent
the K - 1 ALR series. draws is a draws x H x K array and
final_draws a draws x K matrix.
An object of class "dynamic_forecast": a list with summary (one
row per horizon 1, \dots, H, on the response scale), latent
(summary of the forecast latent path), draws (the predictive draws,
draws x H), latent_draws (the latent forecast draws), final (the
single-row summary of the final H-step-ahead forecast), final_draws
(the predictive draws at horizon H), the forecast horizon, and the
forecast_offset / forecast_trials that were used. For the
multinomial family additionally prob (share summary) and prob_draws
(draws x H x K share draws); see Details for the layout.
fit_dynamic_model(), plot_forecast()
sim <- simulate_dynamic_poisson(60, 0.2, 2, seed = 1)
fit <- fit_dynamic_model(sim$y, nsave = 300, nburn = 200, seed = 1)
fc <- forecast(fit, horizon = 8)
fc$summary
fc$final
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.