構造方程式モデル

勉強 11日目

Soichi Matsuura https://so-ichi.com/ (Ritsumeikan University)http://www.ritsumei.ac.jp/
2020年1月7日

Table of Contents


構造方程式モデル

SEMについて

構造方程式モデル(SEM)とは,線形回帰や因子分析といった分析手法を一般化して体系化したものである。 以前は共分散構造分析と呼ばれていたが,最近は構造方程式モデル(Systematic Equation Model: SEM)と呼ばれることが多い。 またSEMの世界では,

というらしい。特に意味はない。

パス図

変数の因果関係や相互関係を図で表したものであり,基本的に研究者が仮説や設定として事前に用意しておくものである。 つまり探索的な因子分析とは異なり,潜在変数(共通因子)から影響を受ける要素を事前に想定したモデルとなる。 パス図の表現するルールとして,

分析

RでSEMを行う場合に事実上の標準となっているパッケージがlavaanである。 まずlavaanを読み込む。


# install.packages("lavaan") # first time only
library(lavaan)

ここでは,Rで構造方程式モデル推定を勉強のためのバイブルである豊田 (2014)「共分散構造分析 R編」東京図書のデータを用いる。 データはこのテキストの資料配付サイトから入手できる。


df <- read.csv("seminar.csv")

このデータは,セミナーにおける「充実感」と「講師の質」を調査するためのデータであり,

から構成されている。上の4つは「講師の質」を表し,下の3つは「本人の充実度」を表しそうである。

最初に,変数を定義する。 lavaanでモデルを設定するための記法は

となっている。これを'で囲むことでモデルの指定ができる。


model1 <- ' # 因子分析
  f1 =~ text + pre + pace + sup
  f2 =~ satis + comp + mat
  #f2 ~~ f1
  '

上記で構築したmodel1lavaansem()関数で推定する。


fit <- sem(
  model = model1, 
  data = df,
  estimator = "ML")

推定結果を結果をsummary() で表示する。


summary(object = fit, standardize = TRUE)

lavaan 0.6-5 ended normally after 44 iterations

  Estimator                                         ML
  Optimization method                           NLMINB
  Number of free parameters                         15
                                                      
  Number of observations                           118
                                                      
Model Test User Model:
                                                      
  Test statistic                                14.992
  Degrees of freedom                                13
  P-value (Chi-square)                           0.308

Parameter Estimates:

  Information                                 Expected
  Information saturated (h1) model          Structured
  Standard errors                             Standard

Latent Variables:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv
  f1 =~                                                        
    text              1.000                               0.327
    pre               2.247    0.837    2.685    0.007    0.736
    pace              1.550    0.615    2.522    0.012    0.508
    sup               1.855    0.680    2.727    0.006    0.607
  f2 =~                                                        
    satis             1.000                               0.931
    comp              0.570    0.250    2.282    0.022    0.530
    mat               0.385    0.170    2.261    0.024    0.358
  Std.all
         
    0.320
    0.814
    0.426
    0.538
         
    0.659
    0.402
    0.390

Covariances:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv
  f1 ~~                                                        
    f2                0.138    0.068    2.025    0.043    0.453
  Std.all
         
    0.453

Variances:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv
   .text              0.942    0.128    7.335    0.000    0.942
   .pre               0.275    0.131    2.099    0.036    0.275
   .pace              1.160    0.167    6.929    0.000    1.160
   .sup               0.905    0.149    6.060    0.000    0.905
   .satis             1.127    0.381    2.955    0.003    1.127
   .comp              1.463    0.230    6.364    0.000    1.463
   .mat               0.716    0.111    6.465    0.000    0.716
    f1                0.107    0.071    1.505    0.132    1.000
    f2                0.866    0.412    2.103    0.035    1.000
  Std.all
    0.898
    0.337
    0.818
    0.711
    0.565
    0.839
    0.848
    1.000
    1.000

推定結果から,パス図を作成するために,semPlotパッケージを用いる。


#install.packages("semPlot")
library(semPlot)
semPaths(fit, "model1", "std", edge.label.cex = 1.2, residuals = FALSE, intercepts = FALSE)

課題

以前利用した,飲み物の好みについてのアンケート調査データを用いて,構造方程式を構築し,推定する。


df2 <- read.csv("chap14.csv") # 飲み物のデータ

資料に示されたパス図をもとに,モデルを構築し,推定する。


model2 <- '
f3 =~ café + tea + milk
f3 ~ sex
'
fit2 <- sem(model2, data = df2, auto.var = TRUE)
summary(fit2, standardized = TRUE)

lavaan 0.6-5 ended normally after 33 iterations

  Estimator                                         ML
  Optimization method                           NLMINB
  Number of free parameters                          7
                                                      
  Number of observations                            20
                                                      
Model Test User Model:
                                                      
  Test statistic                                18.780
  Degrees of freedom                                 2
  P-value (Chi-square)                           0.000

Parameter Estimates:

  Information                                 Expected
  Information saturated (h1) model          Structured
  Standard errors                             Standard

Latent Variables:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv
  f3 =~                                                        
    café             1.000                               0.929
    tea               1.106    0.164    6.739    0.000    1.028
    milk              0.785    0.132    5.934    0.000    0.729
  Std.all
         
    0.868
    0.984
    0.905

Regressions:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv
  f3 ~                                                         
    sex               0.102    0.429    0.238    0.812    0.110
  Std.all
         
    0.054

Variances:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv
   .café             0.284    0.107    2.655    0.008    0.284
   .tea               0.034    0.072    0.470    0.639    0.034
   .milk              0.118    0.052    2.283    0.022    0.118
   .f3                0.861    0.355    2.424    0.015    0.997
  Std.all
    0.247
    0.031
    0.182
    0.997

推定結果からパス図を作成する。


semPaths(fit2, "model2", "std", edge.label.cex = 1.2, residuals = FALSE, intercepts = FALSE)

さらに,複雑なパス図に基づいて次のようにモデルを構築する。


model3 <- ' # sem
  f3 =~ café + tea + milk
  f4 =~ water + g_tea + w_tea
  f3 ~ sex
  f4 ~ sex
  '

上記のモデルを推定し,作図する。


fit3 <- sem(model3, data = df2, auto.var = TRUE)
summary(fit3, standardized = TRUE)

lavaan 0.6-5 ended normally after 33 iterations

  Estimator                                         ML
  Optimization method                           NLMINB
  Number of free parameters                         15
                                                      
  Number of observations                            20
                                                      
Model Test User Model:
                                                      
  Test statistic                                23.059
  Degrees of freedom                                12
  P-value (Chi-square)                           0.027

Parameter Estimates:

  Information                                 Expected
  Information saturated (h1) model          Structured
  Standard errors                             Standard

Latent Variables:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv
  f3 =~                                                        
    café             1.000                               0.930
    tea               1.104    0.164    6.749    0.000    1.027
    milk              0.785    0.132    5.954    0.000    0.730
  f4 =~                                                        
    water             1.000                               0.914
    g_tea             0.838    0.169    4.972    0.000    0.766
    w_tea             1.106    0.160    6.917    0.000    1.011
  Std.all
         
    0.868
    0.983
    0.906
         
    0.909
    0.803
    0.969

Regressions:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv
  f3 ~                                                         
    sex               0.106    0.430    0.247    0.805    0.114
  f4 ~                                                         
    sex               0.450    0.417    1.079    0.280    0.493
  Std.all
         
    0.056
         
    0.241

Covariances:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv
 .f3 ~~                                                        
   .f4                0.086    0.193    0.448    0.654    0.105
  Std.all
         
    0.105

Variances:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv
   .café             0.282    0.106    2.652    0.008    0.282
   .tea               0.036    0.071    0.505    0.613    0.036
   .milk              0.117    0.051    2.274    0.023    0.117
   .water             0.175    0.093    1.891    0.059    0.175
   .g_tea             0.323    0.115    2.811    0.005    0.323
   .w_tea             0.065    0.093    0.704    0.482    0.065
   .f3                0.863    0.355    2.427    0.015    0.997
   .f4                0.786    0.305    2.581    0.010    0.942
  Std.all
    0.246
    0.033
    0.180
    0.173
    0.355
    0.060
    0.997
    0.942

semPaths(fit3, "model3", "std", fit.measures = TRUE, edge.label.cex = 1.2, residuals = FALSE, intercepts = FALSE)