Build all transition probability matrices of an inhomogeneous HMM
tpm_g.RdIn an HMM, we often model the influence of covariates on the state process by linking them to the transition probabiltiy matrix.
Most commonly, this is done by specifying a linear predictor
$$ \eta_{ij}^{(t)} = \beta^{(ij)}_0 + \beta^{(ij)}_1 z_{t1} + \dots + \beta^{(ij)}_p z_{tp} $$
for each off-diagonal element (\(i \neq j\)) of the transition probability matrix and then applying the inverse multinomial logistic link (also known as softmax) to each row.
This function efficiently calculates all transition probabilty matrices for a given design matrix Z and parameter matrix beta.
Usage
tpm_g(
  Z,
  beta,
  Eta = NULL,
  byrow = FALSE,
  ref = NULL,
  ad = NULL,
  report = TRUE,
  sparse = FALSE
)Arguments
- Z
 covariate design matrix with or without intercept column, i.e. of dimension c(n, p) or c(n, p+1)
If
Zhas only p columns, an intercept column of ones will be added automatically.- beta
 matrix of coefficients for the off-diagonal elements of the transition probability matrix
Needs to be of dimension c(N*(N-1), p+1), where the first column contains the intercepts.
- Eta
 optional pre-calculated linear predictor matrix of dimension c(n, N*(N-1)).
Usually,
Etais calculated asZ %*% t(beta). If provided, noZandbetaare necessary and will be ignored.- byrow
 logical indicating if each transition probability matrix should be filled by row
Defaults to
FALSE, but should be set toTRUEif one wants to work with a matrix of beta parameters returned by popular HMM packages likemoveHMM,momentuHMM, orhmmTMB.- ref
 Optional integer vector of length N giving, for each row, the column index of the reference state (its predictor is fixed to 0). Defaults to the diagonal (
ref = 1:N).- ad
 optional logical, indicating whether automatic differentiation with
RTMBshould be used. By default, the function determines this itself.- report
 logical, indicating whether the coefficient matrix
betashould be reported from the fitted model. Defaults toTRUE, but only works ifad = TRUE.- sparse
 logical, indicating whether sparsity in the rows of
Zshould be exploited.