library(lavaan)
myData <- read.csv("/path/to/mydata/myData.csv")
myModel <- '
f1 =~ item1 + item2 + item3
f2 =~ item4 + item5 + item6
f3 =~ item7 + item8 + item9
'
fit <- cfa(model = myModel, data = myData)
summary(fit, fit_measures = TRUE)Features
lavaan is reliable, open and extensible
by default, lavaan implements the textbook/paper formulas, so there are no surprises
lavaan can partially mimic results of the commercial package Mplus via the
mimic = "Mplus"argumentlavaan is not a black box: you can browse the source code on GitHub
lavaan can be extended: see the Related Projects page for extensions and add-ons.
lavaan is easy and intuitive to use
- the ‘lavaan model syntax’ allows users to express their models in a compact, elegant and useR-friendly way; for example, a typical CFA analysis looks as follows:
you can choose between a user-friendly interface in combination with the fitting functions
cfa()andsem()or a low-level interface using the fitting functionlavaan()where ‘defaults’ do not get in the wayconvenient arguments (eg.
group_equal="loadings") simplify many common tasks (eg. measurement invariance testing)lavaan outputs all the information you need: a large number of fit measures, modification indices, standardized solutions, and technical information that is stored in a fitted lavaan object
lavaan provides many advanced options
full support for meanstructures and multiple groups
several estimators are available: ML (and robust variants MLM, MLMV, MLR), GLS, WLS (and robust variants DWLS, WLSM, WLSMV), ULS (ULSM, ULSMV), DLS, (MI)IV, and pairwise ML (PML)
standard errors: standard, robust/huber-white/sandwich, bootstrap
test statistics: standard, Satorra-Bentler, Yuan-Bentler, Satterthwaite, scaled-shifted, Bollen-Stine bootstrap, the FMG family, Hayakawa
missing data: FIML estimation or two.stage (for multiple imputation, see the lavaan.mi package)
linear and nonlinear equality and inequality constraints
full support for analyzing categorical data: lavaan (from version 0.5 onwards) can handle any mixture of binary, ordinal and continuous observed variables (using ULS(MV), (D)WLS(MV) or PML estimators; but not ML)
(from version 0.6 onwards): support for multilevel SEM (two levels only); (from version 0.7 onwards): support for random slopes
apart from the start ‘nlminb()’ optimizer, lavaan also offers the EM algorithm for multilevel models, and Gauss-Newton (optim_method = “gn”) alternatives
the sam() function provides convenient access to several “structural-after-measurement” (SAM) approaches, including local SAM (LSAM)