Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

simulate_hmm

Simulate hidden Markov models


Description

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

Usage

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

# 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")

seqHMM

Mixture Hidden Markov Models for Social Sequence Data and Other Multivariate, Multichannel Categorical Time Series

v1.0.14
GPL (>= 2)
Authors
Jouni Helske [aut, cre] (<https://orcid.org/0000-0001-7130-793X>), Satu Helske [aut] (<https://orcid.org/0000-0003-0532-0153>)
Initial release
2019-10-21

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.