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=100t = 100 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] 100
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 <- 5L # 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)
#> 
#> Parametric bootstrap confidence intervals.
#> type = "pc"
#>             est     se R    2.5%   97.5%
#> beta_1_1    0.7 0.0326 5  0.6612  0.7388
#> beta_2_1    0.5 0.0428 5  0.4467  0.5538
#> beta_3_1   -0.1 0.0488 5 -0.1505 -0.0451
#> beta_1_2    0.0 0.0204 5 -0.0447  0.0054
#> beta_2_2    0.6 0.0208 5  0.5909  0.6407
#> beta_3_2    0.4 0.0407 5  0.3644  0.4673
#> beta_1_3    0.0 0.0122 5 -0.0149  0.0151
#> beta_2_3    0.0 0.0366 5 -0.0377  0.0550
#> beta_3_3    0.5 0.0348 5  0.4602  0.5416
#> psi_1_1     0.1 0.0045 5  0.0959  0.1067
#> psi_2_2     0.1 0.0072 5  0.0942  0.1100
#> psi_3_3     0.1 0.0068 5  0.0918  0.1063
#> mu0_1_1     0.0 0.1453 5  0.0246  0.3091
#> mu0_2_1     0.0 0.3752 5 -0.7492  0.2085
#> mu0_3_1     0.0 0.3640 5 -0.4807  0.4184
#> sigma0_1_1  1.0 0.3589 5  0.4323  1.1368
#> sigma0_2_1  0.2 0.5852 5 -0.3458  1.0481
#> sigma0_3_1  0.2 0.5702 5 -0.1066  1.2729
#> sigma0_2_2  1.0 0.4921 5  0.4113  1.4608
#> sigma0_3_2  0.2 0.7381 5 -0.3913  1.4683
#> sigma0_3_3  1.0 0.5953 5  0.4312  1.7523
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)
#> 
#> Parametric bootstrap confidence intervals.
#> type = "bc"
#>             est     se R    2.5%   97.5%
#> beta_1_1    0.7 0.0326 5  0.6628  0.7417
#> beta_2_1    0.5 0.0428 5  0.4523  0.5578
#> beta_3_1   -0.1 0.0488 5 -0.1520 -0.0472
#> beta_1_2    0.0 0.0204 5 -0.0114  0.0070
#> beta_2_2    0.6 0.0208 5  0.5902  0.6357
#> beta_3_2    0.4 0.0407 5  0.3603  0.4221
#> beta_1_3    0.0 0.0122 5 -0.0161  0.0135
#> beta_2_3    0.0 0.0366 5 -0.0401  0.0469
#> beta_3_3    0.5 0.0348 5  0.4645  0.5432
#> psi_1_1     0.1 0.0045 5  0.0985  0.1075
#> psi_2_2     0.1 0.0072 5  0.0940  0.1094
#> psi_3_3     0.1 0.0068 5  0.0923  0.1064
#> mu0_1_1     0.0 0.1453 5  0.0239  0.0239
#> mu0_2_1     0.0 0.3752 5 -0.2414  0.2513
#> mu0_3_1     0.0 0.3640 5 -0.4326  0.4496
#> sigma0_1_1  1.0 0.3589 5  0.4333  1.1429
#> sigma0_2_1  0.2 0.5852 5 -0.0339  1.1423
#> sigma0_3_1  0.2 0.5702 5 -0.1297  1.0882
#> sigma0_2_2  1.0 0.4921 5  0.4368  1.4679
#> sigma0_3_2  0.2 0.7381 5 -0.4601  0.3568
#> sigma0_3_3  1.0 0.5953 5  0.5636  1.8693

References

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
Pesigan, I. J. A., Russell, M. A., & Chow, S.-M. (2025). Inferences and effect sizes for direct, indirect, and total effects in continuous-time mediation models. Psychological Methods. https://doi.org/10.1037/met0000779
R Core Team. (2024). R: A language and environment for statistical computing. R Foundation for Statistical Computing. https://www.R-project.org/