simulate_hmm: Simulate hidden Markov models

Description Usage Arguments Value See Also Examples

View source: R/simulate_hmm.R

Description

Simulate sequences of observed and hidden states given parameters of a hidden Markov model.

Usage

1
2
simulate_hmm(n_sequences, initial_probs, transition_probs, emission_probs,
  sequence_length)

Arguments

n_sequences

Number of simulations.

initial_probs

A vector of initial state probabilities.

transition_probs

A matrix of transition probabilities.

emission_probs

A matrix of emission probabilities or a list of such objects (one for each channel).

sequence_length

Length for simulated sequences.

Value

A list of state sequence objects of class stslist.

See Also

build_hmm and fit_model for building and fitting hidden Markov models; ssplot for plotting multiple sequence data sets; seqdef for more information on state sequence objects; and simulate_mhmm for simulating mixture hidden Markov models.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
# Parameters for the HMM
emission_probs <- matrix(c(0.5, 0.2, 0.5, 0.8), 2, 2)
transition_probs <- matrix(c(5/6, 1/6, 1/6, 5/6), 2, 2)
initial_probs <- c(1, 0)

# Setting the seed for simulation
set.seed(1)

# Simulating sequences
sim <- simulate_hmm(
  n_sequences = 10, initial_probs = initial_probs, 
  transition_probs = transition_probs, 
  emission_probs = emission_probs, 
  sequence_length = 20)
  
ssplot(sim, sortv = "mds.obs", type = "I")

Example output

 [!] In ssplot() : withlegend is deprecated, use with.legend instead.
 [!] In ssplot() : cex.plot is deprecated, use cex.axis instead.
 [!] In ssplot() : withlegend is deprecated, use with.legend instead.
 [!] In ssplot() : fontsize is deprecated, use cex instead.
 [!] In ssplot() : fontsize is deprecated, use cex instead.

seqHMM documentation built on May 10, 2018, 5:04 p.m.