Simulate Random Drift Matrices with a Covariate from the Multivariate Normal Distribution
Source:R/RcppExports.R
SimPhiNCovariate.RdThis function simulates random drift matrices
from the multivariate normal distribution,
allowing the mean drift matrix to vary
as a linear function of a covariate
The function ensures that the generated drift matrices are stable
using TestPhi().
Usage
SimPhiNCovariate(
n,
phi0,
vcov_phi_vec_l,
phi1,
x,
margin = 0,
auto_ubound = 0,
phi_lbound = NULL,
phi_ubound = NULL,
bound = FALSE,
max_iter = 100000L
)Arguments
- n
Positive integer. Number of replications.
- phi0
Numeric matrix. Baseline drift matrix (\(\boldsymbol{\Phi}_0\)).
- vcov_phi_vec_l
Numeric matrix. Cholesky factorization (
t(chol(vcov_phi_vec))) of the sampling variance-covariance matrix of \(\mathrm{vec} \left( \boldsymbol{\Phi} \right)\).- phi1
Numeric matrix. Matrix of covariate effects mapping \(\mathbf{x}\) to \(\mathrm{vec}(\boldsymbol{\Phi})\).
- x
List of numeric vectors. Covariate values.
- margin
Numeric scalar specifying the stability threshold for the real part of the eigenvalues. The default
0.0corresponds to the imaginary axis; values less than0.0enforce a stricter stability margin.- auto_ubound
Numeric scalar specifying the upper bound for the diagonal elements of \(\boldsymbol{\Phi}\). Default is
0.0, requiring all diagonal values to be \(\leq 0\).- phi_lbound
Optional numeric matrix of same dim as
phi. Use NA for no lower bound.- phi_ubound
Optional numeric matrix of same dim as
phi. 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(),
LinSDEInterceptEta(),
LinSDEInterceptY(),
LinSDEMeanEta(),
LinSDEMeanY(),
ProjectToHurwitz(),
ProjectToStability(),
SSMCovEta(),
SSMCovY(),
SSMInterceptEta(),
SSMInterceptY(),
SSMMeanEta(),
SSMMeanY(),
SimAlphaN(),
SimBetaN(),
SimBetaN2(),
SimBetaNCovariate(),
SimCovDiagN(),
SimCovN(),
SimIotaN(),
SimMVN(),
SimMuN(),
SimNuN(),
SimPhiN(),
SimPhiN2(),
SimSSMFixed(),
SimSSMIVary(),
SimSSMLinGrowth(),
SimSSMLinGrowthIVary(),
SimSSMLinSDEFixed(),
SimSSMLinSDEIVary(),
SimSSMOUFixed(),
SimSSMOUIVary(),
SimSSMVARFixed(),
SimSSMVARIVary(),
SpectralRadius(),
TestPhi(),
TestPhiHurwitz(),
TestStability(),
TestStationarity()
Examples
n <- 5
phi0 <- matrix(
data = c(
-0.357, 0.771, -0.450,
0.0, -0.511, 0.729,
0, 0, -0.693
),
nrow = 3
)
vcov_phi_vec_l <- t(chol(0.001 * diag(9)))
# One scalar covariate per replication
phi1 <- matrix(data = 0, nrow = 9, ncol = 1)
phi1[1, 1] <- 0.10 # x shifts phi[1,1]
x <- list(c(0), c(1), c(-1), c(0.5), c(2))
SimPhiNCovariate(
n = n,
phi0 = phi0,
vcov_phi_vec_l = vcov_phi_vec_l,
phi1 = phi1,
x = x
)
#> [[1]]
#> [,1] [,2] [,3]
#> [1,] -0.3765914 -0.01058848 -0.04617385
#> [2,] 0.8166669 -0.54811423 -0.01558777
#> [3,] -0.4811700 0.68307304 -0.66308147
#>
#> [[2]]
#> [,1] [,2] [,3]
#> [1,] -0.1827693 -0.04749673 -0.02039162
#> [2,] 0.7541351 -0.53188626 0.08655416
#> [3,] -0.4355784 0.71807782 -0.64235630
#>
#> [[3]]
#> [,1] [,2] [,3]
#> [1,] -0.4355311 -0.009941172 -0.02135158
#> [2,] 0.7472695 -0.540460856 -0.05944341
#> [3,] -0.4138522 0.734597964 -0.71644021
#>
#> [[4]]
#> [,1] [,2] [,3]
#> [1,] -0.3917425 -0.01756875 0.001208828
#> [2,] 0.7840805 -0.48789034 0.017578063
#> [3,] -0.4818337 0.74712907 -0.708353500
#>
#> [[5]]
#> [,1] [,2] [,3]
#> [1,] -0.1258044 0.005440268 0.05875903
#> [2,] 0.7839044 -0.521210732 0.00491790
#> [3,] -0.4534969 0.687419498 -0.64692547
#>