Compares fit from several lavaan models. Also optionally includes references values. The reference fit values are based on Schreiber et al. (2006).
Schreiber, J. B., Nora, A., Stage, F. K., Barlow, E. A., & King, J. (2006). Reporting structural equation modeling and confirmatory factor analysis results: A review. The Journal of educational research, 99(6), 323-338. https://doi.org/10.3200/JOER.99.6.323-338
compare_fit(..., nice_table = FALSE)
lavaan model objects to extract fit indices from
Logical, whether to print the table as a rempsyc::nice_table
as well as print the reference values at the bottom of the table.
(latent <- list(visual = paste0("x", 1:3),
textual = paste0("x", 4:6),
speed = paste0("x", 7:9)))
#> $visual
#> [1] "x1" "x2" "x3"
#>
#> $textual
#> [1] "x4" "x5" "x6"
#>
#> $speed
#> [1] "x7" "x8" "x9"
#>
(regression <- list(ageyr = c("visual", "textual", "speed"),
grade = c("visual", "textual", "speed")))
#> $ageyr
#> [1] "visual" "textual" "speed"
#>
#> $grade
#> [1] "visual" "textual" "speed"
#>
HS.model <- write_lavaan(latent = latent, regression = regression)
cat(HS.model)
#> ##################################################
#> # [---------------Latent variables---------------]
#>
#> visual =~ x1 + x2 + x3
#> textual =~ x4 + x5 + x6
#> speed =~ x7 + x8 + x9
#>
#> ##################################################
#> # [---------Regressions (Direct effects)---------]
#>
#> ageyr ~ visual + textual + speed
#> grade ~ visual + textual + speed
#>
library(lavaan)
#> This is lavaan 0.6-12
#> lavaan is FREE software! Please report any bugs.
fit <- lavaan(HS.model, data=HolzingerSwineford1939,
auto.var=TRUE, auto.fix.first=TRUE,
auto.cov.lv.x=TRUE)
compare_fit(fit)
#> Model chi2 df p CFI TLI RMSEA SRMR AIC BIC
#> 1 fit 173.661 37 0 0.874 0.813 0.111 0.072 8693.533 8800.942