tpm_g function

Build all transition probability matrices of an inhomogeneous HMM

Build all transition probability matrices of an inhomogeneous HMM

In 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 [REMOVE_ME]ηij(t)=β0(ij)+β1(ij)zt1++βp(ij)ztp[REMOVEME2] \eta_{ij}^{(t)} = \beta^{(ij)}_0 + \beta^{(ij)}_1 z_{t1} + \dots + \beta^{(ij)}_p z_{tp} [REMOVE_ME_2]

for each off-diagonal element (iji \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.

tpm_g(Z, beta, byrow = FALSE, ad = NULL, report = TRUE)

Arguments

  • Z: covariate design matrix with or without intercept column, i.e. of dimension c(n, p) or c(n, p+1)

    If Z has 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.

  • byrow: logical indicating if each transition probability matrix should be filled by row

    Defaults to FALSE, but should be set to TRUE if one wants to work with a matrix of beta parameters returned by popular HMM packages like moveHMM, momentuHMM, or hmmTMB.

  • ad: optional logical, indicating whether automatic differentiation with RTMB should be used. By default, the function determines this itself.

  • report: logical, indicating whether the coefficient matrix beta should be reported from the fitted model. Defaults to TRUE, but only works if ad = TRUE.

Returns

array of transition probability matrices of dimension c(N,N,n)

Description

In 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

ηij(t)=β0(ij)+β1(ij)zt1++βp(ij)ztp \eta_{ij}^{(t)} = \beta^{(ij)}_0 + \beta^{(ij)}_1 z_{t1} + \dots + \beta^{(ij)}_p z_{tp}

for each off-diagonal element (iji \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.

Examples

Z = matrix(runif(200), ncol = 2) beta = matrix(c(-1, 1, 2, -2, 1, -2), nrow = 2, byrow = TRUE) Gamma = tpm_g(Z, beta)

See Also

Other transition probability matrix functions: generator(), tpm(), tpm_cont(), tpm_emb(), tpm_emb_g(), tpm_p()