Parametric Bootstrap (The OrnsteinβUhlenbeck Model)
Ivan Jacob Agaloos Pesigan
2025-02-14
Source:vignettes/pb-ou.Rmd
pb-ou.Rmd
Model
The measurement model is given by where , , and are random variables and , , and are model parameters. represents a vector of observed random variables, a vector of latent random variables, and a vector of random measurement errors, at time and individual . denotes a vector of intercepts, a matrix of factor loadings, and the covariance matrix of .
An alternative representation of the measurement error is given by where is a vector of independent standard normal random variables and .
The dynamic structure is given by where is the long-term mean or equilibrium level, is the rate of mean reversion, determining how quickly the variable returns to its mean, is the matrix of volatility or randomness in the process, and is a Wiener process or Brownian motion, which represents random fluctuations.
Parameters
Notation
Let be the number of time points and be the number of individuals.
Let the measurement model intecept vector be given by
Let the factor loadings matrix be given by
Let the measurement error covariance matrix be given by
Let the initial condition be given by
Let the long-term mean vector be given by
Let the rate of mean reversion matrix be given by
Let the dynamic process noise covariance matrix be given by
Let .
R Function Arguments
n
#> [1] 5
time
#> [1] 100
delta_t
#> [1] 0.1
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
mu
#> [1] 0 0 0
phi
#> [,1] [,2] [,3]
#> [1,] -0.357 0.000 0.000
#> [2,] 0.771 -0.511 0.000
#> [3,] -0.450 0.729 -0.693
sigma
#> [,1] [,2] [,3]
#> [1,] 0.24455556 0.02201587 -0.05004762
#> [2,] 0.02201587 0.07067800 0.01539456
#> [3,] -0.05004762 0.01539456 0.07553061
sigma_l # sigma_l <- t(chol(sigma))
#> [,1] [,2] [,3]
#> [1,] 0.49452559 0.0000000 0.000000
#> [2,] 0.04451917 0.2620993 0.000000
#> [3,] -0.10120330 0.0759256 0.243975
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 <- "ou"
We use the PBSSMOUFixed
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 OrnsteinβUhlenbeck model multiple times is computationally intensive.
library(bootStateSpace)
pb <- PBSSMOUFixed(
R = R,
path = path,
prefix = prefix,
n = n,
time = time,
delta_t = delta_t,
mu0 = mu0,
sigma0_l = sigma0_l,
mu = mu,
phi = phi,
sigma_l = sigma_l,
nu = nu,
lambda = lambda,
theta_l = theta_l,
ncores = parallel::detectCores(),
seed = 42
)
summary(pb)
#> Call:
#> PBSSMOUFixed(R = R, path = path, prefix = prefix, n = n, time = time,
#> delta_t = delta_t, mu0 = mu0, sigma0_l = sigma0_l, mu = mu,
#> phi = phi, sigma_l = sigma_l, nu = nu, lambda = lambda, theta_l = theta_l,
#> ncores = parallel::detectCores(), seed = 42)
#> est se R 2.5% 97.5%
#> phi_1_1 -0.3570 0.0915 5 -0.2905 -0.0677
#> phi_2_1 0.7710 0.2973 5 0.4056 1.1398
#> phi_3_1 -0.4500 0.1507 5 -0.6873 -0.3524
#> phi_1_2 0.0000 0.1110 5 -0.4812 -0.2093
#> phi_2_2 -0.5110 0.2813 5 -0.9066 -0.2762
#> phi_3_2 0.7290 0.1325 5 0.6434 0.9556
#> phi_1_3 0.0000 0.1592 5 -0.0033 0.3680
#> phi_2_3 0.0000 0.1793 5 -0.1667 0.2364
#> phi_3_3 -0.6930 0.0971 5 -0.8155 -0.5816
#> sigma_1_1 0.2446 0.0501 5 0.1767 0.3029
#> sigma_2_1 0.0220 0.0313 5 -0.0319 0.0398
#> sigma_3_1 -0.0500 0.0420 5 -0.1246 -0.0279
#> sigma_2_2 0.0707 0.0480 5 0.0221 0.1345
#> sigma_3_2 0.0154 0.0174 5 0.0133 0.0523
#> sigma_3_3 0.0755 0.0326 5 0.0253 0.1067
#> theta_1_1 0.2000 0.0195 5 0.1681 0.2093
#> theta_2_2 0.2000 0.0181 5 0.1939 0.2347
#> theta_3_3 0.2000 0.0118 5 0.1908 0.2162
#> mu0_1_1 0.0000 0.1985 5 -0.2841 0.1974
#> mu0_2_1 0.0000 0.2249 5 -0.4795 0.0903
#> mu0_3_1 0.0000 0.2002 5 0.2694 0.7245
#> sigma0_1_1 1.0000 0.6896 5 0.1709 1.6286
#> sigma0_2_1 0.2000 0.7082 5 -0.2206 1.3790
#> sigma0_3_1 0.2000 0.4829 5 -0.0541 1.1038
#> sigma0_2_2 1.0000 0.5403 5 0.1653 1.5218
#> sigma0_3_2 0.2000 0.4366 5 -0.1888 0.9029
#> sigma0_3_3 1.0000 0.4151 5 0.2797 1.3094
summary(pb, type = "bc")
#> Call:
#> PBSSMOUFixed(R = R, path = path, prefix = prefix, n = n, time = time,
#> delta_t = delta_t, mu0 = mu0, sigma0_l = sigma0_l, mu = mu,
#> phi = phi, sigma_l = sigma_l, nu = nu, lambda = lambda, theta_l = theta_l,
#> ncores = parallel::detectCores(), seed = 42)
#> est se R 2.5% 97.5%
#> phi_1_1 -0.3570 0.0915 5 -0.3056 -0.3056
#> phi_2_1 0.7710 0.2973 5 0.4387 1.1650
#> phi_3_1 -0.4500 0.1507 5 -0.6977 -0.3539
#> phi_1_2 0.0000 0.1110 5 -0.2025 -0.2025
#> phi_2_2 -0.5110 0.2813 5 -0.9622 -0.3598
#> phi_3_2 0.7290 0.1325 5 0.6402 0.9317
#> phi_1_3 0.0000 0.1592 5 -0.0252 0.3118
#> phi_2_3 0.0000 0.1793 5 -0.1261 0.2696
#> phi_3_3 -0.6930 0.0971 5 -0.8057 -0.5734
#> sigma_1_1 0.2446 0.0501 5 0.1843 0.3074
#> sigma_2_1 0.0220 0.0313 5 -0.0287 0.0406
#> sigma_3_1 -0.0500 0.0420 5 -0.1148 -0.0277
#> sigma_2_2 0.0707 0.0480 5 0.0431 0.1429
#> sigma_3_2 0.0154 0.0174 5 0.0132 0.0496
#> sigma_3_3 0.0755 0.0326 5 0.0326 0.1085
#> theta_1_1 0.2000 0.0195 5 0.1684 0.2098
#> theta_2_2 0.2000 0.0181 5 0.1937 0.2280
#> theta_3_3 0.2000 0.0118 5 0.1901 0.2162
#> mu0_1_1 0.0000 0.1985 5 -0.3199 0.0697
#> mu0_2_1 0.0000 0.2249 5 -0.1604 0.1127
#> mu0_3_1 0.0000 0.2002 5 0.2657 0.2657
#> sigma0_1_1 1.0000 0.6896 5 0.1630 1.5791
#> sigma0_2_1 0.2000 0.7082 5 -0.1815 1.4226
#> sigma0_3_1 0.2000 0.4829 5 -0.0835 0.6530
#> sigma0_2_2 1.0000 0.5403 5 0.6522 1.6013
#> sigma0_3_2 0.2000 0.4366 5 -0.2111 0.7772
#> sigma0_3_3 1.0000 0.4151 5 0.6142 1.3516