| simulate_tna | R Documentation |
Takes or draws a transition matrix, generates sequences from it with
simulate_sequences(), and fits one transition network to the sequences
with the tna package, all in one call.
simulate_tna(
n = 100L,
transition = NULL,
chain_length = 20L,
initial = NULL,
states = NULL,
n_states = 5L,
state_categories = c("metacognitive", "cognitive"),
model = c("tna", "ftna", "ctna", "atna"),
seed = NULL,
...,
batch = NULL
)
n |
Number of sequences, defaulting to |
transition |
Generating transition matrix, or a tidy data frame with
columns |
chain_length |
Sequence length, defaulting to |
initial |
Initial probabilities or a fixed starting state. When |
states |
State labels. |
n_states |
Number of automatically generated states. |
state_categories |
Learning-state categories the labels of a drawn
matrix come from, defaulting to |
model |
TNA estimator, one of |
seed |
Optional random seed. |
... |
Further arguments passed to |
batch |
Optional single positive whole number. When given, the
simulator runs |
The fitted network as a native tna model, of class
c("simulab_tna", "tna"), so every tna function (plot(),
centralities(), summary() and the rest) applies to it. Printing it
shows the native tna print, then the generating transition matrix and
initial probabilities. Tidy tables come from as.data.frame():
the fitted edges (the default; columns from, to and weight), the
generating transitions (columns from, to and probability),
initial_probabilities, the generated sequences in long form, wide
and model_info. Requires the suggested tna package, and raises
simulab_missing_tna without it.
if (requireNamespace("tna", quietly = TRUE)) {
# With no arguments: a drawn 5-state system, 100 sequences, one network.
network <- simulate_tna(seed = 1)
network
validate_recovery(network, network, term = "to", estimate = "weight")
# From a given transition matrix.
transition <- data.frame(
from = rep(c("plan", "act"), each = 2),
to = rep(c("plan", "act"), times = 2),
probability = c(0.3, 0.7, 0.6, 0.4)
)
simulate_tna(n = 200, transition = transition, seed = 1)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.