| augment_markov | R Documentation |
Add a Markov chain to each input row
augment_markov(
data,
transition,
chain_length,
initial = NULL,
states = NULL,
trim_state = NULL,
id = "id",
period = "period",
state = "state",
seed = NULL
)
data |
Base |
transition, chain_length, states, trim_state |
Markov-chain arguments. |
initial |
Starting-state probabilities or the name of an input variable
containing each row's starting state. When |
id, period, state |
Output variable names. |
seed |
Optional random seed. |
A long-form simulab_sim base data.frame combining the input
variables with one row per chain position: id, period, state,
followed by the other input columns. A transitions table
(from, to, probability) is available through as.data.frame().
data <- data.frame(id = 1:20, group = rep(c("a", "b"), each = 10))
result <- augment_markov(
data,
transition = matrix(c(0.7, 0.3, 0.4, 0.6), nrow = 2, byrow = TRUE),
chain_length = 10,
states = c("A", "B"),
seed = 1
)
head(result)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.