Calculate conditional local state probabilities in HMMs
stateprobs.RdComputes $$\Pr(\text{State}_t = j \mid X_1, ..., X_T)$$ for a given HMM.
Arguments
- delta
initial distribution; either
a vector of length
nStates, ora matrix of dimension
c(nTracks, nStates)iftrackIDis provided
- Gamma
transition probability matrix; either
a matrix of dimension
c(nStates, nStates),an array of dimension
c(nStates, nStates, nTracks)iftrackIDis provided, oran array of dimension
c(nStates, nStates, nObs)for time-varying transition probabilities, in which casestateprobs_gis called internally
- allprobs
matrix of state-dependent probabilities or density values of dimension
c(nObs, nStates)- trackID
optional vector of length
nObscontainingnTracksunique IDs that separate tracks- mod
optional model object containing
delta,Gamma,allprobs, and optionallytrackID. When usingRTMB::MakeADFunorqremlwithforwardin the likelihood, these are reported automatically after model fitting and the object returned byRTMB::report()orqremlcan be passed directly.- forecast
logical, indicating if forecast probabilities \(\Pr(\text{State}_t = j \mid X_1, ..., X_t)\) should be calculated instead.
See also
Other decoding functions:
stateprobs_g(),
stateprobs_p(),
viterbi(),
viterbi_g(),
viterbi_p()
Examples
Gamma = tpm(c(-1,-2))
delta = stationary(Gamma)
allprobs = matrix(runif(10), nrow = 10, ncol = 2)
probs = stateprobs(delta, Gamma, allprobs)