View source: R/stationary_moments.R
| stationary_moments | R Documentation | 
hhh4-modelReturns the mean vector and covariance matrix of the periodically stationary distribution implied by an hhh4 object.
stationary_moments(
  hhh4Obj,
  start = 1,
  n_seasons = 1,
  return_Sigma = FALSE,
  return_cov_array = FALSE,
  return_mu_decomposed = FALSE,
  return_M = FALSE,
  max.iter = 10,
  tolerance = 1e-05
)
hhh4Obj | 
 
  | 
start | 
 start of the season  | 
n_seasons | 
 number of  | 
return_Sigma | 
 logical: return entire variance/covariance matrix of the prediction; can take a lot of storage  | 
return_cov_array | 
 logical: return an array containing week-wise covariance matrices  | 
return_mu_decomposed | 
 logical: return an array containing a decomposition of
stationary means into the three
components   | 
return_M | 
 logical: return the array M containing un-centered second moments (used internally for calculations)  | 
max.iter | 
 maximum number of iterations before iterative algorithm stops  | 
tolerance | 
 element-wise maximum tolerance (entering into termination criterion for the iterative calculation)  | 
An object of class stationary_moments_hhh4 containing the following components:
mu_matrix A matrix containing the stationary means. Each row corresponds
to a time period and each column to a unit.
var_matrix A matrix containing the stationary 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 stationary means and (un-centered) second moments,
specifically E(c(1, X)
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 position (within a cycle) of the time period to which the first elements of
mu_matrix etc. correspond (i.e. the start argument from the call of
stationary_moments)
freq the length of a cycle
n_seasons the number of seasons covered in mu_matrix etc.
n_units the number of units covered in the prediction
timepoints the positions within a cycle of the timepoints covered by mu_matrix etc.
condition NULL. Only relevant in predictive moments, just a place holder here.
type "stationary"; to distinguish from predictive 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)
# specify and fit model
control_salmonella <- list(end = list(f = addSeason2formula(~ 1), lag = 1),
                           ar = list(f = addSeason2formula(~ 1), lag = 1),
                           family = "NegBinM")
fit_salmonella <- hhh4(salmonella, control_salmonella)
# obtain periodically stationary moments:
stat_mom <- stationary_moments(fit_salmonella)
# plot periodically stationary means:
fanplot_stationary(stat_mom)
# add paths of the six seasons in the data set:
for(i in 0:5){
 lines(1:52/52, salmonella@observed[(i*52 + 1):((i + 1)*52)], col = "blue")
}
legend("topleft", col = "blue", lty = 1, legend = "observed seasons")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.