forward_backward {seqHMM} | R Documentation |
Forward and Backward Probabilities for Hidden Markov Model
Description
The forward_backward
function computes scaled forward and backward probabilities of a hidden Markov model.
Usage
forward_backward(model, forward_only = FALSE, log_space = FALSE, threads = 1)
Arguments
model |
Object of class |
forward_only |
If |
log_space |
Compute forward and backward probabilities in logarithmic scale instead of scaling.
The default is |
threads |
Number of threads used in parallel computing. The default is 1. |
Value
List with components
forward_probs |
If |
backward_probs |
Scaled backward probabilities ( |
scaling_factors |
Sum of non-scaled forward probabilities at each time point.
Only computed if |
In case of multiple observations, these are computed independently for each sequence.
Examples
# Load a pre-defined MHMM
data("mhmm_biofam")
# Compute forward and backward probabilities
fb <- forward_backward(mhmm_biofam)
# The most probable hidden state at time t
# given the observations up to time t for the first subject:
apply(fb$forward_probs[, , 1], 2, which.max)