Simulate Transition Matrices with a Covariate from the Multivariate Normal Distribution
Source:R/RcppExports.R
SimBetaNCovariate.RdThis function simulates random transition matrices from a multivariate
normal distribution, allowing the mean transition matrix to vary as a
linear function of a covariate.
The function ensures that the generated transition matrices are stationary
using TestStationarity() with a rejection sampling approach.
Usage
SimBetaNCovariate(
n,
beta0,
vcov_beta_vec_l,
beta1,
x,
margin = 1,
beta_lbound = NULL,
beta_ubound = NULL,
bound = FALSE,
max_iter = 100000L
)Arguments
- n
Positive integer. Number of replications.
- beta0
Numeric matrix. Baseline transition matrix \(\boldsymbol{\beta}_0\) corresponding to \(\mathbf{x} = \mathbf{0}\).
- vcov_beta_vec_l
Numeric matrix. Cholesky factorization (
t(chol(vcov_beta_vec))) of the sampling variance-covariance matrix of \(\mathrm{vec} \left( \boldsymbol{\beta} \right)\).- beta1
Numeric matrix. Matrix of covariate effects mapping \(\mathbf{x}\) to \(\mathrm{vec}(\boldsymbol{\beta})\).
- x
List of numeric vectors. Covariate values.
- margin
Numeric scalar specifying the stationarity threshold. Values less than 1 indicate stricter stationarity criteria.
- beta_lbound
Optional numeric matrix of same dim as
beta. Use NA for no lower bound.- beta_ubound
Optional numeric matrix of same dim as
beta. Use NA for no upper bound.- bound
Logical; if TRUE, resample until all elements respect bounds (NA bounds ignored).
- max_iter
Safety cap on resampling attempts per draw.
See also
Other Simulation of State Space Models Data Functions:
LinSDE2SSM(),
LinSDECovEta(),
LinSDECovY(),
LinSDEMeanEta(),
LinSDEMeanY(),
ProjectToHurwitz(),
ProjectToStability(),
SSMCovEta(),
SSMCovY(),
SSMMeanEta(),
SSMMeanY(),
SimAlphaN(),
SimBetaN(),
SimBetaN2(),
SimCovDiagN(),
SimCovN(),
SimIotaN(),
SimNuN(),
SimPhiN(),
SimPhiN2(),
SimPhiNCovariate(),
SimSSMFixed(),
SimSSMIVary(),
SimSSMLinGrowth(),
SimSSMLinGrowthIVary(),
SimSSMLinSDEFixed(),
SimSSMLinSDEIVary(),
SimSSMOUFixed(),
SimSSMOUIVary(),
SimSSMVARFixed(),
SimSSMVARIVary(),
SpectralRadius(),
TestPhi(),
TestPhiHurwitz(),
TestStability(),
TestStationarity()
Examples
n <- 5
beta0 <- matrix(
data = c(
0.7, 0.5, -0.1,
0.0, 0.6, 0.4,
0, 0, 0.5
),
nrow = 3
)
vcov_beta_vec_l <- t(chol(0.001 * diag(9)))
# One scalar covariate per replication
beta1 <- matrix(data = 0, nrow = 9, ncol = 1)
beta1[1, 1] <- 0.10 # x shifts beta[1,1]
x <- list(c(0), c(1), c(-1), c(0.5), c(2))
SimBetaNCovariate(
n = n,
beta0 = beta0,
vcov_beta_vec_l = vcov_beta_vec_l,
beta1 = beta1,
x = x
)
#> [[1]]
#> [,1] [,2] [,3]
#> [1,] 0.73714275 -0.01569974 -0.01051835
#> [2,] 0.51045990 0.62092334 -0.02241639
#> [3,] -0.05715703 0.41446261 0.49795605
#>
#> [[2]]
#> [,1] [,2] [,3]
#> [1,] 0.79546249 0.000930592 0.01095603
#> [2,] 0.48309397 0.562960936 0.02006462
#> [3,] -0.09565399 0.404087614 0.47342670
#>
#> [[3]]
#> [,1] [,2] [,3]
#> [1,] 0.63629846 0.001422849 0.008760512
#> [2,] 0.50411427 0.588666045 -0.046495787
#> [3,] -0.06590982 0.419744641 0.526820311
#>
#> [[4]]
#> [,1] [,2] [,3]
#> [1,] 0.7799245 0.03766229 -0.01601237
#> [2,] 0.4905213 0.58185885 -0.04205268
#> [3,] -0.1251074 0.32625402 0.50291231
#>
#> [[5]]
#> [,1] [,2] [,3]
#> [1,] 0.8692902 -0.0004960935 0.047489421
#> [2,] 0.4895781 0.5295633964 -0.001605503
#> [3,] -0.1546900 0.3846987284 0.559527733
#>