This function returns a data.frame with a simulated state sequence and observations. The length of the simulated sequence can be specified either as a number of state transition (with argument n_state_transitions) or as a number of time-point (with argument n_timepoints) Each row of the returned data.frame is a time-point and the columns specify the sequence id, the time-point, the state and the values of the observation. Each variable has its own column.

simulate_hsmm(
  model,
  seq_id = NULL,
  n_state_transitions = NULL,
  n_timepoints = NULL,
  seed = NULL,
  all_states = FALSE,
  min_tp_per_state = NULL,
  mult_seq_allowed = TRUE
)

Arguments

model

a object of class or hsmm.

seq_id

(optional) a character specifying the name of the sequence to simulate.

n_state_transitions

(optional) an integer specifying the number of state transitions that should be simulated.

n_timepoints

(optional) an integer specifying the number of time-point to simulate. One can either specify n_state_transitions or n_timepoints. If both are specified, n_timepoints is ignored and a sequence with n_state_transitions is specified.

seed

(optional) the seed for the random generator. Allows to reproduce a simulated sequence.

all_states

(optional) a logical specifying if all states should be present in the simulated sequence. By default, this option is FALSE. When TRUE, the sequence may be longer than the specified length via n_state_transitions or n_timepoints

min_tp_per_state

(optional) if all_states == TRUE, this option can be used to specify the minimum number of time-point in each state.

mult_seq_allowed

(optional) if all_states == TRUE, this option can be used to specify if representation of all states in the simulated sequence can be achieved by simulated several sequences or by simulating a single sequence.

Value

A data.frame with the following columns: seq_id, the identifier of the sequence, t the time-stamp, state the hidden state and one additional column for each specified variable.

References

J. O’Connell, S. Hojsgaard, Hidden semi-Markov models for multiple observation sequences: The mhsmm package for R. Journal of Statistical Software. 39, 1–22 (2011) https://www.jstatsoft.org/article/view/v039i04

Examples

my_model = simple_model # simple_model is a model attached to the HiddenSemiMarkov package for demos Xsim = simulate_hsmm(model = my_model, n_state_transitions = 10) plot_hsmm_seq(model = my_model, X = Xsim)