| simulate_ordinal | R Documentation |
Simulate correlated ordinal variables
simulate_ordinal(
n,
probabilities,
n_variables = 1L,
rho = 0,
structure = c("independent", "exchangeable", "ar1", "custom"),
correlation = NULL,
labels = NULL,
variable_names = NULL,
seed = NULL,
batch = NULL
)
n |
Number of observations. |
probabilities |
A numeric vector used for every variable or a matrix with one row per variable and one column per category. |
n_variables |
Number of variables when |
rho, structure, correlation |
Correlation arguments for the latent
normal variables. |
labels |
Optional category labels. |
variable_names |
Optional variable names. |
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 and one column per variable, each holding a category label.
Two tidy tables come from as.data.frame(): what = "probabilities" has
one row per variable and category with columns variable, category and
probability; what = "correlation" has one row per latent
correlation-matrix cell with columns row, column and correlation.
That correlation is the latent Gaussian one, not the correlation of the
realized categories, which is attenuated by the thresholding.
result <- simulate_ordinal(
n = 200, probabilities = c(0.2, 0.5, 0.3), n_variables = 2, rho = 0.4, seed = 1
)
head(result)
as.data.frame(result, what = "probabilities")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.