Skip to contents

Computes $$\Pr(S_t = j \mid X_1, ..., X_T)$$ for periodically inhomogeneous HMMs

Usage

stateprobs_p(
  delta,
  Gamma,
  allprobs,
  tod,
  trackID = NULL,
  mod = NULL,
  forecast = FALSE
)

Arguments

delta

initial or stationary distribution of length nStates, or matrix of dimension c(nTracks, nStates) for nTracks independent tracks, if trackID is provided

This could e.g. be the periodically stationary distribution (for each track) as computed by stationary_p.

Gamma

array of transition probability matrices for each time point in the cycle of dimension c(nStates, nStates, L), where L is the length of the cycle.

allprobs

matrix of state-dependent probabilities/ density values of dimension c(nObs, nStates)

tod

(Integer valued) variable for cycle indexing in 1, ..., L, mapping the data index to a generalised time of day (length nObs). For half-hourly data L = 48. It could, however, also be day of year for daily data and L = 365.

trackID

optional vector of length nObs containing nTracks unique IDs that separate tracks. The observations of each track need to be consecutive.

mod

optional model object containing initial distribution delta, transition probability matrix Gamma, matrix of state-dependent probabilities allprobs, and potentially a trackID variable

If you are using automatic differentiation either with RTMB::MakeADFun or qreml and include forward_p in your likelihood function, the objects needed for state decoding are automatically reported after model fitting. Hence, you can pass the model object obtained from obj$report(), lama or qreml directly to this function.

forecast

logical, indicating if forecast probabilities \(\Pr(S_t = j \mid X_1, ..., X_{t-1})\) should be calculated instead.

Value

matrix of conditional state probabilities of dimension c(nObs, nStates)

Details

Deprecated: please use stateprobs with argument tod instead.

See also

Examples

L = 24
beta = matrix(c(-1, 2, -1, -2, 1, -1), nrow = 2, byrow = TRUE)
Gamma = tpm_p(1:L, L, beta, degree = 1)
delta = stationary_p(Gamma, 2) # for tod[1] = 1
allprobs = matrix(runif(200), nrow = 100, ncol = 2)
tod = rep(1:24, 5)[1:100]

probs = stateprobs_p(delta, Gamma, allprobs, tod)
#> stateprobs_p() is deprecated, please use stateprobs(..., tod = tod) for periodic models instead.