
Last chance! 50% off unlimited learning
Sale ends in
Sampling functions for Bayesian analysis of mixture autoregressive
models. Draws observations from posterior distributions of the latent
variables Z_t
s and the parameters of mixture autoregressive
models.
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)
for sampZpi
, a list containing the following elements:
matrix
with nrow = nsim
and ncol = g
:
sampled mixing weights.
matrix
with nrow = n - p
and ncol = g
, n
equal to
length(y)
and p
equal to max(pk
:
the simulated latent variables Z_t
at the last of nsim
iterations
(functional). Specifically, each row contains 1
for exactly
one component, and is filled with 0
.
Vector of length g
. Column sums of latentZ
.
for sampMuShift
, a list containing the following elements:
matrix
with nrow = nsim
and ncol = g
:
simulated shift parameters, obtained by transformation of the
means.
matrix
with nrow = nsim
and ncol = g
:
simulated mean parameters.
for sampSigmaTau
, a list containing the following elements:
matrix
with nrow = nsim
and ncol = g
:
scale parameters, obtained by transformation
of precisions.
matrix
with nrow = nsim
and ncol = g
:
precision parameters.
numeric
vector of length nsim
simulated values
of hyperparameter lambda, due to hierarchical setup.
a time series (currently a numeric
vector).
numeric
vector of length g
. The autoregressive order
of each component.
numeric
vector of length g
. Current mixing weights.
numeric
vector of length g
. Current mean parameters.
numeric
vector of length g
. Current shift parameters.
list
of g
elements. Autoregressive coefficients for
each component.
numeric
vector of length g
. Current scale parameters
dessired sample size.
numeric
vector of length g
. Hyperparameters for
Dirichlet prior. If missing, a vector of 1
s is generated. If
length is 1
, creates a vector of length g
with given
number.
numeric
vector of length g
. Current precision
parameters.
output from sampZpi
. Component sum of latent variables Z_t.
output latentZ
from sampZpi
. A matrix containing the
simulated latent variables.
hyperparameters.
Davide Ravagli
sampZpi
draws observations from posterior distributions of the
latent variables Z_t
s 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.
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
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)
Run the code above in your browser using DataLab