Build the generator matrix of a continuous-time Markov chain
generator.RdThis function builds the infinitesimal generator matrix for a continuous-time Markov chain from an unconstrained parameter vector.
Arguments
- beta
parameters; either
a vector of length
nStates * (nStates-1), ora matrix of dimension
c(nStates * (nStates-1), p+1)if design matrixZis also provided.
- Z
optional covariate design matrix with or without intercept column, i.e. of dimension
c(nObs, p)orc(nObs, p+1). If provided,betaneeds to be a matrix of dimensionc(nStates * (nStates-1), p+1).- Eta
optional pre-calculated matrix of linear predictors of dimension
c(nObs, nStates * (nStates-1)). If provided,Zandbetawill be ignored.- byrow
logical indicating if the generator matrix should be filled by row
- report
logical, indicating whether the generator matrix
Qshould be reported from the fitted model. Defaults toTRUE, but only works if when automatic differentiation withRTMBis used.- param
depricated, please use argument
betainstead.
Value
infinitesimal generator matrix of dimension c(nStates, nStates) or array of such matrices of dimension c(nStates, nStates, nObs) if Z or Eta is provided.
Details
Off-diagonal entries are calculated as \(\exp(\beta_i)\) to ensure positivity. The diagonal entries are then set to the negative row sums, which is required for generator matrices.
If a design matrix Z or a matrix of linear predictors Eta is provided, the function will automatically call generator_g to build the generator matrix based on the design matrix and coefficient matrix.
In that case, the argument beta needs to be a matrix of coefficients of dimension c(nStates * (nStates-1), p+1), where the first column contains the intercepts.
See also
Other transition probability matrix functions:
generator_g(),
tpm(),
tpm_ct(),
tpm_emb(),
tpm_emb_g(),
tpm_g(),
tpm_g2(),
tpm_p()
Examples
# 2 states: 2 free off-diagonal elements
generator(rep(-1, 2))
#> S1 S2
#> S1 -0.3678794 0.3678794
#> S2 0.3678794 -0.3678794
# 3 states: 6 free off-diagonal elements
generator(rep(-2, 6))
#> S1 S2 S3
#> S1 -0.2706706 0.1353353 0.1353353
#> S2 0.1353353 -0.2706706 0.1353353
#> S3 0.1353353 0.1353353 -0.2706706