View source: R/lav_simulate_old.R
simulateData | R Documentation |
Simulate data starting from a lavaan model syntax.
simulateData(model = NULL, model.type = "sem", meanstructure = FALSE,
int.ov.free = TRUE, int.lv.free = FALSE,
marker.int.zero = FALSE, conditional.x = FALSE, 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 = paste("G", 1:ngroups, sep = ""), skewness = NULL,
kurtosis = NULL, seed = NULL, empirical = FALSE,
return.type = "data.frame", return.fit = FALSE,
debug = FALSE, standardized = 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 |
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. Defaults to zero. |
kurtosis |
Numeric vector. The kurtosis values for the observed variables. Defaults to zero. |
seed |
Set random seed. |
empirical |
Logical. 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 unity by default. 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.
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 <- simulateData(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.