Learn R Programming

simStateSpace (version 1.2.14)

SimPhiNCovariate: Simulate Random Drift Matrices with a Covariate from the Multivariate Normal Distribution

Description

This 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
)

Value

Returns a list of random drift matrices.

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.0 corresponds to the imaginary axis; values less than 0.0 enforce 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.

Author

Ivan Jacob Agaloos Pesigan

See Also

Other Simulation of State Space Models Data Functions: LinSDE2SSM(), LinSDECovEta(), LinSDECovY(), LinSDEMeanEta(), LinSDEMeanY(), ProjectToHurwitz(), ProjectToStability(), SSMCovEta(), SSMCovY(), SSMMeanEta(), SSMMeanY(), SimAlphaN(), SimBetaN(), SimBetaN2(), SimBetaNCovariate(), SimCovDiagN(), SimCovN(), SimIotaN(), SimNuN(), SimPhiN(), SimPhiN2(), SimSSMFixed(), SimSSMIVary(), SimSSMLinGrowth(), SimSSMLinGrowthIVary(), SimSSMLinSDEFixed(), SimSSMLinSDEIVary(), SimSSMOUFixed(), SimSSMOUIVary(), SimSSMVARFixed(), SimSSMVARIVary(), SpectralRadius(), TestPhi(), TestPhiHurwitz(), TestStability(), TestStationarity()

Examples

Run this code
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
)

Run the code above in your browser using DataLab