simulateData(model = NULL, model.type = "sem", meanstructure = FALSE,
int.ov.free = TRUE, int.lv.free = 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.syntax for more information. Alternatively, a
parameter table (eg. the "cfa", "sem" or "growth". This may affect
how starting values are computed, and may be used to alter the terminology
used in the summary output, or the layout of paTRUE, the means of the observed
variables enter the model. If "default", the value is set based
on the user-specified model, and/or the values of other arguments.FALSE, the intercepts of the observed variables
are fixed to zero.FALSE, the intercepts of the latent variables
are fixed to zero.TRUE, the exogenous `x' covariates are considered
fixed variables and the means, variances and covariances of these variables
are fixed to their sample values. If FALSE, they are considered
random, and the means, vTRUE, the exogenous latent variables
are assumed to be uncorrelated.TRUE, the metric of each latent variable is
determined by fixing their variances to 1.0. If FALSE, the metric
of each latent variable is determined by fixing the factor loading of the
first indicator to 1.0.TRUE, the factor loading of the first indicator
is set to 1.0 for every latent variable.TRUE, the residual variance (if included)
of an observed indicator is set to zero if it is the only indicator of a
latent variable.TRUE, the residual variances and the variances
of exogenous latent variables are included in the model and set free.TRUE, the covariances of exogenous latent
variables are included in the model and set free.TRUE, the covariances of dependent variables
(both observed and latent) are included in the model and set free.lavaan
function.return.type = "matrix" or
return.type = "cov", a list of length(sample.nobs)
is returned, with either the data or covariance matricTRUE, the implied moments (Mu and Sigma)
specify the empirical not population mean and covariance matrix."data.frame", a data.frame is returned. If
"matrix", a numeric matrix is returned (without any variable names).
If "cov", a covariance matrix is returned (without any variable
names).TRUE, return the fitted model that has been used
to generate the data as an attribute (called "fit"); this
may be useful for inspection.TRUE, debugging information is displayed.TRUE, the residual variances of the observed
variables are set in such a way such that the model implied variances
are unity. This allows regression coefficients and factor loadings
(involving observed variables) to be specifreturn.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
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)Run the code above in your browser using DataLab