Confirmatory Factor Analysis Workflow

Confirmatory Factor Analysis Workflow

This vignette outlines a small CFA workflow using the bundled continuous dataset.

library(PsychoMatic)
data(psychomatic_continuous)

Specify A Model

model <- "
factor1 =~ item1 + item2 + item3
factor2 =~ item4 + item5 + item6
"

Compare Candidate Models

compare_models_auto() uses lavaan directly and returns a compact table for alternative CFA specifications. ML-type estimators report information criteria when available, whereas WLSMV-style workflows compare models through scaled or robust fit indices when available. The code is not evaluated during vignette checks to keep package installation fast on constrained machines.

models <- list(
  one_factor = "general =~ item1 + item2 + item3 + item4 + item5 + item6",
  two_factor = model
)
comparison <- compare_models_auto(
  psychomatic_continuous,
  models = models,
  estimator = "ML",
  language = "eng"
)
comparison$fit

Full Automated CFA

The higher-level cfa_auto() function adds estimator selection, reliability, fit interpretation, warnings, and reporting tables. It is shown but not run by default in this vignette because it requires optional diagnostic packages.

cfa_result <- cfa_auto(
  psychomatic_continuous,
  model = model,
  estimator = "ML",
  language = "eng"
)
summary(cfa_result)