Parametric Bootstrap (The Vector Autoregressive Model)
Ivan Jacob Agaloos Pesigan
2025-01-18
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] 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