simulate_nhmm: Simulate Non-homogeneous Hidden Markov Models

View source: R/simulate_nhmm.R

simulate_nhmmR Documentation

Simulate Non-homogeneous Hidden Markov Models

Description

Simulate sequences of observed and hidden states given the parameters of a non-homogeneous hidden Markov model.

Usage

simulate_nhmm(
  n_states,
  emission_formula,
  initial_formula = ~1,
  transition_formula = ~1,
  data,
  id,
  time,
  coefs = NULL,
  init_sd = 2 * is.null(coefs)
)

Arguments

n_states

An integer > 1 defining the number of hidden states.

emission_formula

of class formula() for the state emission probabilities, or a list of such formulas in case of multiple response variables. The left-hand side of formulas define the responses. For multiple responses having same formula, you can use a form c(y1, y2) ~ x, where y1 and y2 are the response variables.

initial_formula

of class formula() for the initial state probabilities. Left-hand side of the formula should be empty.

transition_formula

of class formula() for the state transition probabilities. Left-hand side of the formula should be empty.

data

A data frame containing the variables used in the model formulas. Note that this should also include also the response variable(s), which are used to define the number of observed symbols (using levels()) and the length of sequences. The actual values of the response variables does not matter though, as they are replaced by the simulated values. The exception is the first time point in FAN-HMM case: If the emission_formula contains lagged responses, the response variable values at the first time point are used to define the emissions at the second time point, and the simulations are done from the second time point onwards. This matches the case prior_obs = "fixed" in estimate_nhmm().

id

Name of the id variable in data identifying different sequences.

time

Name of the time index variable in data.

coefs

Same as argument inits in estimate_nhmm(). If NULL, (default), the model parameters are generated randomly. If you want to simulate new sequences based on an estimated model fit, you can use coefs = fit$etas and init_sd = 0.

init_sd

Standard deviation of the normal distribution used to generate random coefficients. Default is 2 when coefs is NULL and 0 otherwise.

Value

A list with the model used in simulation as well as the simulated hidden state sequences.


seqHMM documentation built on June 8, 2025, 10:16 a.m.