| simulate_hmm | R Documentation |
Draws an initial hidden state for each sequence from initial, evolves it
with transition for chain_length occasions, and emits one observed
category per occasion from emission.
simulate_hmm(
n,
transition,
chain_length,
emission,
initial = NULL,
state_labels = NULL,
observation_labels = NULL,
seed = NULL,
batch = NULL
)
n |
Number of sequences. A single positive whole number. |
transition |
Hidden-state transition matrix, or a tidy data frame with
columns |
chain_length |
Sequence length. A single positive whole number; every sequence has the same length. |
emission |
Hidden-state-by-observed-category probability matrix, or a
tidy data frame with columns |
initial |
Initial hidden-state probabilities, one per hidden state,
summing to one. |
state_labels, observation_labels |
Optional labels, one unique value
per hidden state and per observed category. They default to
|
seed |
Optional random seed. |
batch |
Optional single positive whole number. When given, the
simulator runs |
A long-form simulab_sim base data.frame with one row per
sequence-occasion (n * chain_length rows) and columns id, occasion,
state (the true hidden state label) and observation (the emitted
category label). Components transitions (columns from, to,
probability), emissions (columns state, observation,
probability) and initial_probabilities (columns state,
probability) hold the generating parameters in tidy form.
result <- simulate_hmm(
n = 50,
transition = matrix(c(0.7, 0.3, 0.4, 0.6), nrow = 2, byrow = TRUE),
chain_length = 20,
emission = matrix(c(0.9, 0.1, 0.2, 0.8), nrow = 2, byrow = TRUE),
seed = 1
)
head(result)
components(result)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.