Simulate Data from a Vector Autoregressive Zero-Inflated Poisson (VARZIP) Model
Source:R/RcppExports.R
SimVARZIP.RdThis function generates synthetic time series data from a Vector Autoregressive Zero-Inflated Poisson (VARZIP) model.
Arguments
- time
Integer. Number of time points to simulate.
- burn_in
Integer. Number of burn-in observations to exclude before returning the results.
- constant
Numeric vector. The constant term vector of length
k, wherekis the number of variables.- coef
Numeric matrix. Coefficient matrix with dimensions
kby(k * p). Eachkbykblock corresponds to the coefficient matrix for a particular lag.- chol_cov
Numeric matrix. The Cholesky decomposition of the covariance matrix of the multivariate normal noise. It should have dimensions
kbyk.
Value
Numeric matrix containing the simulated time series data
with dimensions k by time,
where k is the number of variables
and time is the number of observations.
Details
The SimVARZIP() function generates synthetic time series data
from a Vector Autoregressive (VAR)
with Zero-Inflated Poisson (ZIP) model for the first observed variable.
See SimVAR() for more details on generating data for VAR(p).
The SimVARZIP function goes further by using the generated values
for the first variable to generate data from the ZIP model.
The exponential of the values from the first variable
from the original VAR(p) model
are used as the intensity parameter in the Poisson distribution
in the ZIP model.
Data from the ZIP model are used to replace the original values
for the first variable.
Values for the rest of the variables are unchanged.
The generated data includes a burn-in period,
which is excluded before returning the results.
The steps involved in generating the time series data are as follows:
Extract the number of variables
kand the number of lagspfrom the input.Create a matrix
dataof sizekx (time + burn_in) to store the generated data.Set the initial values of the matrix
datausing the constant termconstant.For each time point starting from the
p-th time point totime + burn_in - 1:Generate a vector of random process noise from a multivariate normal distribution with mean 0 and covariance matrix
chol_cov.Generate the VAR time series values for each variable
jat timetby applying the autoregressive terms for each laglagand each variablel.Add the generated noise to the VAR time series values.
For the first variable, apply the Zero-Inflated Poisson (ZIP) model:
Compute the intensity
intensityas the exponential of the first variable's value at timet.Sample a random value
ufrom a uniform distribution on [0, 1].If
uis less thanintensity / (1 + intensity), set the first variable's value to zero (inflation).Otherwise, sample the first variable's value from a Poisson distribution with mean
intensity(count process).
Transpose the data matrix
dataand return only the required time period after burn-in as a numeric matrix.
See also
Other Simulation of Autoregressive Data Functions:
CheckARCoef(),
CheckVARCoef(),
SimARCoef(),
SimAR(),
SimMVN(),
SimPD(),
SimVARCoef(),
SimVARExo(),
SimVARZIPExo(),
SimVAR(),
SimVariance(),
YXExo(),
YX()
Examples
set.seed(42)
time <- 50L
burn_in <- 10L
k <- 3
p <- 2
constant <- c(1, 1, 1)
coef <- matrix(
data = c(
0.4, 0.0, 0.0, 0.1, 0.0, 0.0,
0.0, 0.5, 0.0, 0.0, 0.2, 0.0,
0.0, 0.0, 0.6, 0.0, 0.0, 0.3
),
nrow = k,
byrow = TRUE
)
chol_cov <- chol(diag(3))
y <- SimVARZIP(
time = time,
burn_in = burn_in,
constant = constant,
coef = coef,
chol_cov = chol_cov
)
head(y)
#> [,1] [,2] [,3]
#> [1,] 0 3.271626 4.772946
#> [2,] 0 3.297536 5.918128
#> [3,] 1 2.039249 4.670999
#> [4,] 0 3.177612 3.249752
#> [5,] 0 4.138388 2.583101
#> [6,] 2 4.479106 4.351911