Learn R Programming

LaMa (version 2.1.2)

generator_g: Build generator matrices of a continuous-time Markov chain

Description

This function builds infinitesimal generator matrices for a continuous-time Markov chain based on a design matrix and coefficient matrix.

Usage

generator_g(Z, beta, Eta = NULL, byrow = FALSE, report = TRUE)

Value

array of infinitesimal generator matrices of dimension c(nStates, nStates, nObs)

Arguments

Z

Covariate design matrix with or without intercept column, i.e. of dimension c(nObs, p) or c(nObs, p+1). If not provided, intercept column is added automatically.

beta

Matrix of coefficients for the off-diagonal elements of the generator matrix of dimension c(nStates * (nStates-1), p+1). First columns contains the intercepts.

Eta

optional pre-calculated matrix of linear predictors of dimension c(nObs, nStates * (nStates-1)). If provided, no Z and beta are necessary and will be ignored.

byrow

logical indicating if the generator matrices should be filled by row

report

logical, indicating whether the generator matrices Q should be reported from the fitted model. Defaults to TRUE, but only works if when automatic differentiation with RTMB is used.

Details

Off-diagonal entries are calculated as \(\exp(Z \beta_i)\) to ensure positivity. The diagonal entries are then set to the negative row sums, which is required for generator matrices.

See Also

Other transition probability matrix functions: generator(), tpm(), tpm_ct(), tpm_emb(), tpm_emb_g(), tpm_g(), tpm_g2(), tpm_p()

Examples

Run this code
# 2 states: 2 free off-diagonal elements
generator(rep(-1, 2))
# 3 states: 6 free off-diagonal elements
generator(rep(-2, 6))

Run the code above in your browser using DataLab