井出草平の研究ノート

複数グループのCFAのフィッティング指標[R]

複数グループに分けての確証的因子分析。
とりあえずの用途としては、構成概念妥当性を調べる際に複数グループのフィッティング指標を見るというもの。測定の不定性と言われるもの(Measurement Invariance)である。

lavaan.ugent.be

グループ変数は"school"。

モデルとフィッティング指標の出力

library(lavaan)
HS.model <- '  visual =~ x1 + x2 + x3
              textual =~ x4 + x5 + x6
              speed   =~ x7 + x8 + x9 '
fit <- cfa(HS.model, 
           data = HolzingerSwineford1939, estimator = "WLSMV",
           group = "school")
fitMeasures(fit, c("chisq","df","pvalue","gfi","agfi","cfi","tli","rmsea", "srmr"))
 chisq     df pvalue    gfi   agfi    cfi    tli  rmsea   srmr 
56.995 48.000  0.175  0.999  0.997  0.990  0.985  0.035  0.061 

semToolsを用いたフィッティング指標の出力

library(semTools)
measurementInvariance(model=HS.model, estimator= "ML",
                      data = HolzingerSwineford1939, 
                      group = "school")

結果。

The measurementInvariance function is deprecated, and it will cease to be included in future versions of semTools. See help('semTools-deprecated) for details.
Measurement invariance models:

Model 1 : fit.configural
Model 2 : fit.loadings
Model 3 : fit.intercepts
Model 4 : fit.means

Chi Square Difference Test

               Df    AIC    BIC  Chisq Chisq diff Df diff Pr(>Chisq)    
fit.configural 48 7484.4 7706.8 115.85                                  
fit.loadings   54 7480.6 7680.8 124.04      8.192       6     0.2244    
fit.intercepts 60 7508.6 7686.6 164.10     40.059       6  4.435e-07 ***
fit.means      63 7543.1 7710.0 204.61     40.502       3  8.338e-09 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1


Fit measures:

Fit measures:以降が表示されず、measurementInvarianceコマンドが非推奨になるという警告がでる。measEq.syntaxコマンドが今後は使われていくようだ。

measEq.syntaxの使用例

こちらを参考にしてみたものの、いまいちまだ理解ができていない。

https://groups.google.com/g/lavaan/c/oKwP0_6-i1g

WLSMVをestimatorとして指定してみた。

fit1 <- cfa(HS.model, data = HolzingerSwineford1939, std.lv = TRUE, group = "school")
fit2 <- measEq.syntax(configural.model = fit1, group = "school",estimator = "WLSMV",
                        group.equal = c("loadings","intercepts"),
                        return.fit = TRUE)
summary(fit2)
fitMeasures(fit2, c("chisq","df","pvalue","gfi","agfi","cfi","tli","rmsea", "srmr"))

結果。

 chisq     df pvalue    gfi   agfi    cfi    tli  rmsea   srmr 
87.919 60.000  0.011  0.998  0.997  0.969  0.962  0.056  0.076 

なお「WLSMVは推定量ではなく、estimator = "DWLS"、test = "scaled.shifted"、se = "robust.sem"を設定するためのショートカットにすぎない」ので注意。

この話、小野島昂洋さんのブログでも書いてあった。Mplus1-5と6以降ではWLSMVの挙動が違うらしい。

onoshima.github.io

WLSMVというのはそもそも,estimatorのみを指している訳でなく,estimatorがDWLSで,robust標準誤差を用いて,平均と分散を調整したテスト統計量を使う3点セットのことらしい

group.equal = c("loadings","intercepts")という指定はscalar invarianceモデルだったと思うので、Configural /Metric invarianceモデルの場合はこのあたりを変更すればよいのだろう。

積み残しがたくさんあるので、また後日、疑問点を解決したい。