Skip to contents

Model

The measurement model is given by 𝐲i,t=π›ˆi,t\begin{equation} \mathbf{y}_{i, t} = \boldsymbol{\eta}_{i, t} \end{equation} where 𝐲i,t\mathbf{y}_{i, t} represents a vector of observed variables and π›ˆi,t\boldsymbol{\eta}_{i, t} a vector of latent variables for individual ii and time tt. Since the observed and latent variables are equal, we only generate data from the dynamic structure.

The dynamic structure is given by π›ˆi,t=𝛂+π›ƒπ›ˆi,tβˆ’1+𝛇i,t,with𝛇i,tβˆΌπ’©(𝟎,𝚿)\begin{equation} \boldsymbol{\eta}_{i, t} = \boldsymbol{\alpha} + \boldsymbol{\beta} \boldsymbol{\eta}_{i, t - 1} + \boldsymbol{\zeta}_{i, t}, \quad \mathrm{with} \quad \boldsymbol{\zeta}_{i, t} \sim \mathcal{N} \left( \mathbf{0}, \boldsymbol{\Psi} \right) \end{equation} where π›ˆi,t\boldsymbol{\eta}_{i, t}, π›ˆi,tβˆ’1\boldsymbol{\eta}_{i, t - 1}, and 𝛇i,t\boldsymbol{\zeta}_{i, t} are random variables, and 𝛂\boldsymbol{\alpha}, 𝛃\boldsymbol{\beta}, and 𝚿\boldsymbol{\Psi} are model parameters. Here, π›ˆi,t\boldsymbol{\eta}_{i, t} is a vector of latent variables at time tt and individual ii, π›ˆi,tβˆ’1\boldsymbol{\eta}_{i, t - 1} represents a vector of latent variables at time tβˆ’1t - 1 and individual ii, and 𝛇i,t\boldsymbol{\zeta}_{i, t} represents a vector of dynamic noise at time tt and individual ii. 𝛂\boldsymbol{\alpha} denotes a vector of intercepts, 𝛃\boldsymbol{\beta} a matrix of autoregression and cross regression coefficients, and 𝚿\boldsymbol{\Psi} the covariance matrix of 𝛇i,t\boldsymbol{\zeta}_{i, t}.

An alternative representation of the dynamic noise is given by 𝛇i,t=𝚿12𝐳i,t,with𝐳i,tβˆΌπ’©(𝟎,𝐈)\begin{equation} \boldsymbol{\zeta}_{i, t} = \boldsymbol{\Psi}^{\frac{1}{2}} \mathbf{z}_{i, t}, \quad \mathrm{with} \quad \mathbf{z}_{i, t} \sim \mathcal{N} \left( \mathbf{0}, \mathbf{I} \right) \end{equation} where (𝚿12)(𝚿12)β€²=𝚿\left( \boldsymbol{\Psi}^{\frac{1}{2}} \right) \left( \boldsymbol{\Psi}^{\frac{1}{2}} \right)^{\prime} = \boldsymbol{\Psi} .

Parameters

Notation

Let t=1000t = 1000 be the number of time points and n=5n = 5 be the number of individuals.

Let the initial condition π›ˆ0\boldsymbol{\eta}_{0} be given by

π›ˆ0βˆΌπ’©(π›π›ˆβˆ£0,πšΊπ›ˆβˆ£0)\begin{equation} \boldsymbol{\eta}_{0} \sim \mathcal{N} \left( \boldsymbol{\mu}_{\boldsymbol{\eta} \mid 0}, \boldsymbol{\Sigma}_{\boldsymbol{\eta} \mid 0} \right) \end{equation}

π›π›ˆβˆ£0=(000)\begin{equation} \boldsymbol{\mu}_{\boldsymbol{\eta} \mid 0} = \left( \begin{array}{c} 0 \\ 0 \\ 0 \\ \end{array} \right) \end{equation}

πšΊπ›ˆβˆ£0=(10.20.20.210.20.20.21).\begin{equation} \boldsymbol{\Sigma}_{\boldsymbol{\eta} \mid 0} = \left( \begin{array}{ccc} 1 & 0.2 & 0.2 \\ 0.2 & 1 & 0.2 \\ 0.2 & 0.2 & 1 \\ \end{array} \right) . \end{equation}

Let the constant vector 𝛂\boldsymbol{\alpha} be given by

𝛂=(000).\begin{equation} \boldsymbol{\alpha} = \left( \begin{array}{c} 0 \\ 0 \\ 0 \\ \end{array} \right) . \end{equation}

Let the transition matrix 𝛃\boldsymbol{\beta} be given by

𝛃=(0.7000.50.60βˆ’0.10.40.5).\begin{equation} \boldsymbol{\beta} = \left( \begin{array}{ccc} 0.7 & 0 & 0 \\ 0.5 & 0.6 & 0 \\ -0.1 & 0.4 & 0.5 \\ \end{array} \right) . \end{equation}

Let the dynamic process noise 𝚿\boldsymbol{\Psi} be given by

𝚿=(0.10000.10000.1).\begin{equation} \boldsymbol{\Psi} = \left( \begin{array}{ccc} 0.1 & 0 & 0 \\ 0 & 0.1 & 0 \\ 0 & 0 & 0.1 \\ \end{array} \right) . \end{equation}

R Function Arguments

n
#> [1] 5
time
#> [1] 1000
mu0
#> [1] 0 0 0
sigma0
#>      [,1] [,2] [,3]
#> [1,]  1.0  0.2  0.2
#> [2,]  0.2  1.0  0.2
#> [3,]  0.2  0.2  1.0
sigma0_l # sigma0_l <- t(chol(sigma0))
#>      [,1]      [,2]      [,3]
#> [1,]  1.0 0.0000000 0.0000000
#> [2,]  0.2 0.9797959 0.0000000
#> [3,]  0.2 0.1632993 0.9660918
alpha
#> [1] 0 0 0
beta
#>      [,1] [,2] [,3]
#> [1,]  0.7  0.0  0.0
#> [2,]  0.5  0.6  0.0
#> [3,] -0.1  0.4  0.5
psi
#>      [,1] [,2] [,3]
#> [1,]  0.1  0.0  0.0
#> [2,]  0.0  0.1  0.0
#> [3,]  0.0  0.0  0.1
psi_l # psi_l <- t(chol(psi))
#>           [,1]      [,2]      [,3]
#> [1,] 0.3162278 0.0000000 0.0000000
#> [2,] 0.0000000 0.3162278 0.0000000
#> [3,] 0.0000000 0.0000000 0.3162278

Parametric Bootstrap

R <- 1000L # use at least 1000 in actual research
path <- getwd()
prefix <- "var"

We use the PBSSMVARFixed function from the bootStateSpace package to perform parametric bootstraping using the parameters described above. The argument R specifies the number of bootstrap replications. The generated data and model estimates are stored in path using the specified prefix for the file names. The ncores = parallel::detectCores() argument instructs the function to use all available CPU cores in the system.

NOTE: Fitting the VAR model multiple times is computationally intensive.

library(bootStateSpace)
pb <- PBSSMVARFixed(
  R = R,
  path = path,
  prefix = prefix,
  n = n,
  time = time,
  mu0 = mu0,
  sigma0_l = sigma0_l,
  alpha = alpha,
  beta = beta,
  psi_l = psi_l,
  ncores = parallel::detectCores(),
  seed = 42
)
summary(pb)
#> Call:
#> PBSSMVARFixed(R = R, path = path, prefix = prefix, n = n, time = time, 
#>     mu0 = mu0, sigma0_l = sigma0_l, alpha = alpha, beta = beta, 
#>     psi_l = psi_l, ncores = parallel::detectCores(), seed = 42)
#>             est     se    R    2.5%   97.5%
#> beta_1_1    0.7 0.0113 1000  0.6772  0.7204
#> beta_2_1    0.5 0.0114 1000  0.4785  0.5235
#> beta_3_1   -0.1 0.0120 1000 -0.1235 -0.0770
#> beta_1_2    0.0 0.0097 1000 -0.0188  0.0192
#> beta_2_2    0.6 0.0092 1000  0.5810  0.6174
#> beta_3_2    0.4 0.0099 1000  0.3806  0.4196
#> beta_1_3    0.0 0.0097 1000 -0.0183  0.0201
#> beta_2_3    0.0 0.0094 1000 -0.0180  0.0179
#> beta_3_3    0.5 0.0099 1000  0.4806  0.5188
#> psi_1_1     0.1 0.0020 1000  0.0961  0.1040
#> psi_2_2     0.1 0.0019 1000  0.0962  0.1033
#> psi_3_3     0.1 0.0020 1000  0.0960  0.1038
#> mu0_1_1     0.0 0.4466 1000 -0.8475  0.9017
#> mu0_2_1     0.0 0.4250 1000 -0.9161  0.7748
#> mu0_3_1     0.0 0.4490 1000 -0.8908  0.7923
#> sigma0_1_1  1.0 0.6008 1000  0.0971  2.3803
#> sigma0_2_1  0.2 0.4126 1000 -0.5615  1.0978
#> sigma0_3_1  0.2 0.4442 1000 -0.5930  1.2457
#> sigma0_2_2  1.0 0.5815 1000  0.0952  2.2643
#> sigma0_3_2  0.2 0.4441 1000 -0.5108  1.1431
#> sigma0_3_3  1.0 0.5684 1000  0.1019  2.0030
summary(pb, type = "bc")
#> Call:
#> PBSSMVARFixed(R = R, path = path, prefix = prefix, n = n, time = time, 
#>     mu0 = mu0, sigma0_l = sigma0_l, alpha = alpha, beta = beta, 
#>     psi_l = psi_l, ncores = parallel::detectCores(), seed = 42)
#>             est     se    R    2.5%   97.5%
#> beta_1_1    0.7 0.0113 1000  0.6783  0.7217
#> beta_2_1    0.5 0.0114 1000  0.4787  0.5238
#> beta_3_1   -0.1 0.0120 1000 -0.1235 -0.0772
#> beta_1_2    0.0 0.0097 1000 -0.0188  0.0190
#> beta_2_2    0.6 0.0092 1000  0.5816  0.6178
#> beta_3_2    0.4 0.0099 1000  0.3806  0.4195
#> beta_1_3    0.0 0.0097 1000 -0.0189  0.0198
#> beta_2_3    0.0 0.0094 1000 -0.0184  0.0171
#> beta_3_3    0.5 0.0099 1000  0.4812  0.5198
#> psi_1_1     0.1 0.0020 1000  0.0961  0.1041
#> psi_2_2     0.1 0.0019 1000  0.0963  0.1034
#> psi_3_3     0.1 0.0020 1000  0.0964  0.1042
#> mu0_1_1     0.0 0.4466 1000 -0.8431  0.9035
#> mu0_2_1     0.0 0.4250 1000 -0.8722  0.8117
#> mu0_3_1     0.0 0.4490 1000 -0.8908  0.7923
#> sigma0_1_1  1.0 0.6008 1000  0.3483  4.6690
#> sigma0_2_1  0.2 0.4126 1000 -0.4286  1.4031
#> sigma0_3_1  0.2 0.4442 1000 -0.4311  1.5559
#> sigma0_2_2  1.0 0.5815 1000  0.3301  3.6552
#> sigma0_3_2  0.2 0.4441 1000 -0.3742  1.4170
#> sigma0_3_3  1.0 0.5684 1000  0.3172  3.2279

References

Chow, S.-M., Ho, M. R., Hamaker, E. L., & Dolan, C. V. (2010). Equivalence and differences between structural equation modeling and state-space modeling techniques. Structural Equation Modeling: A Multidisciplinary Journal, 17(2), 303–332. https://doi.org/10.1080/10705511003661553
Ou, L., Hunter, M. D., & Chow, S.-M. (2019). What’s for dynr: A package for linear and nonlinear dynamic modeling in R. The R Journal, 11(1), 91. https://doi.org/10.32614/rj-2019-012
R Core Team. (2024). R: A language and environment for statistical computing. R Foundation for Statistical Computing. https://www.R-project.org/