% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/sim.lavaan.R
\name{sim.lavaan}
\alias{sim.lavaan}
\title{Generates Simulated Data from a lavaan Model Syntax}
\usage{
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)
}
\arguments{
\item{model}{a character string indicating the lavaan model syntax.}

\item{n}{a numeric value indicating the number of observations. By
default, 500 simulated cases are simulated.}

\item{std}{logical: if \code{TRUE}, lavaan model syntax specified in
the argument \code{model} is based on standardized parameters.}

\item{skew}{a numeric vector indicating the skewness values for the
observed variables. Note that this argument is only used when
\code{std = FALSE}.}

\item{kurt}{a numeric vector indicating the kurtosis values for the
observed variables. Note that this argument is only used
when \code{std = FALSE}.
Note that this argument is only used when \code{std = FALSE}.}

\item{observed}{logical: if \code{TRUE} (default), observed variables are
included. Note that this argument is only used when
\code{std = TRUE}.}

\item{latent}{logical: if \code{TRUE}, latent variables are included.
Note that this argument is only used when \code{std = TRUE}.}

\item{fscores}{logical: if \code{TRUE}, factor score are included.
Note that this argument is only used when \code{std = TRUE}.}

\item{composites}{logical: if \code{TRUE}, composite  variables are included.
Note that this argument is only used when \code{std = TRUE}.}

\item{errors}{logical: if \code{TRUE}, observed error and latent disturbance
variables are included. Note that this argument is only used
when \code{std = TRUE}.}

\item{matrices}{logical: if \code{TRUE}, matrices are included as attributes.
Note that this argument is only used when \code{std = TRUE}.}

\item{method}{a character string indicating the matrix decomposition used
to determine the matrix root of \code{sigma} in the random
number generator for the multivariate normal distribution,
i.e., \code{"eigen"} (default) for eigenvalue decomposition,
\code{"svd"} for singular value decomposition, and \code{"chol"}
for Cholesky decomposition. Note that this argument is only
used when \code{std = TRUE}.}

\item{seed}{a numeric value specifying the seed of the pseudo-random
numbers used when simulating multivariate normal data.}

\item{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 \code{std = TRUE}.}

\item{check}{logical: if \code{TRUE} (default), argument specification
is checked.}
}
\value{
Returns a data frame.
}
\description{
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 \code{model} in a unstandardized
metric.
}
\note{
This function uses the function \code{simulateData} from the R package
\pkg{lavaan} by Yves Rosseel (2012) when \code{std = FALSE} and is based on
modified copies of the function \code{sim_standardized} from the \pkg{simstandard}
package by W. Joel Schneider (2021) and the function \code{rmvnorm} from the
package \pkg{mvtnorm} by Alan Genz and Frank Bretz (2026) when \code{std = TRUE}.
}
\examples{
\dontrun{

# 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)
}
}
\references{
Genz, A., & Bretz, F. (2026). \emph{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.
\emph{Journal of Statistical Software, 48}, 1-36. https://doi.org/10.18637/jss.v048.i02

Schneider, W. J. (2021). \emph{simstandard: Generate standardized data}. R package
version 0.6.3. https://doi.org/10.32614/CRAN.package.simstandard
}
\author{
Takuya Yanagida
}
