Sampling functions for Bayesian analysis of mixture autoregressive models
sampZpi.RdSampling functions for Bayesian analysis of mixture autoregressive
models. Draws observations from posterior distributions of the latent
variables Z_ts and the parameters of mixture autoregressive
models.
Usage
sampZpi(y, pk, prob, mu, AR, sigma, nsim, d)
sampMuShift(y, pk, prec, nk, shift, z, AR, nsim)
sampSigmaTau(y, pk, prec, nk, AR, mu, z, a, c, nsim)Arguments
- y
a time series (currently a
numericvector).- pk
numericvector of lengthg. The autoregressive order of each component.- prob
numericvector of lengthg. Current mixing weights.- mu
numericvector of lengthg. Current mean parameters.- shift
numericvector of lengthg. Current shift parameters.- AR
listofgelements. Autoregressive coefficients for each component.- sigma
numericvector of lengthg. Current scale parameters- nsim
dessired sample size.
- d
numericvector of lengthg. Hyperparameters for Dirichlet prior. If missing, a vector of1s is generated. If length is1, creates a vector of lengthgwith given number.- prec
numericvector of lengthg. Current precision parameters.- nk
output from
sampZpi. Component sum of latent variables Z_t.- z
output
latentZfromsampZpi. A matrix containing the simulated latent variables.- a,c
hyperparameters.
Details
sampZpi draws observations from posterior distributions of the
latent variables Z_ts and mixing weights of a Mixture
autoregressive model.
sampSigmaTau draws observations from posterior distributions of
the precisions tau_k of a Mixture autoregressive model, and
obtains scales sigma_k by transformation.
sampMuShift Draws observations from posterior distributions of
the means mu_k of a Mixture autoregressive model, and obtains
shifts phi_k0 by transformation.
Value
for sampZpi, a list containing the following elements:
- mix_weights
matrixwithnrow = nsimandncol = g: sampled mixing weights.- latentZ
matrixwithnrow = n - pandncol = g,nequal tolength(y)andpequal tomax(pk: the simulated latent variablesZ_tat the last ofnsimiterations (functional). Specifically, each row contains1for exactly one component, and is filled with0.- nk
Vector of length
g. Column sums oflatentZ.
for sampMuShift, a list containing the following elements:
- shift
matrixwithnrow = nsimandncol = g: simulated shift parameters, obtained by transformation of the means.- mu
matrixwithnrow = nsimandncol = g: simulated mean parameters.
for sampSigmaTau, a list containing the following elements:
- scale
matrixwithnrow = nsimandncol = g: scale parameters, obtained by transformation of precisions.- precision
matrixwithnrow = nsimandncol = g: precision parameters.- lambda
numericvector of lengthnsimsimulated values of hyperparameter lambda, due to hierarchical setup.
Examples
model <- new("MixARGaussian",
prob = exampleModels$WL_At@prob, # c(0.5, 0.5)
scale = exampleModels$WL_At@scale, # c(1, 2)
arcoef = exampleModels$WL_At@arcoef@a ) # list(-0.5, 1.1)
prob <- model@prob
sigma <- model@scale
prec <- 1 / sigma ^ 2
g <- length(model@prob)
d <- rep(1, g)
pk <- model@arcoef@p
p <- max(pk)
shift <- mu <- model@shift
AR <- model@arcoef@a
model
#> An object of class "MixARGaussian"
#> Number of components: 2
#> prob shift scale order ar_1
#> Comp_1 0.5 0 1 1 -0.5
#> Comp_2 0.5 0 2 1 1.1
#>
#> Distributions of the error components:
#> standard Gaussian
#>
set.seed(1234)
n <- 50 # 500
nsim <- 50
y <- mixAR_sim(model, n = n, init = 0)
x <- sampZpi(y, pk, prob, shift, AR, sigma, nsim = nsim, d)
x1 <- sampMuShift(y, pk, prec, nk = x$nk, shift, z = x$latentZ, AR, nsim = nsim)
x2 <- sampSigmaTau(y, pk, prec, nk = x$nk, AR, mu = x1$mu, z = x$latentZ,
a = 0.2, c = 2, nsim = nsim)