Skip to contents

Model

The measurement model is given by π’ši,t=𝝂+𝚲𝜼i,t+𝜺i,t,with𝜺i,tβˆΌπ’©(𝟎,𝚯)\begin{equation} \mathbf{y}_{i, t} = \boldsymbol{\nu} + \boldsymbol{\Lambda} \boldsymbol{\eta}_{i, t} + \boldsymbol{\varepsilon}_{i, t}, \quad \mathrm{with} \quad \boldsymbol{\varepsilon}_{i, t} \sim \mathcal{N} \left( \mathbf{0}, \boldsymbol{\Theta} \right) \end{equation} where π’ši,t\mathbf{y}_{i, t}, 𝜼i,t\boldsymbol{\eta}_{i, t}, and 𝜺i,t\boldsymbol{\varepsilon}_{i, t} are random variables and 𝝂\boldsymbol{\nu}, 𝚲\boldsymbol{\Lambda}, and 𝚯\boldsymbol{\Theta} are model parameters. π’ši,t\mathbf{y}_{i, t} represents a vector of observed random variables, 𝜼i,t\boldsymbol{\eta}_{i, t} a vector of latent random variables, and 𝜺i,t\boldsymbol{\varepsilon}_{i, t} a vector of random measurement errors, at time tt and individual ii. 𝝂\boldsymbol{\nu} denotes a vector of intercepts, 𝚲\boldsymbol{\Lambda} a matrix of factor loadings, and 𝚯\boldsymbol{\Theta} the covariance matrix of 𝜺\boldsymbol{\varepsilon}.

An alternative representation of the measurement error is given by 𝜺i,t=𝚯12𝒛i,t,with𝒛i,tβˆΌπ’©(𝟎,𝑰)\begin{equation} \boldsymbol{\varepsilon}_{i, t} = \boldsymbol{\Theta}^{\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 𝒛i,t\mathbf{z}_{i, t} is a vector of independent standard normal random variables and (𝚯12)(𝚯12)β€²=𝚯\left( \boldsymbol{\Theta}^{\frac{1}{2}} \right) \left( \boldsymbol{\Theta}^{\frac{1}{2}} \right)^{\prime} = \boldsymbol{\Theta} .

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 measurement model intecept vector 𝝂\boldsymbol{\nu} be given by

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

Let the factor loadings matrix 𝚲\boldsymbol{\Lambda} be given by

𝚲=(100010001).\begin{equation} \boldsymbol{\Lambda} = \left( \begin{array}{ccc} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \\ \end{array} \right) . \end{equation}

Let the measurement error covariance matrix 𝚯\boldsymbol{\Theta} be given by

𝚯=(0.20000.20000.2).\begin{equation} \boldsymbol{\Theta} = \left( \begin{array}{ccc} 0.2 & 0 & 0 \\ 0 & 0.2 & 0 \\ 0 & 0 & 0.2 \\ \end{array} \right) . \end{equation}

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
nu
#> [1] 0 0 0
lambda
#>      [,1] [,2] [,3]
#> [1,]    1    0    0
#> [2,]    0    1    0
#> [3,]    0    0    1
theta
#>      [,1] [,2] [,3]
#> [1,]  0.2  0.0  0.0
#> [2,]  0.0  0.2  0.0
#> [3,]  0.0  0.0  0.2
theta_l # theta_l <- t(chol(theta))
#>           [,1]      [,2]      [,3]
#> [1,] 0.4472136 0.0000000 0.0000000
#> [2,] 0.0000000 0.4472136 0.0000000
#> [3,] 0.0000000 0.0000000 0.4472136

Parametric Bootstrap

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

We use the PBSSMFixed 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 state space model multiple times is computationally intensive.

library(bootStateSpace)
pb <- PBSSMFixed(
  R = R,
  path = path,
  prefix = prefix,
  n = n,
  time = time,
  mu0 = mu0,
  sigma0_l = sigma0_l,
  alpha = alpha,
  beta = beta,
  psi_l = psi_l,
  nu = nu,
  lambda = lambda,
  theta_l = theta_l,
  ncores = parallel::detectCores(),
  seed = 42
)
summary(pb)
#> Call:
#> PBSSMFixed(R = R, path = path, prefix = prefix, n = n, time = time, 
#>     mu0 = mu0, sigma0_l = sigma0_l, alpha = alpha, beta = beta, 
#>     psi_l = psi_l, nu = nu, lambda = lambda, theta_l = theta_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.1472 5  0.6941 1.0351
#> beta_2_1    0.5 0.1279 5  0.4496 0.7733
#> beta_3_1   -0.1 0.1837 5 -0.3680 0.0905
#> beta_1_2    0.0 0.0931 5 -0.1952 0.0159
#> beta_2_2    0.6 0.1238 5  0.3981 0.6914
#> beta_3_2    0.4 0.1303 5  0.3027 0.6157
#> beta_1_3    0.0 0.0726 5 -0.0868 0.0796
#> beta_2_3    0.0 0.0700 5 -0.1075 0.0689
#> beta_3_3    0.5 0.1251 5  0.2849 0.5984
#> psi_1_1     0.1 0.0430 5  0.0283 0.1307
#> psi_2_2     0.1 0.0389 5  0.0391 0.1242
#> psi_3_3     0.1 0.1228 5  0.0323 0.3395
#> theta_1_1   0.2 0.0311 5  0.1957 0.2653
#> theta_2_2   0.2 0.0208 5  0.1833 0.2321
#> theta_3_3   0.2 0.0992 5  0.0142 0.2631
#> mu0_1_1     0.0 0.2121 5 -0.3388 0.1220
#> mu0_2_1     0.0 0.6807 5 -0.9925 0.5905
#> mu0_3_1     0.0 0.4071 5 -0.5921 0.3290
#> sigma0_1_1  1.0 0.4171 5  0.0639 0.9914
#> sigma0_2_1  0.2 0.2994 5 -0.2398 0.3937
#> sigma0_3_1  0.2 0.2760 5 -0.4190 0.2773
#> sigma0_2_2  1.0 0.5731 5  0.1729 1.4578
#> sigma0_3_2  0.2 0.6389 5 -0.8718 0.7498
#> sigma0_3_3  1.0 0.5732 5  0.7010 2.0259
summary(pb, type = "bc")
#> Call:
#> PBSSMFixed(R = R, path = path, prefix = prefix, n = n, time = time, 
#>     mu0 = mu0, sigma0_l = sigma0_l, alpha = alpha, beta = beta, 
#>     psi_l = psi_l, nu = nu, lambda = lambda, theta_l = theta_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.1472 5  0.6893 0.8651
#> beta_2_1    0.5 0.1279 5  0.4388 0.6034
#> beta_3_1   -0.1 0.1837 5 -0.2273 0.1159
#> beta_1_2    0.0 0.0931 5 -0.1201 0.0178
#> beta_2_2    0.6 0.1238 5  0.4236 0.6937
#> beta_3_2    0.4 0.1303 5  0.2873 0.5413
#> beta_1_3    0.0 0.0726 5 -0.0994 0.0533
#> beta_2_3    0.0 0.0700 5 -0.1133 0.0567
#> beta_3_3    0.5 0.1251 5  0.3903 0.6182
#> psi_1_1     0.1 0.0430 5  0.0518 0.1386
#> psi_2_2     0.1 0.0389 5  0.0706 0.1270
#> psi_3_3     0.1 0.1228 5  0.0224 0.1549
#> theta_1_1   0.2 0.0311 5  0.1943 0.2483
#> theta_2_2   0.2 0.0208 5  0.1826 0.2298
#> theta_3_3   0.2 0.0992 5  0.1616 0.2712
#> mu0_1_1     0.0 0.2121 5 -0.3452 0.1086
#> mu0_2_1     0.0 0.6807 5 -1.1172 0.2865
#> mu0_3_1     0.0 0.4071 5 -0.6252 0.3193
#> sigma0_1_1  1.0 0.4171 5  0.1364 1.0369
#> sigma0_2_1  0.2 0.2994 5 -0.2101 0.3938
#> sigma0_3_1  0.2 0.2760 5 -0.1779 0.3156
#> sigma0_2_2  1.0 0.5731 5  0.1976 1.4781
#> sigma0_3_2  0.2 0.6389 5 -0.7051 0.7916
#> sigma0_3_3  1.0 0.5732 5  0.6935 1.8237

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/