posterior: Calculate Posterior Probability for States of HMM

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/utils.R

Description

For each state of an HMM the posterior probability that this state produced a given observation is calculated.

Usage

1

Arguments

data

Vector with observation sequence.

hmm

Object of class hmm.

log

Logical indicating whether the logarithm of the posterior probability should be returned.

Details

Regardless of the value of log the computation is carried out in log space. If log = FALSE the result is transformed back to linear space before it is returned.

Value

A matrix with as many rows as hmm has states and one column for each entry in data.

Author(s)

Peter Humburg

See Also

forward, backward

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
## create two state HMM with t distributions
state.names <- c("one","two")
transition <- c(0.1, 0.02)
location <- c(1, 2)
scale <- c(1, 1)
df <- c(4, 6)
model <- getHMM(list(a=transition, mu=location, sigma=scale, nu=df),
    state.names)

## obtain observation sequence from model
obs <- sampleSeq(model, 100)

## calculate posterior probability for state "one"
post <- posterior(obs, model, log=FALSE)

## get sequence of individually most likely states
state.seq <- apply(post,2,max)
state.seq <- states(model)[state.seq]

humburg/tileHMM documentation built on May 17, 2019, 9:13 p.m.