View source: R/predictive_moments.R
| predictive_moments | R Documentation |
hhh4 modelThis functions calculates the predictive mean vector and covariance
matrix for a path forecast from an hhh4 model.
predictive_moments(
hhh4Obj,
t_condition,
lgt,
return_Sigma = FALSE,
return_cov_array = FALSE,
return_mu_decomposed = FALSE,
return_M = FALSE
)
hhh4Obj |
an |
t_condition |
the index of the week on which to condition the
path forecast, i.e. an integer between 1 and |
lgt |
the length of the path forecast, i.e. 52 for forecasting an entire season when using weekly data |
return_Sigma |
logical: should the entire variance-covariance
matrix of the forecast be returned? defaults to |
return_cov_array |
logical: should an array with week-wise covariance matrices be returned? |
return_mu_decomposed |
logical: should an array with the predictive means decomposed into the different components be returned? |
return_M |
logical: should the matrix M containing the predictive first and (un-centered) second moments be returned? |
An object of class predictive_moments_hhh4 containing
the following components:
mu_matrix A matrix containing the predictive means.
Each row corresponds
to a time period and each column to a unit.
var_matrix A matrix containing the predictive variances.
cov_array An array containing time period-wise
variance-covariance matrices.
mu_vector as mu_matrix, but flattened into a vector.
Sigma a large covariance matrix for all elements
of the prediction
(corresponding to mu_vector)
M a matrix containing predictive means and (un-centered)
second moments,
specifically E(c(1, X)
shall be forecasted.
Important in the internal calculation, accessible mainly for
de-bugging purposes.
mu_decomposed an array with the same number of rows
and columns as
mu_matrix, but three layers corresponding to the contributions
of the three
components to the means
start the index (in the original sts object) of
the first time
period of the prediction
freq the length of a cycle
n_units the number of units covered in the prediction
timepoints the timepoints covered by the prediction etc.
timepoints as timepoints, but calendar time
rather than indices
condition A matrix containing the realizations for
the conditioning time period (or periods)
realizations_matrix A matrix containing the realizations
that have materialized in the
period covered by the prediction.
type "predictive"; to distinguish from stationary
moments.
has_temporal_structure does the object still have the
original temporal structure? can
be set to FALSE when aggregated using aggregate_prediction.
data("salmonella.agona")
# convert old "disProg" to new "sts" data class:
salmonella <- disProg2sts(salmonella.agona)
control_salmonella <- list(end = list(f = addSeason2formula(~ 1), lag = 1),
ar = list(f = addSeason2formula(~ 1), lag = 1),
family = "NegBinM", subset = 6:250)
fit_salmonella <- hhh4_lag(salmonella, control_salmonella) # fit model
# obtain prediction:
pred_mom <- predictive_moments(fit_salmonella, t_condition = 250, lgt = 52)
plot(fit_salmonella)
fanplot_prediction(pred_mom, add = TRUE) # add fan plot
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.