Learn R Programming

HMMHSMM (version 0.1.0)

globaldecodeHSMM: Global Decoding of Hidden Semi-Markov Models

Description

Computes the most likely hidden state sequence for a univariate time series using a fitted Hidden Semi-Markov Model (HSMM) via the Viterbi algorithm.

Usage

globaldecodeHSMM(x, M = NA, HSMM, obsdist, dwelldist, shift = FALSE)

Value

A numeric vector of length length(x), giving the most likely hidden state at each observation.

Arguments

x

Numeric vector. The observed data sequence.

M

Integer. Maximum dwell time to consider for semi-Markov states. Defaults to min(length(x), 1000) if NA.

HSMM

A fitted HSMM object (output from findmleHSMM) containing the estimated model parameters.

obsdist

Character string. Observation distribution. Supported distributions: "norm", "pois", "weibull", "zip", "nbinom", "zinb", "exp", "gamma", "lnorm", "gev", "ZInormal", "ZIgamma".

dwelldist

Character string. Dwell-time distribution. Supported distributions: "pois", "nbinom", "betabinom".

shift

Logical character. Whether or not the dwell distribution has been shifted by a shift parameter. Defaults to FALSE.

Author

Aimee Cody

Details

This function computes the global most probable state sequence (Viterbi path) for a sequence of observations under a Hidden Semi-Markov Model using the parameters contained in a fitted HSMM object. The function calculates observation log-probabilities, dwell-time log-probabilities, and forward log-probabilities to determine the Viterbi path.

See Also

findmleHSMM, for estimating HSMM parameters from data. generateHSMM, for simulating HSMM data. localdecodeHSMM, for local decoding of HSMM states. globaldecodeHMM, for global decoding hidden Markov models.

Examples

Run this code
J <- 3
Pi <- matrix(c(0.0, 0.6, 0.4,
               0.5, 0.0, 0.5,
               0.3, 0.7, 0.0), nrow = J, byrow = TRUE)

obspar <- list(
  mean = c(4, 2, 6),
  sd   = c(1, 1, 2)
)

dwellpar <- list(
  lambda = c(3, 5, 4)
)

# Simulate HSMM data
sim <- generateHSMM(n = 1000, J = J, obsdist = "norm",
                    dwelldist = "pois", obspar = obspar,
                    dwellpar = dwellpar, Pi = Pi)

# Fit HSMM using the true parameters
HSMM_true <- findmleHSMM(x = sim$x, J = J, M = 100,
                          obsdist = "norm", dwelldist = "pois",
                          obspar = obspar, dwellpar = dwellpar,
                          Pi = Pi)

# Decode states using globaldecodeHSMM
states <- globaldecodeHSMM(x = sim$x, M = 100, HSMM = HSMM_true,
                           obsdist = "norm", dwelldist = "pois")

head(states)

Run the code above in your browser using DataLab