Computes $$\Pr(\text{State}_t = j \mid X_1, ..., X_T)$$ for a given HMM.
stateprobs(
delta,
Gamma,
allprobs,
trackID = NULL,
mod = NULL,
forecast = FALSE,
tod = NULL
)matrix of conditional state probabilities of dimension c(nObs, nStates)
initial distribution; either
a vector of length nStates,
a matrix of dimension c(nTracks, nStates) if trackID is provided, or
a model object as for mod, so that mod can be passed as the first argument
transition probability matrix; either
a matrix of dimension c(nStates, nStates),
an array of dimension c(nStates, nStates, nTracks) if trackID is provided,
an array of dimension c(nStates, nStates, nObs) for time-varying transition probabilities, or
an array of dimension c(nStates, nStates, L) for periodic transition probabilities, if tod is provided
matrix of state-dependent probabilities or density values of dimension c(nObs, nStates)
optional vector of length nObs containing nTracks unique IDs that separate tracks.
The observations of each track need to be consecutive.
optional model object containing delta, Gamma, allprobs, and
optionally trackID. When using RTMB::MakeADFun or qreml with
forward in the likelihood, these are reported automatically after model fitting
and the object returned by obj$report(), lama or qreml can be passed directly.
logical, indicating if forecast probabilities \(\Pr(\text{State}_t = j \mid X_1, ..., X_{t-1})\) should be calculated instead.
optional integer vector of length nObs with values in 1, ..., L, indexing the slices of Gamma for periodic models
Other decoding functions:
stateprobs_g(),
stateprobs_p(),
viterbi(),
viterbi_g(),
viterbi_p()
Gamma = tpm(c(-1,-2))
delta = stationary(Gamma)
allprobs = matrix(runif(10), nrow = 10, ncol = 2)
probs = stateprobs(delta, Gamma, allprobs)
Run the code above in your browser using DataLab