## Comparing Paths in a Path Model With R/Lavaan

by Arndt Regorz, MSc.

June 2, 2024

When you are estimating a path model with manifest variables sometimes you have a hypothesis comparing two paths with each other. Example hypothesis: The effect of x1 on y is significantly stronger than the effect of x2 on y.

There are two different approaches available to test such a hypothesis with R and lavaan: LR-tests and contrasts. Here, you will learn both of them.

### 1. Example Model

We will look at the two possible approaches with a simple model example, see figure 1.

Figure 1

Example Model

Let’s say we want to compare the two a-paths of this model to each other (IV1 -> MED, IV2 -> MED) in order to see which is stronger.

Here is the lavaan code for this model. I have defined labels for all structural paths because we can use those later for the path comparisons.

model1 <- '

MED ~ a1 * IV1 + a2 * IV2

DV1 ~ b1 * MED + c11 * IV1

DV2 ~ b2 * MED

DV1 ~~ DV2

'

model_fit <- sem(data = my_data, model = model1)

summary(model_fit, fit.measures = TRUE)

For this model we get a good model fit (Chi-square = 37.35, p < .001, CFI = .983, SRMR = .010). Both effects of interest are significant, IV1->MED with a path coefficient of 0.304, p < .001, IV2->MED with a path coefficient of 0.500, p < .001. The second path is larger but we don’t know whether the difference between these two effects is significant.

### 2. LR-Test

One way to compare two paths is using a model comparison with a likelihood-ratio-test (LR-test, chi square difference test). With this approach we compare two models to each other:

Model 1 is the unconstrained model.

Model 2 is a model where the two paths that are to be compared are constrained to be equal

After fitting both models the resulting model fit objects are compared with an LR-test. The null hypothesis of this test is that those two paths are equal. If the LR-test is significant we have shown that this is not the case and that the two paths are, in fact, significantly different from each other.

For this approach we estimate the model a second time, this time with an equality constraint for the two effects we want to compare to each other. Please note that for an equality constraint you need two equal signs (==).

model2 <- '

MED ~ a1 * IV1 + a2 * IV2

DV1 ~ b1 * MED + c11 * IV1

DV2 ~ b2 * MED

DV1 ~~ DV2

a1 == a2

'

model_fit2 <- sem(data = my_data, model = model2)

Now we can compare the fit of both models to each other.

lavTestLRT(model_fit, model_fit2)

The results are shown in figure 2.

Figure 2

Results LR-Test

We can see that the second, constrained, model shows a significantly worse fit than the unconstrained model. Therefore, the null hypothesis of two equal paths can be discarded and we have shown that the two paths are significantly different from each other (the path from IV2 to MED being the larger one based on the results of model 1 reported in the previous section of this post).

### 3. Contrasts

There is a second option to compare two paths. Instead of comparing two models we can define a contrast (i.e., a user defined parameter) that is the difference between the two effects we want to compare to each other.

For that we refit the original model, but this time with one additional element: We include a user defined parameter using the labels and the operator :=

model3 <- '

MED ~ a1 * IV1 + a2 * IV2

DV1 ~ b1 * MED + c11 * IV1

DV2 ~ b2 * MED

DV1 ~~ DV2

contr_a2_a1 := a2 - a1

'

model_fit3 <- sem(data = my_data, model = model3)

summary(model_fit3, fit.measures = TRUE)

User defined effects don’t change the model fit, we get the same overall model fit as in the first model. But at the end of the parameter estimates we get an additional line with the user defined effect, see figure 3.

Figure 3

User Defined Contrast

This shows that the path a2 is significantly larger than the path a1.

### 4. Choosing the Best Method

Which of the two methods should you use, LR-test or contrasts?

The LR-test has the advantage that the scale of the variables does not matter as much as for the contrast. Thus, in theory the LR-test should be preferred.

However, there are two practical advantages of the contrast approach:

1. If you want to run more than one comparison between paths in your model with the LR-test you need to rerun your model as many times as you have planned comparisons. If you use contrasts, instead, you can define more than one contrast in one model (by adding additional lines with user defined effects to your model specification code), making it much easier and faster to compare many effects.

2. If you want to compare two indirect effects to each other you can easily extend the contrast approach to that. Let’s say you want to compare the indirect effect IV1-MED-DV1 to the indirect effect IV2-MED-DV1. Then, using the labels, you could simply define a contrast for these indirect effects as part of your model definition:

ind_11_21 := a1 * b - a2 * b

The resulting contrast directly tests whether those two indirect effects are different from each other (when calculating indirect effects it can be a good idea to use bootstrapping or Monte Carlo simulation which is not shown here).

### 5. The Scale Matters

There is one important point to keep in mind when using one of the two path comparison approaches. Both lavaan codes compare the unstandardized effects. If you want to compare the standardized effects (= betas) instead, you could standardize the variables in your model first and then run the path comparison method of your choice (LR-test or contrast).

### Citation

Regorz, A. (2024, June 2). Comparing paths in a path model with R/lavaan. Regorz Statistik. http://www.regorz-statistik.de/blog/lavaan_path_comparison.html