posterior_probs: Posterior Probabilities for (Mixture) Hidden Markov Models

Description Usage Arguments Value Examples

View source: R/posterior_probs.R

Description

Function posterior_probs computes the posterior probabilities of hidden states of a (mixture) hidden Markov model.

Usage

1
posterior_probs(model, log_space = FALSE)

Arguments

model

A (mixture) hidden Markov model of class hmm or mhmm.

log_space

Compute posterior probabilities in logarithmic scale. The default is FALSE.

Value

Posterior probabilities. In case of multiple observations, these are computed independentlsy for each sequence.

Examples

1
2
3
4
5
6
7
8
# Load a pre-defined MHMM
data("mhmm_biofam")

# Compute posterior probabilities
pb <- posterior_probs(mhmm_biofam)

# Locally most probable states for the first subject:
pb[, , 1]

Example output

                   time
state                       a15         a16         a17         a18         a19
  Cluster 1:State 1 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000
  Cluster 1:State 2 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000
  Cluster 1:State 3 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000
  Cluster 1:State 4 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000
  Cluster 2:State 1 1.009409371 1.125629027 1.125484763 1.125337563 1.125187406
  Cluster 2:State 2 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000
  Cluster 2:State 3 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000
  Cluster 2:State 4 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000
  Cluster 3:State 1 0.004288691 0.004782475 0.004781862 0.004781237 0.004780599
  Cluster 3:State 2 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000
  Cluster 3:State 3 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000
  Cluster 3:State 4 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000
  Cluster 3:State 5 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000
  Cluster 3:State 6 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000
                   time
state                       a20         a21         a22        a23       a24
  Cluster 1:State 1 0.000000000 0.000000000 0.000000000 0.00000000  0.000000
  Cluster 1:State 2 0.000000000 0.000000000 0.000000000 0.00000000  0.000000
  Cluster 1:State 3 0.000000000 0.000000000 0.000000000 0.00000000  0.000000
  Cluster 1:State 4 0.000000000 0.000000000 0.000000000 0.00000000  0.000000
  Cluster 2:State 1 1.125034273 1.124878148 1.124719015 1.12455686  0.000000
  Cluster 2:State 2 0.000000000 0.000000000 0.000000000 0.00000000  0.000000
  Cluster 2:State 3 0.000000000 0.000000000 0.000000000 0.00000000 30.159486
  Cluster 2:State 4 0.000000000 0.000000000 0.000000000 0.00000000  0.000000
  Cluster 3:State 1 0.004779948 0.004779285 0.004778609 0.00477792  0.000000
  Cluster 3:State 2 0.000000000 0.000000000 0.000000000 0.00000000  0.000000
  Cluster 3:State 3 0.000000000 0.000000000 0.000000000 0.00000000  0.000000
  Cluster 3:State 4 0.000000000 0.000000000 0.000000000 0.00000000  0.000000
  Cluster 3:State 5 0.000000000 0.000000000 0.000000000 0.00000000  0.128139
  Cluster 3:State 6 0.000000000 0.000000000 0.000000000 0.00000000  0.000000
                   time
state                      a25         a26         a27         a28         a29
  Cluster 1:State 1 0.00000000 0.000000000 0.000000000 0.000000000 0.000000000
  Cluster 1:State 2 0.00000000 0.000000000 0.000000000 0.000000000 0.000000000
  Cluster 1:State 3 0.00000000 0.000000000 0.000000000 0.000000000 0.000000000
  Cluster 1:State 4 0.00000000 0.000000000 0.000000000 0.000000000 0.000000000
  Cluster 2:State 1 0.00000000 0.000000000 0.000000000 0.000000000 0.000000000
  Cluster 2:State 2 0.00000000 0.000000000 0.000000000 0.000000000 0.000000000
  Cluster 2:State 3 0.00000000 0.000000000 0.000000000 0.000000000 0.000000000
  Cluster 2:State 4 3.45937019 0.995966298 0.995909822 0.995858456 0.995811741
  Cluster 3:State 1 0.00000000 0.000000000 0.000000000 0.000000000 0.000000000
  Cluster 3:State 2 0.00000000 0.000000000 0.000000000 0.000000000 0.000000000
  Cluster 3:State 3 0.00000000 0.000000000 0.000000000 0.000000000 0.000000000
  Cluster 3:State 4 0.00000000 0.000000000 0.000000000 0.000000000 0.000000000
  Cluster 3:State 5 0.01469787 0.004231575 0.004231335 0.004231117 0.004230919
  Cluster 3:State 6 0.00000000 0.000000000 0.000000000 0.000000000 0.000000000
                   time
state                       a30
  Cluster 1:State 1 0.000000000
  Cluster 1:State 2 0.000000000
  Cluster 1:State 3 0.000000000
  Cluster 1:State 4 0.000000000
  Cluster 2:State 1 0.000000000
  Cluster 2:State 2 0.000000000
  Cluster 2:State 3 0.000000000
  Cluster 2:State 4 0.995769262
  Cluster 3:State 1 0.000000000
  Cluster 3:State 2 0.000000000
  Cluster 3:State 3 0.000000000
  Cluster 3:State 4 0.000000000
  Cluster 3:State 5 0.004230738
  Cluster 3:State 6 0.000000000

seqHMM documentation built on Nov. 6, 2018, 5:07 p.m.