Parametric Bootstrap (The Vector Autoregressive Model)
Ivan Jacob Agaloos Pesigan
2025-02-14
Source:vignettes/pb-var.Rmd
pb-var.Rmd
Model
The measurement model is given by where represents a vector of observed variables and a vector of latent variables for individual and time . Since the observed and latent variables are equal, we only generate data from the dynamic structure.
The dynamic structure is given by where , , and are random variables, and , , and are model parameters. Here, is a vector of latent variables at time and individual , represents a vector of latent variables at time and individual , and represents a vector of dynamic noise at time and individual . denotes a vector of intercepts, a matrix of autoregression and cross regression coefficients, and the covariance matrix of .
An alternative representation of the dynamic noise is given by where .
Parameters
Notation
Let be the number of time points and be the number of individuals.
Let the initial condition be given by
Let the constant vector be given by
Let the transition matrix be given by
Let the dynamic process noise be given by
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)
#> est se R 2.5% 97.5%
#> beta_1_1 0.7 0.0280 5 0.6634 0.7330
#> beta_2_1 0.5 0.0261 5 0.4794 0.5376
#> beta_3_1 -0.1 0.0301 5 -0.1475 -0.0760
#> beta_1_2 0.0 0.0486 5 -0.0489 0.0495
#> beta_2_2 0.6 0.0148 5 0.5847 0.6166
#> beta_3_2 0.4 0.0201 5 0.3629 0.4124
#> beta_1_3 0.0 0.0367 5 -0.0568 0.0305
#> beta_2_3 0.0 0.0203 5 -0.0112 0.0385
#> beta_3_3 0.5 0.0227 5 0.4716 0.5200
#> psi_1_1 0.1 0.0065 5 0.0880 0.1030
#> psi_2_2 0.1 0.0040 5 0.0942 0.1035
#> psi_3_3 0.1 0.0047 5 0.0947 0.1057
#> mu0_1_1 0.0 0.7384 5 -0.9757 0.8926
#> mu0_2_1 0.0 0.4396 5 -0.5231 0.5924
#> mu0_3_1 0.0 0.3699 5 -0.6983 0.2269
#> sigma0_1_1 1.0 0.8489 5 0.3086 2.2269
#> sigma0_2_1 0.2 0.3379 5 -0.3639 0.4107
#> sigma0_3_1 0.2 0.3344 5 -0.1751 0.6238
#> sigma0_2_2 1.0 0.3817 5 0.2378 1.0539
#> sigma0_3_2 0.2 0.2974 5 -0.0067 0.7087
#> sigma0_3_3 1.0 0.7525 5 0.2928 2.0012
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.0280 5 0.6677 0.7349
#> beta_2_1 0.5 0.0261 5 0.4848 0.5422
#> beta_3_1 -0.1 0.0301 5 -0.1435 -0.0750
#> beta_1_2 0.0 0.0486 5 -0.0496 0.0475
#> beta_2_2 0.6 0.0148 5 0.5847 0.6171
#> beta_3_2 0.4 0.0201 5 0.3673 0.4132
#> beta_1_3 0.0 0.0367 5 -0.0256 0.0347
#> beta_2_3 0.0 0.0203 5 -0.0120 0.0322
#> beta_3_3 0.5 0.0227 5 0.4723 0.5203
#> psi_1_1 0.1 0.0065 5 0.0893 0.1032
#> psi_2_2 0.1 0.0040 5 0.0950 0.1035
#> psi_3_3 0.1 0.0047 5 0.0944 0.1053
#> mu0_1_1 0.0 0.7384 5 -1.0545 0.7686
#> mu0_2_1 0.0 0.4396 5 -0.4268 0.6248
#> mu0_3_1 0.0 0.3699 5 -0.2398 0.2557
#> sigma0_1_1 1.0 0.8489 5 0.2877 2.1599
#> sigma0_2_1 0.2 0.3379 5 -0.3993 0.4029
#> sigma0_3_1 0.2 0.3344 5 -0.2298 0.4150
#> sigma0_2_2 1.0 0.3817 5 0.3415 1.0726
#> sigma0_3_2 0.2 0.2974 5 0.0217 0.7383
#> sigma0_3_3 1.0 0.7525 5 0.4639 2.1281