View source: R/tpm_functions.R
| tpm | R Documentation |
Markov chains are parametrised in terms of a transition probability matrix \Gamma, for which each row contains a conditional probability distribution of the next state given the current state.
Hence, each row has entries between 0 and 1 that need to sum to one.
For numerical optimisation, we parameterise in terms of unconstrained parameters, thus this function computes said matrix from an unconstrained parameter vector via the inverse multinomial logistic link (also known as softmax) applied to each row.
tpm(
beta,
Z = NULL,
Eta = NULL,
byrow = FALSE,
ref = NULL,
ad = NULL,
report = TRUE,
param = NULL
)
beta |
parameters; either
|
Z |
optional covariate design matrix with or without intercept column, i.e. of dimension |
Eta |
optional pre-calculated matrix of linear predictors of dimension |
byrow |
logical indicating if each transition probability matrix should be filled by row.
Defaults to |
ref |
optional integer vector of length |
ad |
logical; whether to use automatic differentiation. Determined automatically — for debugging only. |
report |
logical; if |
param |
depricated, please use argument |
Transition probability matrix of dimension c(nStates, nStates) or array of such matrices of dimension c(nStates, nStates, nObs) if Z or Eta is provided.
Other transition probability matrix functions:
generator(),
generator_g(),
tpm_ct(),
tpm_emb(),
tpm_emb_g(),
tpm_g(),
tpm_g2(),
tpm_p()
## homogeneous Markov chain
# 2 states: 2 = 2*(2-1) free off-diagonal elements
par <- rep(-2, 2)
Gamma <- tpm(par)
# 3 states: 6 = 3*(3-1) free off-diagonal elements
par <- rep(-3, 6)
Gamma <- tpm(par)
# 4 states: 12 = 4*(4-1) free off-diagonal elements
par <- rep(-4, 12)
Gamma <- tpm(par)
## inhomogeneous Markov chain
# t.p.m. depends on covariates
z1 <- runif(100); z2 <- runif(100) # 2 covariates
Z <- cbind(1, z1, z2) # design matrix
beta0 <- c(-2, -2); beta1 = c(1, -2); beta2 = c(2, -1) # coefficients for intercept and covariates
beta <- cbind(beta0, beta1, beta2) # coefficient matrix; with intercepts!
Gamma <- tpm(beta, Z) # array with 100 slices
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.