Lavaan (CFA, SEM): Are Your Models Nested?
by Arndt Regorz, MSc.
September 15, 2024
If you want to compare different models (SEM, CFA, path analysis), then one important distinction is between models that are nested and models that are not nested. Because you can only use the likelihood ratio test (LR test, chi square difference test) for nested models. For comparing models that are not nested, you need information criteria like AIC or BIC instead.
But not all cases of nested models are immediately obvious. To help you decide whether two or more models are nested within each other there is a function in the semTools package, net(), that can help you with this decision.
1. When Are Models Nested?
Model A is nested within model B if by fixing one or more free parameters in model B you can get to model A.
Let's look at the following three CFA-Models:
Figure 1
CFA Examples
CFA 1 is nested within CFA 2, because by fixing the cross loading in CFA 2 from the indicator x9 on the factor visual to zero, you get CFA 1.
CFA 1 is nested within CFA 3, because by fixing the error correlation in CFA 2 between indicators x7 and x8 to zero, you get CFA 1.
CFA 2 is not nested within CFA 3, and CFA 3 is not nested within CFA 2, because there is no parameter (or set of parameters) that can be fixed to zero to get from one model to the other.
2. Checking Lavaan Models for Nesting
In order to check whether the three models introduced above are nested, first we specify and estimate these models.
library(lavaan)
library(semTools)
# CFA 1
model_1 <- ' visual =~ x1 + x2 + x3
textual =~ x4 + x5 + x6
speed =~ x7 + x8 + x9 '
cfa_fit_1 <- cfa(model_1, data = HolzingerSwineford1939)
# CFA 2
model_2 <- ' visual =~ x1 + x2 + x3 + x9
textual =~ x4 + x5 + x6
speed =~ x7 + x8 + x9 '
cfa_fit_2 <- cfa(model_2, data = HolzingerSwineford1939)
# CFA 3
model_3 <- ' visual =~ x1 + x2 + x3
textual =~ x4 + x5 + x6
speed =~ x7 + x8 + x9
x7 ~~ x8'
cfa_fit_3 <- cfa(model_3, data = HolzingerSwineford1939)
Then, we use the net() function from the semTools library to check whether there is nesting.
net(cfa_fit_1, cfa_fit_2, cfa_fit_3)
As an output we get (after some explanatory text):
Figure 2
Output from the net() function
The output can be interpreted row by row:
CFA 3 is not nested in CFA 2 (second row) and vice versa (since they have the same degrees of freedom the results works the other way around, too).
CFA 1 is nested in CFA 2 and in CFA 3 (third row).
Citation
Regorz, A. (2024, September 15). Lavaan (CFA, SEM): Are Your Models Nested?. Regorz Statistik. https://www.regorz-statistik.de/blog/lavaan_nested_models.html