simulate.hmm: Simulating Hidden Markov objects

Description Usage Arguments Value Examples

View source: R/simulate.R

Description

Simulating Hidden Markov objects

Usage

1
2
## S3 method for class 'hmm'
simulate(object, nsim = 1, seed = NULL, include_state = FALSE, ...)

Arguments

object

Object of class 'hmm'.

nsim

Number of simulations.

seed

Seed to be used for random generation.

include_state

Logical, whether or not the hidden state should also be returned.

...

Additional arguments.

Value

If observations are available in the 'hmm' object, will return a matrix with 'nsim' rows, each of which being a simulation of equal length as the observed data. Otherwise, will return a vector of length 'nsim' of simulations from the model. In either case, if 'include_state' is 'TRUE', each simulation will be appended with a vector of equal length indicating the hidden state.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
# Continuing examples from hmm page

# Normal distributions
X.normal <- simulate(hmm.normal, nsim=100)
summary(X.normal)
plot(X.normal)
hist(X.normal)

# Custom (uniform) distributions
Z.unif <- simulate(hmm.unif, nsim=200, include_state=TRUE)
X.unif <- Z.unif[1:100]
G.unif <- Z.unif[101:200]
plot(X.unif, type='h', col=G.unif, lwd=2)

# Custom (mixed) distributions
Z.mixture <- simulate(hmm.mixture, nsim=200, include_state=TRUE)
X.mixture <- Z.mixture[1:200]
G.mixture <- Z.mixture[201:400]
plot(X.mixture, type='h', col=G.mixture, lwd=2)

asbjornholk/HiddenStateModels documentation built on Jan. 9, 2022, 12:02 a.m.