ESEM-within-CFA syntax composer for lavaan
syntax_composer.Rd
ESEM-within-CFA syntax composer for lavaan
Arguments
- efa_object
A psych::fa() object with the results of a exploratory factor analysis. The factor loadings from this analysis will be set as starting values or fixed values in the lavaan syntax created.
- referents
A named list in the form
list(factor1 = "referent1", etc)
. Each entry identifies the referent for one of the factors. The order of this vector must be the same order the factors are ordered in theefa_object
.
Details
ESEM-within-CFA models have latent variables estimations with all cross-loadings. To improve fit, starting values from a previous exploratory analysis are used. To ensure model identification, a referent is chosen for each latent variable and all their cross-loadings are set as fixed values. This function "composes" such a lavaan model syntax from an EFA object. This model can subsequently be used in lavaan with lavaan::cfa() or lavaan::sem(). The best way to check the output is with writeLines().
It is very important to make sure the order of the referents
vector is the same as the
factor order in the factor loadings matrix in efa_object
. Otherwise, the names of the
latent variables may be wrong in the syntax. See also the vignette esem-within-cfa.
Examples
# use Holzinger and Swineford (1939) dataset in lavaan package
hw_data <- lavaan::HolzingerSwineford1939
hw_data <- hw_data[,c(7:15)]
#make exploratory analysis with geomin rotation
geomin_efa <- esem_efa(hw_data,3)
referents_list <- list(textual = "x5", visual = "x3", speed = "x7")
model_syntax <- syntax_composer(geomin_efa, referents_list)
writeLines(model_syntax)
#> textual =~ start(0.193)*x1+
#> start(0.042)*x2+
#> -0.066*x3+
#> start(0.845)*x4+
#> start(0.884)*x5+
#> start(0.804)*x6+
#> 0.035*x7+
#> start(-0.044)*x8+
#> start(0.024)*x9
#>
#> visual =~ start(0.595)*x1+
#> start(0.509)*x2+
#> start(0.688)*x3+
#> start(0.02)*x4+
#> -0.061*x5+
#> start(0.083)*x6+
#> -0.137*x7+
#> start(0.137)*x8+
#> start(0.391)*x9
#>
#> speed =~ start(0.029)*x1+
#> start(-0.124)*x2+
#> 0.016*x3+
#> start(0.009)*x4+
#> 0.009*x5+
#> start(-0.011)*x6+
#> start(0.731)*x7+
#> start(0.688)*x8+
#> start(0.455)*x9
#>
# esem-within-cfa
esem_w_cfa <- lavaan::cfa(model_syntax, data = hw_data, std.lv = TRUE)
summary(esem_w_cfa)
#> Length Class Mode
#> 1 lavaan S4