/
approx_fi.Rmd
129 lines (89 loc) · 4.73 KB
/
approx_fi.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
---
title: "Approximate fit indices"
author: Mauricio Garnier-Villarreal
bibliography:
- refs.bib
---
```{r pkgld, include=FALSE}
library(blavaan, quietly=TRUE)
library(lavaan, quietly=TRUE)
library(bayesplot)
```
### Introduction
In SEM, one of the first steps is to evaluate the model's global fit. This is commonly done by presenting multiple fit indices, with some of the most common being based on the model's $\chi^2$. We have developed Bayesian versions of these indices [@garnier_adapting_2020] that can be computed with *blavaan*.
### Noncentrality-Based Fit Indices
This group of indices compares the hypothesized model against the perfect saturated model. It specifically uses the noncentrality parameter $\hat{\lambda} = \chi^2 - df$, with the df being adjusted by different model/data characterictics.
Specific indices include Root Mean Square Error of approximation (RMSEA), McDonald’s centrality index (Mc), gamma-hat ($\hat{\Gamma}$), and adjusted gamma-hat ($\hat{\Gamma}_{adj}$).
We will show an example with the @holswi39 example. You first estimate your SEM/CFA model as usual
```{r, include=FALSE, cache=TRUE}
HS.model <- ' visual =~ x1 + x2 + x3
textual =~ x4 + x5 + x6
speed =~ x7 + x8 + x9 '
fit <- bcfa(HS.model, data=HolzingerSwineford1939, std.lv=TRUE)
```
```{r, eval=F}
HS.model <- ' visual =~ x1 + x2 + x3
textual =~ x4 + x5 + x6
speed =~ x7 + x8 + x9 '
fit <- bcfa(HS.model, data=HolzingerSwineford1939, std.lv=TRUE)
```
You then need to pass the model to the ```blavFitIndices()``` function
```{r bfi1, cache=TRUE, warning=FALSE}
gl_fits <- blavFitIndices(fit)
```
Finally, you can describe the posterior distribution for each of the indices with their ```summary()``` function. With this call, we see the 3 central tendency measures (mean median, and mode), the standard deviation, and the 90% Credible Interval
```{r}
summary(gl_fits, central.tendency = c("mean","median","mode"), prob = .90)
```
### Incremental Fit Indices
Another group of fit indices compares the hypothesized model with the *worst* possible model, so they are called incremental indices. Such indices compare your model's $\chi^2_H$ to the *null* model's $\chi^2_0$ in different ways. Indices include the Comparative Fit Index (CFI), Tucker-Lewis Index (TLI), and Normed Fit Index (NFI).
To estimate these indices we need to define and estimate the respective *null* model. The standard *null* model used by default in frequentist SEM programs (like *lavaan*) includes only the indicators variances and intercepts, and no covariances between items.
You can specify your *null* model by including only the respective indicator variances in your model syntax, such as
```{r nmod, include=FALSE, cache=TRUE}
HS.model_null <- '
x1 ~~ x1
x2 ~~ x2
x3 ~~ x3
x4 ~~ x4
x5 ~~ x5
x6 ~~ x6
x7 ~~ x7
x8 ~~ x8
x9 ~~ x9 '
fit_null <- bcfa(HS.model_null, data=HolzingerSwineford1939)
```
```{r, eval=F}
HS.model_null <- '
x1 ~~ x1
x2 ~~ x2
x3 ~~ x3
x4 ~~ x4
x5 ~~ x5
x6 ~~ x6
x7 ~~ x7
x8 ~~ x8
x9 ~~ x9 '
fit_null <- bcfa(HS.model_null, data=HolzingerSwineford1939)
```
Once you have your hypothesized and null models, you pass both to the ```blavFitIndices``` function, and now it will provide both types of fit indices
```{r bfi2, cache = TRUE, warning = FALSE}
gl_fits_all <- blavFitIndices(fit, baseline.model = fit_null)
summary(gl_fits_all, central.tendency = c("mean","median","mode"), prob = .90)
```
The ```summary()``` method now presents the central tendency measure you asked for, standard deviation, and credible interval for the noncentrality and incremental fit indices.
### Access the indices posterior distributions
You can also extract the posterior distributions for the respective indices, this way you can explore further details. For example, diagnostic plots using the ```bayesplot``` package.
```{r expi}
dist_fits <- data.frame(gl_fits_all@indices)
head(dist_fits)
```
Once we have saved the posterior distributions, we can explore the the histogram and scatterplots between indices.
```{r plpi, warning = FALSE}
mcmc_pairs(dist_fits, pars = c("BRMSEA","BGammaHat","BCFI","BTLI"),
diag_fun = "hist")
```
### Summary
You can estimate posterior distributions for $\chi^2$ based global fit indices. Notice that here we only presented the fit indices based on the recommended method *devM* and with the recommended number of parameters metric *loo*. These can be adjusted by the user if desired.
The general recommendation is to prefer $\hat{\Gamma}$ and CFI, as these have shown to be less sensitive to model and data characteristics.
These defaults and recommendations are made based on previous simulation research. For more details about the fit indices please see @garnier_adapting_2020.
### References