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.74284297 0.01446261 -0.002043949
#> [2,]  0.48430026 0.58948165  0.001537672
#> [3,] -0.07907666 0.37758361  0.495462488
#> 
#> [[2]]
#>            [,1]        [,2]        [,3]
#> [1,]  0.8043460 0.004087614 -0.02657330
#> [2,]  0.5009306 0.610956032  0.06268561
#> [3,] -0.1370391 0.420064618  0.53629846
#> 
#> [[3]]
#>            [,1]       [,2]       [,3]
#> [1,]  0.6340902 0.01974464 0.02682031
#> [2,]  0.5014228 0.60876051 0.04162174
#> [3,] -0.1113340 0.35350421 0.52992448
#> 
#> [[4]]
#>            [,1]        [,2]        [,3]
#> [1,]  0.7248926 -0.07374598 0.002912312
#> [2,]  0.5376623  0.58398763 0.038392832
#> [3,] -0.1181411  0.35794732 0.469290227
#> 
#> [[5]]
#>            [,1]        [,2]         [,3]
#> [1,]  0.8453100 -0.01530127 0.0595277334
#> [2,]  0.4995039  0.64748942 0.0006538527
#> [3,] -0.1704366  0.39839450 0.5065986906
#>