Skip to contents

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

Value

Returns a list of random transition matrices.

Author

Ivan Jacob Agaloos Pesigan

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.73036823 0.01429155  0.01462578
#> [2,]  0.52649681 0.58576430 -0.01684809
#> [3,] -0.09953784 0.36629745  0.48667642
#> 
#> [[2]]
#>            [,1]       [,2]        [,3]
#> [1,]  0.8134643 0.01219682 -0.02611926
#> [2,]  0.5396417 0.63603814  0.04816789
#> [3,] -0.1243459 0.35616216  0.50670407
#> 
#> [[3]]
#>            [,1]      [,2]       [,3]
#> [1,]  0.5689039 0.0076459 0.03714275
#> [2,]  0.5728070 0.6275588 0.01045990
#> [3,] -0.1382798 0.4065403 0.54284297
#> 
#> [[4]]
#>            [,1]        [,2]         [,3]
#> [1,]  0.7709233 -0.02241639 -0.004537512
#> [2,]  0.5144626  0.59795605 -0.016906034
#> [3,] -0.1105184  0.40153767  0.504346010
#> 
#> [[5]]
#>             [,1]       [,2]        [,3]
#> [1,]  0.86296094 0.02006462 0.036298455
#> [2,]  0.50408761 0.57342670 0.004114273
#> [3,] -0.08904397 0.46268561 0.534090175
#>