| specify_model | R Documentation |
Creates a model specification object that flows automatically through all subsequent steps – CFA, ESEM, B-ESEM, alignment check, Mplus syntax, and comparison tables. Define your factor structure once at the top; everything else is derived automatically.
specify_model(
...,
data,
label = "ESEM Model",
ordered = FALSE,
group = NULL,
estimator = NULL,
missing = NULL
)
... |
Named character vectors, one per factor. The name becomes the
factor name and the vector contains the indicator names.
Example: |
data |
A |
label |
Optional character string labelling the model (used in
output headers and Mplus titles). Default |
ordered |
Logical or character vector. If |
group |
Character. Name of a grouping variable in |
estimator |
Character. Override the auto-selected lavaan estimator.
If |
missing |
Character. Missing-data handling. If |
An object of class "esem_spec" containing:
factorsNamed list of factor -> indicator assignments.
factor_namesCharacter vector of factor names.
all_itemsCharacter vector of all indicators in order.
nfactorsNumber of specific factors.
dataThe supplied data frame.
labelModel label.
cfa_syntaxReady-to-use lavaan CFA model string.
targetTarget matrix for ESEM target rotation.
bifactor_targetTarget matrix for B-ESEM.
data("HolzingerSwineford1939", package = "lavaan")
# Continuous indicators (MLR estimator by default)
spec <- specify_model(
Visual = c("x1", "x2", "x3"),
Textual = c("x4", "x5", "x6"),
Speed = c("x7", "x8", "x9"),
data = HolzingerSwineford1939,
label = "Holzinger-Swineford 3-factor"
)
print(spec)
# Multi-group spec (for invariance testing)
spec_mg <- specify_model(
Visual = c("x1", "x2", "x3"),
Textual = c("x4", "x5", "x6"),
Speed = c("x7", "x8", "x9"),
data = HolzingerSwineford1939,
group = "sex",
label = "HS 3-factor (multi-group)"
)
# Run the CFA/ESEM/B-ESEM comparison from a spec
results <- run_comparison(spec)
print(results)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.