| lavSimulateData | R Documentation |
Simulate data starting from a lavaan model syntax.
lavSimulateData(model = NULL, model_type = "sem", meanstructure = FALSE,
int_ov_free = TRUE, int_lv_free = FALSE,
marker_int_zero = FALSE, conditional_x = FALSE,
composites = TRUE, fixed_x = FALSE,
orthogonal = FALSE, std_lv = TRUE, auto_fix_first = FALSE,
auto_fix_single = FALSE, auto_var = TRUE, auto_cov_lv_x = TRUE,
auto_cov_y = TRUE, ..., sample_nobs = 500L, ov_var = NULL,
group_label = NULL, skewness = NULL,
kurtosis = NULL, cluster_idx = NULL, seed = NULL, empirical = FALSE,
mass = FALSE, ordered_center = TRUE, return_type = "data.frame",
return_fit = FALSE, debug = FALSE, standardized = FALSE)
simulateData(model = NULL, model_type = "sem", meanstructure = FALSE,
int_ov_free = TRUE, int_lv_free = FALSE,
marker_int_zero = FALSE, conditional_x = FALSE,
composites = TRUE, fixed_x = FALSE,
orthogonal = FALSE, std_lv = TRUE, auto_fix_first = FALSE,
auto_fix_single = FALSE, auto_var = TRUE, auto_cov_lv_x = TRUE,
auto_cov_y = TRUE, ..., sample_nobs = 500L, ov_var = NULL,
group_label = NULL, skewness = NULL,
kurtosis = NULL, cluster_idx = NULL, seed = NULL, empirical = FALSE,
mass = FALSE, ordered_center = TRUE, return_type = "data.frame",
return_fit = FALSE, debug = FALSE, standardized = FALSE)
lav_data_simulate_old(..., ordered_center = FALSE)
model |
A description of the user-specified model. Typically, the model
is described using the lavaan model syntax. See
|
model_type |
Set the model type: possible values
are |
meanstructure |
If |
int_ov_free |
If |
int_lv_free |
If |
marker_int_zero |
Logical. Only relevant if the metric of each latent
variable is set by fixing the first factor loading to unity.
If |
conditional_x |
If |
composites |
If |
fixed_x |
If |
orthogonal |
If |
std_lv |
If |
auto_fix_first |
If |
auto_fix_single |
If |
auto_var |
If |
auto_cov_lv_x |
If |
auto_cov_y |
If |
... |
additional arguments passed to the |
sample_nobs |
Number of observations. If a vector, multiple datasets
are created. If |
ov_var |
The user-specified variances of the observed variables. |
group_label |
The group labels that should be used if multiple groups are created. |
skewness |
Numeric vector. The skewness values for the observed
variables. The default ( |
kurtosis |
Numeric vector. The (excess) kurtosis values for the observed
variables. The default ( |
cluster_idx |
Optional. Only used (and only available via
|
seed |
Set random seed. |
empirical |
Logical. If |
mass |
Logical. If |
ordered_center |
Logical. Only relevant for categorical data, which is
generated by the (new) multilevel-aware engine. If |
return_type |
If |
return_fit |
If |
debug |
If |
standardized |
If |
Model parameters can be specified by fixed values in the lavaan model
syntax. If no fixed values are specified, the value zero will be assumed,
except for factor loadings and variances, which are set to 0.7 and 1.0
respectively. By default, multivariate normal data are generated. However, by
providing skewness and/or kurtosis values, nonnormal multivariate data can be
generated, using the Vale & Maurelli (1983) method. Skewness and kurtosis
values that are all zero are treated as if they were NULL: the data are
then generated by the (multivariate) normal route, which also supports
empirical = TRUE. Because the Vale-Maurelli method reproduces the
requested moments only approximately, combining empirical = TRUE with
nonzero skewness or kurtosis values results in an error.
There is a single data-simulation engine. Multilevel data (model syntax
containing level: blocks, or when the cluster_idx argument is
provided) are generated by an internal multilevel worker; all single-level data
(continuous and categorical, including the ov_var, skewness,
kurtosis, standardized and mass options) are generated by
the historical single-level worker, so that the continuous, single-level output
remains byte-identical to previous versions. For multilevel data, the
ov_var, skewness, kurtosis, standardized and
mass arguments are not (yet) supported and are ignored (with a warning).
lav_data_simulate_old() is a deprecated wrapper kept for backward
compatibility; it forwards to the unified engine (with ordered_center =
FALSE by default, reproducing the historical threshold cut).
The generated data. Either as a data.frame
(if return_type="data.frame"),
a numeric matrix (if return_type="matrix"),
or a covariance matrix (if return_type="cov").
# specify population model
population.model <- ' f1 =~ x1 + 0.8*x2 + 1.2*x3
f2 =~ x4 + 0.5*x5 + 1.5*x6
f3 =~ x7 + 0.1*x8 + 0.9*x9
f3 ~ 0.5*f1 + 0.6*f2
'
# generate data
set.seed(1234)
myData <- lavSimulateData(population.model, sample_nobs = 100L)
# population moments
fitted(sem(population.model))
# sample moments
round(cov(myData), 3)
round(colMeans(myData), 3)
# fit model
myModel <- ' f1 =~ x1 + x2 + x3
f2 =~ x4 + x5 + x6
f3 =~ x7 + x8 + x9
f3 ~ f1 + f2 '
fit <- sem(myModel, data=myData)
summary(fit)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.