| sim.lavaan | R Documentation |
This function simulates data from a lavaan model syntax with unstandardized
or standardized parameters. By default, the function simulates observed variables
based on the model specified in the argument model in a unstandardized
metric.
sim.lavaan(model, n = 500, std = FALSE, skew = NULL, kurt = NULL,
observed = TRUE, latent = FALSE, fscores = FALSE, composites = FALSE,
errors = FALSE, matrices = FALSE, method = c("eigen", "svd", "chol"),
seed = NULL, max.iter = 100, check = TRUE)
model |
a character string indicating the lavaan model syntax. |
n |
a numeric value indicating the number of observations. By default, 500 simulated cases are simulated. |
std |
logical: if |
skew |
a numeric vector indicating the skewness values for the
observed variables. Note that this argument is only used when
|
kurt |
a numeric vector indicating the kurtosis values for the
observed variables. Note that this argument is only used
when |
observed |
logical: if |
latent |
logical: if |
fscores |
logical: if |
composites |
logical: if |
errors |
logical: if |
matrices |
logical: if |
method |
a character string indicating the matrix decomposition used
to determine the matrix root of |
seed |
a numeric value specifying the seed of the pseudo-random numbers used when simulating multivariate normal data. |
max.iter |
a numeric value indicating the maximum number of iterations
when solving for error variances and correlation matrix.
Note that this argument is only used when |
check |
logical: if |
Returns a data frame.
This function uses the function simulateData from the R package
lavaan by Yves Rosseel (2012) when std = FALSE and is based on
modified copies of the function sim_standardized from the simstandard
package by W. Joel Schneider (2021) and the function rmvnorm from the
package mvtnorm by Alan Genz and Frank Bretz (2026) when std = TRUE.
Takuya Yanagida
Genz, A., & Bretz, F. (2026). mvtnorm: Multivariate Normal and t Distributions. R package version 1.3-6. https://doi.org/10.32614/CRAN.package.mvtnorm
Rosseel, Y. (2012). lavaan: An R Package for Structural Equation Modeling. Journal of Statistical Software, 48, 1-36. https://doi.org/10.18637/jss.v048.i02
Schneider, W. J. (2021). simstandard: Generate standardized data. R package version 0.6.3. https://doi.org/10.32614/CRAN.package.simstandard
## Not run:
# Model specification
model <- '# Measurement model
f1 =~ 0.8*x1 + 0.7*x2 + 0.5*x3
f2 =~ 0.7*x4 + 0.8*x5 + 0.6*x6
# Factor correlation
f1 ~~ 0.4*f2'
# Example 1: Unstandardized parameters, simulate 200 cases
simdat1 <- sim.lavaan(model, n = 200)
# Example 2: Standardized parameters, simulate 200 cases
simdat2 <- sim.lavaan(model, std = TRUE, n = 200)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.