| simulate_lca | R Documentation |
Draws a latent class for each observation from proportions, then draws
every indicator independently from that class's category probabilities
(the usual local-independence assumption of latent class analysis).
simulate_lca(
n,
probabilities,
proportions = NULL,
class_labels = NULL,
category_labels = NULL,
seed = NULL,
batch = NULL
)
n |
Number of observations. A single whole number of at least 2. |
probabilities |
Item probabilities as an array with dimensions class,
indicator and category, or as a tidy data frame with columns |
proportions |
Latent-class proportions, one positive value per class;
they are rescaled to sum to one. |
class_labels, category_labels |
Optional labels, one unique value per
class and per category, overriding the names given in |
seed |
Optional random seed. |
batch |
Optional single positive whole number. When given, the
simulator runs |
A simulab_sim base data.frame with one row per observation and
columns id, latent_class (the true class label) and one column per
indicator holding the sampled value of category_labels. A parameters
component holds one row per class-by-indicator-by-category combination
with columns latent_class, indicator, category, probability and
proportion.
# `probabilities` is a class x indicator x category array. Values fill the
# class dimension fastest, so each pair below is one category across the two
# classes: P(indicator = 1) then P(indicator = 2).
probabilities <- array(
c(0.8, 0.2, 0.7, 0.3, # category 1, for each class and indicator
0.2, 0.8, 0.3, 0.7), # category 2, for each class and indicator
dim = c(2, 2, 2),
dimnames = list(
class = c("Class 1", "Class 2"),
indicator = c("item_1", "item_2"),
category = c("no", "yes")
)
)
# Only the `indicator` dimnames name the output columns, so the class and
# category labels are passed explicitly.
result <- simulate_lca(
n = 200,
probabilities = probabilities,
proportions = c(0.6, 0.4),
category_labels = c("no", "yes"),
seed = 1
)
head(result)
as.data.frame(result, what = "parameters")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.