I am estimating some Confirmatory Factor Analysis (CFA) models using the Lavaan package and I hoping to extract the fitMeasures to export out of the model to a spreadsheet. This is easily done using the fitMeasures
command, but it automatically defaults to exporting the "ML" fit measures, even if the model was run using "MLR". Is there a way to extract these fitMeasures
from the robust model?
Here is my example script:
## The famous Holzinger and Swineford (1939) example
HS.model <- 'visual =~ x1 + x2 + x3
textual =~ x4 + x5 + x6
speed =~ x7 + x8 + x9'
fit <- cfa(HS.model, data=HolzingerSwineford1939, estimator="MLR", std.lv=TRUE)
fitMeasures(fit, fit.measures = c("chisq", "cfi", "rmsea", "aic"))
Running the summary reveals that fitMeasures
produces "ML" fit measures, not Robust fit measures:
summary(fit, standardized=TRUE, fit.measures=TRUE, rsquare=TRUE)
Is there a way I can obtain the Robust fit measures? Thanks in-advance for your help!
I think I found the solution to this (below):
I used the following in my example above to extract the robust (scaled) fit measures:
fits<-inspect(fit, "fitMeasures")
fits[c(5:7,24,44,34)]
I hope it helps someone out there and please let me know if there is a better way to accomplish this!
Best Answer
Here is another option that is line with your approach to getting standard fit indices:
That should give you the specific scales you want. You can include as many indices as you want to the fit.scaled object. You can use fitMeasures(fit) to get a display of all possible fit indices you can request of the model.