Using a covariate only for one of the transition probabilities #26
-
Hi! I wonder if there is a way (if it even make sense) to use a covariate that affects only the transition probability from s1 to s2, but not from s2 to s1? Some more details, if needed: Would appreciate your help. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi, yes this is possible. You can specify the
Here is an example with a dummy data set, just to illustrate the syntax. library(hmmTMB)
data <- data.frame(x1 = rnorm(1000))
# Include effect of x1 on Pr(1 > 2) but not on Pr(2 > 1)
formula_matrix <- matrix(c(".", "~x1",
"~1", "."),
nrow = 2, byrow = TRUE)
hid <- MarkovChain$new(data = data,
formula = formula_matrix,
n_states = 2) We can then check that the model has a slope parameter for the effect of > hid$coeff_fe()
[,1]
S1>S2.(Intercept) -2.197225
S1>S2.x1 0.000000
S2>S1.(Intercept) -2.197225 You can find a real example in Section 7.2.2 of Michelot (2022). hmmTMB: Hidden Markov models with flexible covariate effects in R. arXiv preprint, arXiv:2211.14139. Let me know if anything is unclear! |
Beta Was this translation helpful? Give feedback.
Hi, yes this is possible. You can specify the
formula
argument ofMarkovChain$new()
as a matrix, where each entry is the formula corresponding to a transition probability.The formulas in the matrix should be strings, e.g.,
"~x1"
, or"~ x1 * x2"
. The mgcv formula syntax for non-linear and random effects uses quotes, and those should be written as single quotes here, e.g.,"~s(ID, bs = 're')"
.The diagonal entries should be
"."
because diagonal transition probabilities are not estimated so they can't have a formula.Here is an example with a dummy data set, just to illustrate the syntax.