mcmc {CausalMBSTS} | R Documentation |
MCMC samples for a given MBSTS model
Description
Use MCMC to sample from the joint posterior of model parameters in an mbsts model.
Usage
mcmc(
Smodel,
X = NULL,
H = NULL,
nu0.r = NULL,
s0.r,
nu0.eps = NULL,
s0.eps,
niter,
burn,
ping = NULL
)
Arguments
Smodel |
A multivariate state space model of class |
X |
t x N optional matrix of predictors. |
H |
P x P variance-covariance matrix of the regression coefficients. Set
by default to H = c(X'X)^(-1) which is akin to the Zellner's g-prior. The
value of the scaling factor is set to |
nu0.r |
Degrees of freedom of the Inverse-Wishart prior for each Sigma.r. Set by default to n0.r = d + 2, where d is the number of time series in the multivariate model. |
s0.r |
Scale matrix of the Inverse-Wishart prior for each Sigma.r, a vector of errors for state r. Must be a (d x d) positive definite. Default set to the variance-covariance matrix of y multiplied by a scaling factor of 0.01. |
nu0.eps |
Degrees of freedom of the Inverse-Wishart prior for Sigma.eps, a vector of observation errors for each time series. Set by default to d + 2 (must be greater than d - 1). |
s0.eps |
Scale matrix of the Inverse-Wishart prior for Sigma.eps, a vector of observation errors for each time series. Must be a (d x d) positive definite. Default set to the variance-covariance matrix of y multiplied by a scaling factor of 0.01. |
niter |
Number of MCMC iterations. |
burn |
Desired burn-in, set by default to 0.1 * |
ping |
A status message is printed every |
Value
An object of class 'mbsts' which is a list with the following components:
- eta.samples
(
niter
-burn
) draws from the distribution of eta_r.- eps.samples
(
niter
-burn
) draws from the distribution of eps.- states.samples
(
niter
-burn
) draws from p(alpha_t | Y_1:T).- Sigma.r
(
niter
-burn
) draws from the posterior distribution of Sigma.r.- Sigma.eps
(
niter
-burn
) draws from the posterior distribution of Sigma.eps.- Z.beta
(
niter
-burn
) x P matrix of the models selected at each iteration (if a matrix of predictors is provided).- beta
P x d x (
niter
-burn
) ) array of the draws from the posterior distribution of the regression coefficient matrix (if a matrix of predictors is provided).- X
Predictor matrix (if provided).
- y
Matrix of observations.
- Z
(d x m) selection matrix of the observation equation.
- Tt
(m x m) matrix of the state equation.
- R
(m x r) matrix selecting the state disturbances.
- niter
Number of mcmc iterations.
- burn
Burn-in.
Examples
## Example 1 : local level + seasonal (d = 3)
y <- cbind(seq(0.5,100,by=0.5)*0.1 + rnorm(200),
seq(100.25,150,by=0.25)*0.05 + rnorm(200),
rnorm(200, 5,1))
model.1 <- model(y = y, components = c("trend", "seasonal"), seas.period = 7)
mcmc.1 <- mcmc(model.1, s0.r = diag(3), s0.eps = diag(3), niter = 50, burn = 5)
## Example 2 : local level + seasonal + covariates (d = 2)
y <- cbind(rnorm(100), rnorm(100, 2, 3))
X <- cbind(rnorm(100, 0.5, 1) + 5, rnorm(100, 0.2, 2) - 2)
model.2 <- model(y = y, components = c("trend", "seasonal"), seas.period = 7)
mcmc.2 <- mcmc(model.2, X = X, s0.r = diag(2), s0.eps = diag(2), niter = 100, burn = 10)