Skip to contents

Compares fit from one or several lavaan models. Also optionally includes references values. The reference fit values are based on Schreiber et al. (2006).

Usage

nice_fit(model, model.labels, nice_table = FALSE)

Arguments

model

lavaan model object(s) to extract fit indices from

model.labels

Model labels to use. If a named list is provided for model, default to the names of the list. Otherwise, if the list is unnamed, defaults to generic numbering.

nice_table

Logical, whether to print the table as a rempsyc::nice_table as well as print the reference values at the bottom of the table.

Value

A dataframe, representing select fit indices (chi2, df, chi2/df, p-value of the chi2 test, CFI, TLI, RMSEA, SRMR, AIC, and BIC).

References

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

Examples

(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 (measurement model)-----]
#> 
#> 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)
fit <- sem(HS.model, data = HolzingerSwineford1939)
nice_fit(fit)
#>     Model    chi2 df chi2.df p   CFI   TLI RMSEA SRMR      AIC      BIC
#> 1 Model 1 116.263 36    3.23 0 0.926 0.887 0.086 0.06 8638.134 8749.248