1 例題:共分散構造分析

大学生の生活満足度調査に関するデータがある。各変数は以下である。

  • V1:進路につながるという意識をもって大学に通っている
  • V2:自分が望む進路のために、今努力している
  • V3:大学は進路について自分の目標をもって過ごすべきだと思う
  • V4:大学生活を送るうえで、進路について考えることは大事なことだと思う。
  • V5:今やりたいことがある
  • V6:大学に行くのが毎日楽しい
  • V7:毎日の生活にハリがある
  • V8:自分は価値のある大学生活を送っていると思う

大学生活への「目的意識」(V1~V4)が大学生活の「充実感」(V5~V8)につながるかを検証したい

1.1 データの読み込み

# スクリプト山に添付されている"collegelife.csv"を読み込む
dat <- read.csv("collegelife.csv", header = T)

# クラブ活動をしているかどうかを因子型に
dat$club <- factor(dat$club, levels = c(1,0), labels = c("yes","no"))

1.2 分析

# パッケージを読み込む
library(lavaan)

# モデルを組む
model <- "
conscious =~ V1 + V2 + V3 + V4
satis =~ V5 + V6 + V7 + V8
satis ~ conscious
"
# 計算を行う
out <- sem(model = model, 
           estimator = "ML",
           data = dat)

# 結果
summary(out, 
        fit.measures = T,     # 適合度指標もあわせて表示する
        rsquare = T)       # 決定係数も表示する(値が1に近いほど、現状のモデルで当該変数をうまく予測できる)
## lavaan 0.6.16 ended normally after 26 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        17
## 
##   Number of observations                           187
## 
## Model Test User Model:
##                                                       
##   Test statistic                                63.346
##   Degrees of freedom                                19
##   P-value (Chi-square)                           0.000
## 
## Model Test Baseline Model:
## 
##   Test statistic                               566.141
##   Degrees of freedom                                28
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    0.918
##   Tucker-Lewis Index (TLI)                       0.879
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)              -1869.229
##   Loglikelihood unrestricted model (H1)      -1837.556
##                                                       
##   Akaike (AIC)                                3772.457
##   Bayesian (BIC)                              3827.386
##   Sample-size adjusted Bayesian (SABIC)       3773.540
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.112
##   90 Percent confidence interval - lower         0.082
##   90 Percent confidence interval - upper         0.143
##   P-value H_0: RMSEA <= 0.050                    0.001
##   P-value H_0: RMSEA >= 0.080                    0.960
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.072
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
## 
## Latent Variables:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   conscious =~                                        
##     V1                1.000                           
##     V2                0.982    0.107    9.153    0.000
##     V3                0.695    0.097    7.171    0.000
##     V4                0.531    0.086    6.173    0.000
##   satis =~                                            
##     V5                1.000                           
##     V6                1.030    0.140    7.368    0.000
##     V7                1.224    0.157    7.796    0.000
##     V8                1.294    0.154    8.403    0.000
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   satis ~                                             
##     conscious         0.750    0.107    7.017    0.000
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##    .V1                0.370    0.057    6.440    0.000
##    .V2                0.480    0.066    7.280    0.000
##    .V3                0.576    0.066    8.701    0.000
##    .V4                0.506    0.056    9.031    0.000
##    .V5                0.721    0.084    8.612    0.000
##    .V6                0.586    0.071    8.281    0.000
##    .V7                0.608    0.078    7.756    0.000
##    .V8                0.359    0.059    6.048    0.000
##     conscious         0.566    0.099    5.737    0.000
##    .satis             0.134    0.043    3.130    0.002
## 
## R-Square:
##                    Estimate
##     V1                0.605
##     V2                0.532
##     V3                0.322
##     V4                0.240
##     V5                0.386
##     V6                0.450
##     V7                0.527
##     V8                0.679
##     satis             0.703
standardizedSolution(out)     # 標準化係数
##          lhs op       rhs est.std    se      z pvalue ci.lower ci.upper
## 1  conscious =~        V1   0.778 0.041 18.865      0    0.697    0.859
## 2  conscious =~        V2   0.730 0.045 16.285      0    0.642    0.818
## 3  conscious =~        V3   0.568 0.058  9.801      0    0.454    0.681
## 4  conscious =~        V4   0.490 0.063  7.715      0    0.365    0.614
## 5      satis =~        V5   0.621 0.052 11.960      0    0.519    0.723
## 6      satis =~        V6   0.671 0.048 14.088      0    0.578    0.764
## 7      satis =~        V7   0.726 0.043 17.009      0    0.642    0.810
## 8      satis =~        V8   0.824 0.034 23.956      0    0.757    0.891
## 9      satis  ~ conscious   0.839 0.045 18.840      0    0.751    0.926
## 10        V1 ~~        V1   0.395 0.064  6.160      0    0.269    0.521
## 11        V2 ~~        V2   0.468 0.065  7.149      0    0.339    0.596
## 12        V3 ~~        V3   0.678 0.066 10.312      0    0.549    0.807
## 13        V4 ~~        V4   0.760 0.062 12.217      0    0.638    0.882
## 14        V5 ~~        V5   0.614 0.065  9.517      0    0.488    0.741
## 15        V6 ~~        V6   0.550 0.064  8.601      0    0.424    0.675
## 16        V7 ~~        V7   0.473 0.062  7.623      0    0.351    0.594
## 17        V8 ~~        V8   0.321 0.057  5.664      0    0.210    0.432
## 18 conscious ~~ conscious   1.000 0.000     NA     NA    1.000    1.000
## 19     satis ~~     satis   0.297 0.075  3.972      0    0.150    0.443
# 参考:次のように指定すると、最終列に標準化係数が表示される
summary(out, standardized = T)
## lavaan 0.6.16 ended normally after 26 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        17
## 
##   Number of observations                           187
## 
## Model Test User Model:
##                                                       
##   Test statistic                                63.346
##   Degrees of freedom                                19
##   P-value (Chi-square)                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
## 
## Latent Variables:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   conscious =~                                                          
##     V1                1.000                               0.753    0.778
##     V2                0.982    0.107    9.153    0.000    0.739    0.730
##     V3                0.695    0.097    7.171    0.000    0.523    0.568
##     V4                0.531    0.086    6.173    0.000    0.400    0.490
##   satis =~                                                              
##     V5                1.000                               0.673    0.621
##     V6                1.030    0.140    7.368    0.000    0.693    0.671
##     V7                1.224    0.157    7.796    0.000    0.824    0.726
##     V8                1.294    0.154    8.403    0.000    0.871    0.824
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   satis ~                                                               
##     conscious         0.750    0.107    7.017    0.000    0.839    0.839
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .V1                0.370    0.057    6.440    0.000    0.370    0.395
##    .V2                0.480    0.066    7.280    0.000    0.480    0.468
##    .V3                0.576    0.066    8.701    0.000    0.576    0.678
##    .V4                0.506    0.056    9.031    0.000    0.506    0.760
##    .V5                0.721    0.084    8.612    0.000    0.721    0.614
##    .V6                0.586    0.071    8.281    0.000    0.586    0.550
##    .V7                0.608    0.078    7.756    0.000    0.608    0.473
##    .V8                0.359    0.059    6.048    0.000    0.359    0.321
##     conscious         0.566    0.099    5.737    0.000    1.000    1.000
##    .satis             0.134    0.043    3.130    0.002    0.297    0.297

1.3 結果をパス図で表示する

分析作業のために関数を使用する。ただしデザインはあまり美しく整序されたものとはいいがたいため、論文に掲載する際には別途図を作成することが一般的である。

library(semPlot)
semPaths(out, 
         whatLabels = "stand",   # 標準化係数を表示する
         optimizeLatRes = T, 
         edge.label.cex = 1)

1.4 構成概念スコア

因子分析と同様に、個々人の構成概念(ここでは目的意識と充実感)のスコアを計算することも可能である。

factor_score <- predict(out)
plot(factor_score)

2 SEMと因子分析、回帰分析の結果の比較

2.1 因子分析との関係

library(psych)

fa.out <- fa(dat[,c("V1","V2","V3","V4")], 1, fm = "ml")
fa.out
## Factor Analysis using method =  ml
## Call: fa(r = dat[, c("V1", "V2", "V3", "V4")], nfactors = 1, fm = "ml")
## Standardized loadings (pattern matrix) based upon correlation matrix
##     ML1   h2   u2 com
## V1 0.73 0.54 0.46   1
## V2 0.68 0.46 0.54   1
## V3 0.63 0.39 0.61   1
## V4 0.58 0.34 0.66   1
## 
##                 ML1
## SS loadings    1.73
## Proportion Var 0.43
## 
## Mean item complexity =  1
## Test of the hypothesis that 1 factor is sufficient.
## 
## df null model =  6  with the objective function =  0.93 with Chi Square =  171.7
## df of  the model are 2  and the objective function was  0.06 
## 
## The root mean square of the residuals (RMSR) is  0.06 
## The df corrected root mean square of the residuals is  0.1 
## 
## The harmonic n.obs is  187 with the empirical chi square  8.21  with prob <  0.016 
## The total n.obs was  187  with Likelihood Chi Square =  10.9  with prob <  0.0043 
## 
## Tucker Lewis Index of factoring reliability =  0.838
## RMSEA index =  0.154  and the 90 % confidence intervals are  0.074 0.25
## BIC =  0.44
## Fit based upon off diagonal values = 0.98
## Measures of factor score adequacy             
##                                                    ML1
## Correlation of (regression) scores with factors   0.87
## Multiple R square of scores with factors          0.76
## Minimum correlation of possible factor scores     0.52
# SEM
fa.md <- "
f =~ V1 + V2 + V3 + V4
"
sem.out <- sem(fa.md, estimator = "ml", dat)
summary(sem.out)                 
## lavaan 0.6.16 ended normally after 18 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                         8
## 
##   Number of observations                           187
## 
## Model Test User Model:
##                                                       
##   Test statistic                                11.132
##   Degrees of freedom                                 2
##   P-value (Chi-square)                           0.004
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
## 
## Latent Variables:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   f =~                                                
##     V1                1.000                           
##     V2                0.970    0.138    7.052    0.000
##     V3                0.816    0.121    6.749    0.000
##     V4                0.671    0.105    6.400    0.000
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##    .V1                0.433    0.073    5.924    0.000
##    .V2                0.553    0.080    6.890    0.000
##    .V3                0.515    0.068    7.590    0.000
##    .V4                0.439    0.055    8.039    0.000
##     f                 0.503    0.103    4.862    0.000
standardizedsolution(sem.out)         # 測定方程式の係数と一致する
##   lhs op rhs est.std    se      z pvalue ci.lower ci.upper
## 1   f =~  V1   0.733 0.054 13.571      0    0.627    0.839
## 2   f =~  V2   0.679 0.056 12.022      0    0.568    0.790
## 3   f =~  V3   0.628 0.059 10.584      0    0.511    0.744
## 4   f =~  V4   0.583 0.062  9.392      0    0.462    0.705
## 5  V1 ~~  V1   0.463 0.079  5.842      0    0.307    0.618
## 6  V2 ~~  V2   0.539 0.077  7.031      0    0.389    0.689
## 7  V3 ~~  V3   0.606 0.074  8.140      0    0.460    0.752
## 8  V4 ~~  V4   0.660 0.072  9.108      0    0.518    0.802
## 9   f ~~   f   1.000 0.000     NA     NA    1.000    1.000

2.2 回帰分析との関係

2.2.1 事例1:1つの重回帰分析

# 回帰分析
out.lm1 <- lm(V1 ~ V2 + V3, data = dat)
summary(out.lm1)
## 
## Call:
## lm(formula = V1 ~ V2 + V3, data = dat)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -3.5785 -0.4418  0.1287  0.4215  2.5433 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  1.04206    0.29181   3.571 0.000454 ***
## V2           0.42944    0.06073   7.072 3.09e-11 ***
## V3           0.27786    0.06676   4.162 4.84e-05 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.7789 on 184 degrees of freedom
## Multiple R-squared:  0.3623, Adjusted R-squared:  0.3554 
## F-statistic: 52.28 on 2 and 184 DF,  p-value: < 2.2e-16
# SEM
lm.md1 <- "
V1 ~ 1 + V2 + V3"
sem.out <- sem(lm.md1, estimator = "ml", dat)
summary(sem.out)                        # 回帰分析の係数と一致する
## lavaan 0.6.16 ended normally after 1 iteration
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                         4
## 
##   Number of observations                           187
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   V1 ~                                                
##     V2                0.429    0.060    7.129    0.000
##     V3                0.278    0.066    4.196    0.000
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|)
##    .V1                1.042    0.289    3.600    0.000
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##    .V1                0.597    0.062    9.670    0.000

2.2.2 事例2: 2つの重回帰分析

# ライブラリを読み込む
library(texreg)
## Version:  1.38.6
## Date:     2022-04-06
## Author:   Philip Leifeld (University of Essex)
## 
## Consider submitting praise using the praise or praise_interactive functions.
## Please cite the JSS article in your publications -- see citation("texreg").
screenreg(lm(V1 ~ V2 + V3, data = dat))
## 
## =======================
##              Model 1   
## -----------------------
## (Intercept)    1.04 ***
##               (0.29)   
## V2             0.43 ***
##               (0.06)   
## V3             0.28 ***
##               (0.07)   
## -----------------------
## R^2            0.36    
## Adj. R^2       0.36    
## Num. obs.    187       
## =======================
## *** p < 0.001; ** p < 0.01; * p < 0.05
screenreg(lm(V3 ~ V2, data = dat))
## 
## =======================
##              Model 1   
## -----------------------
## (Intercept)    2.93 ***
##               (0.24)   
## V2             0.34 ***
##               (0.06)   
## -----------------------
## R^2            0.14    
## Adj. R^2       0.14    
## Num. obs.    187       
## =======================
## *** p < 0.001; ** p < 0.01; * p < 0.05
# SEM
lm.md2 <- "
V1 ~ V2 + V3 + 1
V3 ~ V2 + 1"
sem.out2 <- sem(lm.md2, estimator = "ml", dat)
summary(sem.out2)            # 二つの回帰分析の結果と一致する
## lavaan 0.6.16 ended normally after 1 iteration
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                         7
## 
##   Number of observations                           187
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   V1 ~                                                
##     V2                0.429    0.060    7.129    0.000
##     V3                0.278    0.066    4.196    0.000
##   V3 ~                                                
##     V2                0.344    0.062    5.587    0.000
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|)
##    .V1                1.042    0.289    3.600    0.000
##    .V3                2.930    0.237   12.350    0.000
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##    .V1                0.597    0.062    9.670    0.000
##    .V3                0.728    0.075    9.670    0.000

2.3 共分散・相関係数との関係

md3 <- "
V1 ~~ V2
V1 ~~ V3
V2 ~~ V3
"
out3 <- sem(md3, dat[,1:8], estimator = "ULS") # 推定方法を最小二乗法にあわせる
summary(out3)
## lavaan 0.6.16 ended normally after 2 iterations
## 
##   Estimator                                        ULS
##   Optimization method                           NLMINB
##   Number of model parameters                         6
## 
##   Number of observations                           187
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model        Unstructured
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   V1 ~~                                               
##     V2                0.542    0.073    7.391    0.000
##     V3                0.390    0.073    5.317    0.000
##   V2 ~~                                               
##     V3                0.355    0.073    4.843    0.000
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##     V1                0.941    0.073   12.837    0.000
##     V2                1.032    0.073   14.077    0.000
##     V3                0.854    0.073   11.649    0.000
cov(dat[,1:3]) # 自己共分散(対角成分)はSEMのVarianceに
##           V1        V2        V3
## V1 0.9412340 0.5419182 0.3898281
## V2 0.5419182 1.0321431 0.3551262
## V3 0.3898281 0.3551262 0.8541199
        # 他の変数との共分散はSEMのcovarianceに一致する

standardizedSolution(out3) # 標準化係数は相関係数と一致する
##   lhs op rhs est.std    se     z pvalue ci.lower ci.upper
## 1  V1 ~~  V2   0.550 0.080 6.887      0    0.393    0.706
## 2  V1 ~~  V3   0.435 0.086 5.081      0    0.267    0.602
## 3  V2 ~~  V3   0.378 0.081 4.676      0    0.220    0.537
## 4  V1 ~~  V1   1.000 0.000    NA     NA    1.000    1.000
## 5  V2 ~~  V2   1.000 0.000    NA     NA    1.000    1.000
## 6  V3 ~~  V3   1.000 0.000    NA     NA    1.000    1.000
round(cor(dat[,1:3]),2)
##      V1   V2   V3
## V1 1.00 0.55 0.43
## V2 0.55 1.00 0.38
## V3 0.43 0.38 1.00

3 さまざまなパス図

3.1 逐次モデル

library(lavaan)
library(semPlot)

md1 <- "
V3 ~ V1 + V2
V4 ~ V2 + V3
V1 ~~ V2"
out1 <- sem(md1, dat)

# パス図
semPaths(out1, whatLabels = "stand", optimizeLatRes = T, edge.label.cex = 1)

3.2 非逐次モデル

md2 <- "
V3 ~ V1 + V4
V4 ~ V2 + V3
V1 ~~ V2"
out2 <- sem(md2, dat)

# パス図
semPaths(out2, whatLabels = "stand", optimizeLatRes = T, edge.label.cex = 1)

3.3 完全逐次モデル

md3 <- "
V3 ~ V1 + V2
V4 ~ V1 + V2 + V3
V1 ~~ V2"
out3 <- sem(md3, dat)

# パス図
semPaths(out3, whatLabels = "stand", optimizeLatRes = T, edge.label.cex = 1)

3.4 多重指標モデル(例題再掲)

md4 <- "
conscious =~ V1 + V2 + V3 + V4
satis     =~ V5 + V6 + V7 + V8
satis ~ conscious
"
out4 <- sem(md4, data = dat)

# パス図
semPaths(out4, whatLabels = "stand", optimizeLatRes = T, edge.label.cex = 1)

3.5 MIMICモデル

md5 <- "
satis =~ V5 + V6 + V7 + V8
satis ~ V1 + V2 + V3 + V4
"
out5 <- sem(md5, data = dat)

# パス図
semPaths(out5, whatLabels = "stand", optimizeLatRes = T, edge.label.cex = 1)

3.6 PLSモデル

【注】F1に当たるconsciousには誤差を想定しないものとしている。これは、測定方程式を構成する変数が1つのみのため、このように制約しないと、他の変数の標準誤差が計算できなくなるためである。

md6 <- "
satis =~ V5 + V6 + V7 + V8
conscious =~ satis
conscious ~ V1 + V2 + V3 + V4
satis ~~ satis
conscious ~~ 0*conscious
"
out6 <- sem(md6, data = dat)

# パス図
semPaths(out6, whatLabels = "stand", optimizeLatRes = T, edge.label.cex = 1)

3.7 二次因子モデル

【注】下記の例では1次の因子の自己共分散を1に制約しないとモデルを当てはまらないためこのようにしている。一次因子間の相関が低いため、やや無理のあるモデルといえる。

md7 <- "
conscious =~ V1 + V2 + V3 + V4
satis =~ V5 + V6 + V7 + V8
motivation =~ conscious + satis
conscious ~~ 1*conscious
satis ~~ 1*satis
"
out7 <- sem(md7, data = dat)

# パス図
semPaths(out7, whatLabels = "stand", optimizeLatRes = T, edge.label.cex = 1)

3.8 階層因子分析モデル

理論上は下記のように書く。ただしこのデータでは推定エラーが出る(結果出力省略)

md8 <- "
conscious =~ V1 + V2 + V3 + V4
satis =~ V5 + V6 + V7 + V8
general =~ V1 + V2 + V3 + V4 + V5 + V6 + V7 + V8
general ~~ 0*conscious
general ~~ 0*satis
conscious ~~ 0*satis
"
out8 <- sem(md8, data = dat)
summary(out8)

4 sem関数とlavaan関数

library(lavaan)
library(semPlot)

4.1 sem関数で書いた場合

md.sem <- "
conscious =~ V1 + V2 + V3 + V4
satis     =~ V5 + V6 + V7 + V8
satis ~ conscious"
out.sem <- sem(md4, data = dat)
summary(out.sem)

sem関数で自動的に設定されているパーツを以下の関数を用いて確かめることができる。 - user=0となっている部分が自動的に設定されているもの - ustart=1となっている部分は自動的に制約が設定されているもの である。

parTable(out.sem)
##    id       lhs op       rhs user block group free ustart exo label plabel
## 1   1 conscious =~        V1    1     1     1    0      1   0         .p1.
## 2   2 conscious =~        V2    1     1     1    1     NA   0         .p2.
## 3   3 conscious =~        V3    1     1     1    2     NA   0         .p3.
## 4   4 conscious =~        V4    1     1     1    3     NA   0         .p4.
## 5   5     satis =~        V5    1     1     1    0      1   0         .p5.
## 6   6     satis =~        V6    1     1     1    4     NA   0         .p6.
## 7   7     satis =~        V7    1     1     1    5     NA   0         .p7.
## 8   8     satis =~        V8    1     1     1    6     NA   0         .p8.
## 9   9     satis  ~ conscious    1     1     1    7     NA   0         .p9.
## 10 10        V1 ~~        V1    0     1     1    8     NA   0        .p10.
## 11 11        V2 ~~        V2    0     1     1    9     NA   0        .p11.
## 12 12        V3 ~~        V3    0     1     1   10     NA   0        .p12.
## 13 13        V4 ~~        V4    0     1     1   11     NA   0        .p13.
## 14 14        V5 ~~        V5    0     1     1   12     NA   0        .p14.
## 15 15        V6 ~~        V6    0     1     1   13     NA   0        .p15.
## 16 16        V7 ~~        V7    0     1     1   14     NA   0        .p16.
## 17 17        V8 ~~        V8    0     1     1   15     NA   0        .p17.
## 18 18 conscious ~~ conscious    0     1     1   16     NA   0        .p18.
## 19 19     satis ~~     satis    0     1     1   17     NA   0        .p19.
##    start   est    se
## 1  1.000 1.000 0.000
## 2  0.937 0.982 0.107
## 3  0.784 0.695 0.097
## 4  0.671 0.531 0.086
## 5  1.000 1.000 0.000
## 6  1.150 1.030 0.140
## 7  1.349 1.224 0.157
## 8  1.617 1.294 0.154
## 9  0.000 0.750 0.107
## 10 0.468 0.370 0.057
## 11 0.513 0.480 0.066
## 12 0.425 0.576 0.066
## 13 0.333 0.506 0.056
## 14 0.587 0.721 0.084
## 15 0.533 0.586 0.071
## 16 0.644 0.608 0.078
## 17 0.559 0.359 0.059
## 18 0.050 0.566 0.099
## 19 0.050 0.134 0.043

4.2 lavaan関数で書いた場合

【注】以下の「;」は一行に複数の項目を入れるためのもの。「;」を省略して改行で代替することも可能である。

md.lavaan <- "
conscious =~ 1*V1 + V2 + V3 + V4
satis     =~ 1*V5 + V6 + V7 + V8
satis ~ conscious
V1~~V1; V2~~V2; V3~~V3; V4~~V4
V5~~V5; V6~~V6; V7~~V7; V8~~V8
satis ~~ satis
conscious ~~ conscious"
out.lavaan <- lavaan(md.lavaan, data = dat)
summary(out.lavaan)

5 総合効果と間接効果

総合効果がtotalとして計算されるように係数の計算を以下のように工夫する。

# モデル
md <- "
V1 ~ c*V2 + b*V3
V3 ~ a*V2
ab := a*b
total := c + ab
"
out <- sem(md, dat)
summary(out) # V2の総合効果はtotalに表現されている
## lavaan 0.6.16 ended normally after 1 iteration
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                         5
## 
##   Number of observations                           187
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   V1 ~                                                
##     V2         (c)    0.429    0.060    7.129    0.000
##     V3         (b)    0.278    0.066    4.196    0.000
##   V3 ~                                                
##     V2         (a)    0.344    0.062    5.587    0.000
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##    .V1                0.597    0.062    9.670    0.000
##    .V3                0.728    0.075    9.670    0.000
## 
## Defined Parameters:
##                    Estimate  Std.Err  z-value  P(>|z|)
##     ab                0.096    0.028    3.355    0.001
##     total             0.525    0.058    9.001    0.000
semPaths(out, whatLabels = "stand", optimizeLatRes = T, edge.label.cex = 1)

6 平均共分散構造分析

6.1 観測変数のみの場合(いわゆるパス解析)

md1 <- "
V4 ~ 1 + V1 + V2 + V3
"
out1 <- sem(md1, dat)

semPaths(out1, whatLabels = "est",     # 標準化していないものを出す
         optimizeLatRes = T, 
         edge.label.cex = 1)

6.2 構造変数を含む場合

この場合には、観測変数の切片を0、潜在変数に切片項を入れることに注意。

md2 <- "
conscious =~ 1*V1 + V2 + V3 + V4
conscious ~ 1                         # ここが切片項
V1 + V2 + V3 + V4 ~ 0*1               # 観測変数の切片を0に

satis =~ 1*V5 + V6 + V7 + V8
satis ~ 1 + conscious                 # 回帰式に切片項を加える
V5 + V6 + V7 + V8 ~ 0*1        # 観測変数の切片を0に

V1~~V1; V2~~V2; V3~~V3; V4~~V4
V5~~V5; V6~~V6; V7~~V7; V8~~V8
satis ~~ satis
conscious ~~ conscious"

out2 <- lavaan(md2, data = dat)

semPaths(out2, whatLabels = "est",     # 標準化していないものを出す
         optimizeLatRes = T, 
         edge.label.cex = 1)

7 多母集団同時分析

library(lavaan)
library(semTools)
library(semPlot)

7.1 1因子モデルの場合

# モデルを組む
md1 <- "
satis =~ V5 + V6 + V7 + V8"

# model1 ~ 5(スライド参照)を比較する
compare.md1 <- measurementInvariance(
  model = md1, 
  data = dat, 
  group = "club",                     # グループ変数を指定する
  strict = T,                         # モデル4の厳密な測定不変モデルを検討するか
  quiet = T)                          # 結果をプリントするか
summary(compareFit(compare.md1))
## ################### Nested Model Comparison #########################
## 
## Chi-Squared Difference Test
## 
##                            Df    AIC    BIC   Chisq Chisq diff    RMSEA Df diff
## compare.md1.fit.configural  4 2034.8 2112.3  6.2152                            
## compare.md1.fit.loadings    7 2029.4 2097.3  6.8354     0.6202 0.000000       3
## compare.md1.fit.intercepts 10 2025.0 2083.2  8.4309     1.5954 0.000000       3
## compare.md1.fit.residuals  14 2025.2 2070.4 16.6030     8.1721 0.105619       4
## compare.md1.fit.means      15 2024.5 2066.5 17.8822     1.2792 0.054647       1
##                            Pr(>Chisq)  
## compare.md1.fit.configural             
## compare.md1.fit.loadings      0.89179  
## compare.md1.fit.intercepts    0.66043  
## compare.md1.fit.residuals     0.08547 .
## compare.md1.fit.means         0.25804  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## ####################### Model Fit Indices ###########################
##                              chisq df pvalue  rmsea     cfi     tli   srmr
## compare.md1.fit.configural 6.215†  4   .184  .077    .990    .971  .022†
## compare.md1.fit.loadings    6.835   7   .446 .000† 1.000†  1.001   .026 
## compare.md1.fit.intercepts  8.431  10   .587 .000† 1.000† 1.008†  .030 
## compare.md1.fit.residuals  16.603  14   .278  .045    .989    .990   .050 
## compare.md1.fit.means      17.882  15   .269  .045    .988    .990   .061 
##                                   aic        bic
## compare.md1.fit.configural  2034.801   2112.348 
## compare.md1.fit.loadings    2029.421   2097.274 
## compare.md1.fit.intercepts  2025.017   2083.177 
## compare.md1.fit.residuals   2025.189   2070.424 
## compare.md1.fit.means      2024.468† 2066.472†
## 
## ################## Differences in Fit Indices #######################
##                                                        df  rmsea    cfi    tli
## compare.md1.fit.loadings - compare.md1.fit.configural   3 -0.077  0.010  0.030
## compare.md1.fit.intercepts - compare.md1.fit.loadings   3  0.000  0.000  0.007
## compare.md1.fit.residuals - compare.md1.fit.intercepts  4  0.045 -0.011 -0.018
## compare.md1.fit.means - compare.md1.fit.residuals       1  0.001 -0.001  0.000
##                                                         srmr    aic     bic
## compare.md1.fit.loadings - compare.md1.fit.configural  0.003 -5.380 -15.073
## compare.md1.fit.intercepts - compare.md1.fit.loadings  0.005 -4.405 -14.098
## compare.md1.fit.residuals - compare.md1.fit.intercepts 0.019  0.172 -12.752
## compare.md1.fit.means - compare.md1.fit.residuals      0.011 -0.721  -3.952
# もっとも厳しい5番目のモデルでも指標は許容範囲のため、
# モデル5をもとにモデルをくむ
out <- sem(md1, data = dat, group = "club",
           group.equal = c("loadings","intercepts", "residuals","means"))
summary(out)
## lavaan 0.6.16 ended normally after 29 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        24
##   Number of equality constraints                    11
## 
##   Number of observations per group:                   
##     no                                             119
##     yes                                             68
## 
## Model Test User Model:
##                                                       
##   Test statistic                                17.882
##   Degrees of freedom                                15
##   P-value (Chi-square)                           0.269
##   Test statistic for each group:
##     no                                           5.283
##     yes                                         12.599
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
## 
## 
## Group 1 [no]:
## 
## Latent Variables:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   satis =~                                            
##     V5                1.000                           
##     V6      (.p2.)    1.178    0.179    6.577    0.000
##     V7      (.p3.)    1.391    0.203    6.838    0.000
##     V8      (.p4.)    1.527    0.214    7.123    0.000
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|)
##    .V5      (.10.)    4.055    0.079   51.202    0.000
##    .V6      (.11.)    3.671    0.075   48.621    0.000
##    .V7      (.12.)    3.249    0.083   39.173    0.000
##    .V8      (.13.)    3.602    0.077   46.625    0.000
##     satis             0.000                           
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##    .V5      (.p5.)    0.819    0.093    8.828    0.000
##    .V6      (.p6.)    0.574    0.073    7.886    0.000
##    .V7      (.p7.)    0.600    0.084    7.169    0.000
##    .V8      (.p8.)    0.290    0.071    4.096    0.000
##     satis             0.343    0.097    3.528    0.000
## 
## 
## Group 2 [yes]:
## 
## Latent Variables:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   satis =~                                            
##     V5                1.000                           
##     V6      (.p2.)    1.178    0.179    6.577    0.000
##     V7      (.p3.)    1.391    0.203    6.838    0.000
##     V8      (.p4.)    1.527    0.214    7.123    0.000
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|)
##    .V5      (.10.)    4.055    0.079   51.202    0.000
##    .V6      (.11.)    3.671    0.075   48.621    0.000
##    .V7      (.12.)    3.249    0.083   39.173    0.000
##    .V8      (.13.)    3.602    0.077   46.625    0.000
##     satis             0.000                           
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##    .V5      (.p5.)    0.819    0.093    8.828    0.000
##    .V6      (.p6.)    0.574    0.073    7.886    0.000
##    .V7      (.p7.)    0.600    0.084    7.169    0.000
##    .V8      (.p8.)    0.290    0.071    4.096    0.000
##     satis             0.375    0.117    3.206    0.001
# いずれにも差がなく、両者で比較する意味はあまりない。

7.2 2因子モデルの場合

# モデルをくむ
md2 <- "
satis     =~ V5 + V6 + V7 + V8
conscious =~ V1 + V2 + V3 + V4
satis ~ conscious"

compare.md2 <- measurementInvariance(
  model = md2, 
  data = dat, 
  group = "club",                     # グループ変数を指定する
  strict = T,                         # モデル4の厳密な測定不変モデルを検討するか
  quiet = T)                          # 結果をプリントするか
summary(compareFit(compare.md2))
## ################### Nested Model Comparison #########################
## 
## Chi-Squared Difference Test
## 
##                            Df    AIC    BIC   Chisq Chisq diff    RMSEA Df diff
## compare.md2.fit.configural 38 3767.9 3929.4  81.012                            
## compare.md2.fit.loadings   44 3763.4 3905.5  88.478      7.466 0.051118       6
## compare.md2.fit.intercepts 50 3755.6 3878.4  92.751      4.274 0.000000       6
## compare.md2.fit.residuals  58 3784.8 3881.7 137.910     45.158 0.222884       8
## compare.md2.fit.means      60 3785.2 3875.7 142.354      4.444 0.114313       2
##                            Pr(>Chisq)    
## compare.md2.fit.configural               
## compare.md2.fit.loadings       0.2799    
## compare.md2.fit.intercepts     0.6397    
## compare.md2.fit.residuals   3.434e-07 ***
## compare.md2.fit.means          0.1084    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## ####################### Model Fit Indices ###########################
##                               chisq df pvalue  rmsea    cfi    tli   srmr
## compare.md2.fit.configural 81.012† 38   .000  .110   .922   .886  .068†
## compare.md2.fit.loadings    88.478  44   .000  .104   .920   .898   .077 
## compare.md2.fit.intercepts  92.752  50   .000 .096† .923† .914†  .078 
## compare.md2.fit.residuals  137.910  58   .000  .121   .856   .861   .107 
## compare.md2.fit.means      142.354  60   .000  .121   .852   .861   .114 
##                                   aic        bic
## compare.md2.fit.configural  3767.889   3929.445 
## compare.md2.fit.loadings    3763.355   3905.524 
## compare.md2.fit.intercepts 3755.629†  3878.411 
## compare.md2.fit.residuals   3784.787   3881.720 
## compare.md2.fit.means       3785.231  3875.702†
## 
## ################## Differences in Fit Indices #######################
##                                                        df  rmsea    cfi    tli
## compare.md2.fit.loadings - compare.md2.fit.configural   6 -0.006 -0.003  0.012
## compare.md2.fit.intercepts - compare.md2.fit.loadings   6 -0.008  0.003  0.016
## compare.md2.fit.residuals - compare.md2.fit.intercepts  8  0.026 -0.067 -0.053
## compare.md2.fit.means - compare.md2.fit.residuals       2  0.000 -0.004  0.001
##                                                         srmr    aic     bic
## compare.md2.fit.loadings - compare.md2.fit.configural  0.009 -4.534 -23.921
## compare.md2.fit.intercepts - compare.md2.fit.loadings  0.002 -7.726 -27.113
## compare.md2.fit.residuals - compare.md2.fit.intercepts 0.028 29.158   3.310
## compare.md2.fit.means - compare.md2.fit.residuals      0.007  0.444  -6.019
# モデル3をもとに比較が可能なのでそれに合わせたモデルを組む
out2 <- sem(md2, data = dat, group = "club",
           group.equal = c("loadings","intercepts"))
summary(out2, standardize = T)
## lavaan 0.6.16 ended normally after 56 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        52
##   Number of equality constraints                    14
## 
##   Number of observations per group:                   
##     no                                             119
##     yes                                             68
## 
## Model Test User Model:
##                                                       
##   Test statistic                                92.752
##   Degrees of freedom                                50
##   P-value (Chi-square)                           0.000
##   Test statistic for each group:
##     no                                          38.403
##     yes                                         54.349
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
## 
## 
## Group 1 [no]:
## 
## Latent Variables:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   satis =~                                                              
##     V5                1.000                               0.660    0.630
##     V6      (.p2.)    1.050    0.142    7.389    0.000    0.693    0.688
##     V7      (.p3.)    1.235    0.158    7.831    0.000    0.815    0.756
##     V8      (.p4.)    1.327    0.157    8.456    0.000    0.876    0.848
##   conscious =~                                                          
##     V1                1.000                               0.789    0.865
##     V2      (.p6.)    0.899    0.090    9.953    0.000    0.710    0.747
##     V3      (.p7.)    0.612    0.079    7.701    0.000    0.483    0.616
##     V4      (.p8.)    0.472    0.074    6.360    0.000    0.372    0.514
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   satis ~                                                               
##     conscious         0.726    0.102    7.083    0.000    0.868    0.868
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .V5      (.20.)    4.098    0.088   46.587    0.000    4.098    3.915
##    .V6      (.21.)    3.714    0.086   43.216    0.000    3.714    3.687
##    .V7      (.22.)    3.318    0.095   35.104    0.000    3.318    3.078
##    .V8      (.23.)    3.657    0.093   39.485    0.000    3.657    3.542
##    .V1      (.24.)    3.897    0.083   47.098    0.000    3.897    4.271
##    .V2      (.25.)    3.828    0.084   45.685    0.000    3.828    4.025
##    .V3      (.26.)    4.263    0.068   62.557    0.000    4.263    5.438
##    .V4      (.27.)    4.400    0.061   71.978    0.000    4.400    6.082
##    .satis             0.000                               0.000    0.000
##     conscis           0.000                               0.000    0.000
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .V5                0.660    0.094    7.016    0.000    0.660    0.603
##    .V6                0.535    0.079    6.757    0.000    0.535    0.527
##    .V7                0.497    0.079    6.260    0.000    0.497    0.428
##    .V8                0.299    0.061    4.908    0.000    0.299    0.281
##    .V1                0.210    0.049    4.279    0.000    0.210    0.252
##    .V2                0.400    0.064    6.270    0.000    0.400    0.443
##    .V3                0.381    0.054    7.033    0.000    0.381    0.621
##    .V4                0.385    0.053    7.320    0.000    0.385    0.735
##    .satis             0.107    0.040    2.686    0.007    0.246    0.246
##     conscious         0.623    0.110    5.679    0.000    1.000    1.000
## 
## 
## Group 2 [yes]:
## 
## Latent Variables:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   satis =~                                                              
##     V5                1.000                               0.661    0.582
##     V6      (.p2.)    1.050    0.142    7.389    0.000    0.694    0.646
##     V7      (.p3.)    1.235    0.158    7.831    0.000    0.816    0.669
##     V8      (.p4.)    1.327    0.157    8.456    0.000    0.877    0.804
##   conscious =~                                                          
##     V1                1.000                               0.787    0.722
##     V2      (.p6.)    0.899    0.090    9.953    0.000    0.708    0.659
##     V3      (.p7.)    0.612    0.079    7.701    0.000    0.481    0.443
##     V4      (.p8.)    0.472    0.074    6.360    0.000    0.371    0.395
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   satis ~                                                               
##     conscious         0.649    0.146    4.433    0.000    0.772    0.772
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .V5      (.20.)    4.098    0.088   46.587    0.000    4.098    3.610
##    .V6      (.21.)    3.714    0.086   43.216    0.000    3.714    3.457
##    .V7      (.22.)    3.318    0.095   35.104    0.000    3.318    2.720
##    .V8      (.23.)    3.657    0.093   39.485    0.000    3.657    3.354
##    .V1      (.24.)    3.897    0.083   47.098    0.000    3.897    3.577
##    .V2      (.25.)    3.828    0.084   45.685    0.000    3.828    3.563
##    .V3      (.26.)    4.263    0.068   62.557    0.000    4.263    3.927
##    .V4      (.27.)    4.400    0.061   71.978    0.000    4.400    4.691
##    .satis             0.063    0.097    0.648    0.517    0.095    0.095
##     conscis          -0.293    0.140   -2.094    0.036   -0.372   -0.372
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .V5                0.852    0.162    5.249    0.000    0.852    0.661
##    .V6                0.673    0.134    5.010    0.000    0.673    0.583
##    .V7                0.821    0.167    4.901    0.000    0.821    0.552
##    .V8                0.421    0.114    3.695    0.000    0.421    0.354
##    .V1                0.568    0.140    4.047    0.000    0.568    0.479
##    .V2                0.653    0.142    4.611    0.000    0.653    0.566
##    .V3                0.947    0.173    5.465    0.000    0.947    0.803
##    .V4                0.742    0.134    5.553    0.000    0.742    0.844
##    .satis             0.176    0.079    2.218    0.027    0.404    0.404
##     conscious         0.619    0.168    3.688    0.000    1.000    1.000

7.3 参考:meansEq.syntaxの書き方

meansEq.syntaxを用いれば、より柔軟に制約をかけたモデルを比較できる。

# meansEq.syntaxを用いれば、より柔軟に制約をかけたモデルを比較できる。
option1 <- measEq.syntax(configural.model = md1, 
                         data = dat,
                         group = "club",
                         group.equal = "loadings",
                         return.fit = T)
option2 <- measEq.syntax(configural.model = md1, 
                         data = dat,
                         group = "club",
                         group.equal = c("loadings", "intercepts"),
                         return.fit = T)
summary(compareFit(list(option1, option2)))
## ################### Nested Model Comparison #########################
## 
## Chi-Squared Difference Test
## 
##                          Df    AIC    BIC  Chisq Chisq diff RMSEA Df diff
## list(option1, option2).1  7 2029.4 2097.3 6.8354                         
## list(option1, option2).2 10 2025.0 2083.2 8.4309     1.5954     0       3
##                          Pr(>Chisq)
## list(option1, option2).1           
## list(option1, option2).2     0.6604
## 
## ####################### Model Fit Indices ###########################
##                            chisq df pvalue  rmsea     cfi     tli   srmr
## list(option1, option2).1 6.835†  7   .446 .000† 1.000†  1.001  .026†
## list(option1, option2).2  8.431  10   .587 .000† 1.000† 1.008†  .030 
##                                 aic        bic
## list(option1, option2).1  2029.421   2097.274 
## list(option1, option2).2 2025.017† 2083.177†
## 
## ################## Differences in Fit Indices #######################
##                                                     df rmsea cfi   tli  srmr
## list(option1, option2).2 - list(option1, option2).1  3     0   0 0.007 0.005
##                                                        aic     bic
## list(option1, option2).2 - list(option1, option2).1 -4.405 -14.098

8 カテゴリカル変数を含むSEM

今回のデータの場合にはclubがカテゴリカル変数である。

library(lavaan)
library(semTools)
library(semPlot)

8.1 外生変数の場合

md1 <- "
V3 ~ V1 + V2 + club
"
out1 <- sem(md1, dat)
summary(out1)
## lavaan 0.6.16 ended normally after 1 iteration
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                         4
## 
##   Number of observations                           187
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   V3 ~                                                
##     V1                0.310    0.074    4.195    0.000
##     V2                0.183    0.071    2.564    0.010
##     club             -0.019    0.126   -0.151    0.880
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##    .V3                0.665    0.069    9.670    0.000

8.2 内生変数の場合

md2 <- "
club ~ V1 + V2 + V3
"
out2 <- sem(md2, dat, ordered = "club", link = "logit")
## Warning in lav_options_set(opt): lavaan WARNING: link will be set to "probit"
## for estimator = "DWLS"
summary(out2)
## lavaan 0.6.16 ended normally after 6 iterations
## 
##   Estimator                                       DWLS
##   Optimization method                           NLMINB
##   Number of model parameters                         4
## 
##   Number of observations                           187
## 
## Model Test User Model:
##                                               Standard      Scaled
##   Test Statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
## 
## Parameter Estimates:
## 
##   Standard errors                           Robust.sem
##   Information                                 Expected
##   Information saturated (h1) model        Unstructured
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   club ~                                              
##     V1                0.003    0.110    0.025    0.980
##     V2                0.251    0.109    2.311    0.021
##     V3               -0.020    0.106   -0.184    0.854
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|)
##    .club              0.000                           
## 
## Thresholds:
##                    Estimate  Std.Err  z-value  P(>|z|)
##     club|t1           0.503    0.497    1.012    0.312
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##    .club              1.000                           
## 
## Scales y*:
##                    Estimate  Std.Err  z-value  P(>|z|)
##     club              1.000

9 モデルの改善

まずは例題のモデルを再度計算してみる。

md1 <- "
conscious =~ V1 + V2 + V3 + V4
satis =~ V5 + V6 + V7 + V8
satis ~ conscious
"

out1 <- sem(mode = md1, data = dat)
summary(out1)
## lavaan 0.6.16 ended normally after 26 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        17
## 
##   Number of observations                           187
## 
## Model Test User Model:
##                                                       
##   Test statistic                                63.346
##   Degrees of freedom                                19
##   P-value (Chi-square)                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
## 
## Latent Variables:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   conscious =~                                        
##     V1                1.000                           
##     V2                0.982    0.107    9.153    0.000
##     V3                0.695    0.097    7.171    0.000
##     V4                0.531    0.086    6.173    0.000
##   satis =~                                            
##     V5                1.000                           
##     V6                1.030    0.140    7.368    0.000
##     V7                1.224    0.157    7.796    0.000
##     V8                1.294    0.154    8.403    0.000
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   satis ~                                             
##     conscious         0.750    0.107    7.017    0.000
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##    .V1                0.370    0.057    6.440    0.000
##    .V2                0.480    0.066    7.280    0.000
##    .V3                0.576    0.066    8.701    0.000
##    .V4                0.506    0.056    9.031    0.000
##    .V5                0.721    0.084    8.612    0.000
##    .V6                0.586    0.071    8.281    0.000
##    .V7                0.608    0.078    7.756    0.000
##    .V8                0.359    0.059    6.048    0.000
##     conscious         0.566    0.099    5.737    0.000
##    .satis             0.134    0.043    3.130    0.002

9.1 修正指標

MI <- modificationIndices(out1)
MI[MI$mi >= 3, ] # 大量に出てくるので、修正指標が3以上のものにひとまず絞る
##          lhs op rhs     mi    epc sepc.lv sepc.all sepc.nox
## 20 conscious =~  V5 24.336  1.335   1.005    0.928    0.928
## 23 conscious =~  V8  4.367 -0.587  -0.442   -0.418   -0.418
## 25     satis =~  V2  4.119  0.682   0.459    0.453    0.453
## 27     satis =~  V4  9.183 -0.733  -0.493   -0.605   -0.605
## 37        V2 ~~  V5  4.342  0.107   0.107    0.182    0.182
## 41        V3 ~~  V4 18.064  0.185   0.185    0.344    0.344
## 42        V3 ~~  V5  9.114  0.157   0.157    0.244    0.244
## 46        V4 ~~  V5 10.569  0.156   0.156    0.258    0.258
## 49        V4 ~~  V8 10.505 -0.128  -0.128   -0.300   -0.300
## 50        V5 ~~  V6  4.520 -0.120  -0.120   -0.185   -0.185
## 51        V5 ~~  V7  4.977 -0.135  -0.135   -0.204   -0.204

上記の修正指標の結果に従い、共分散をいくつか入れてみる。

md2 <- "
conscious =~ V1 + V2 + V3 + V4
satis =~ V5 + V6 + V7 + V8
satis ~ conscious
V3 ~~ V4
V4 ~~ V5
V4 ~~ V8
"
out2 <- sem(mode = md2, data = dat)
summary(out2)
## lavaan 0.6.16 ended normally after 27 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        20
## 
##   Number of observations                           187
## 
## Model Test User Model:
##                                                       
##   Test statistic                                33.816
##   Degrees of freedom                                16
##   P-value (Chi-square)                           0.006
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
## 
## Latent Variables:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   conscious =~                                        
##     V1                1.000                           
##     V2                0.983    0.107    9.156    0.000
##     V3                0.647    0.098    6.632    0.000
##     V4                0.477    0.087    5.509    0.000
##   satis =~                                            
##     V5                1.000                           
##     V6                1.034    0.141    7.348    0.000
##     V7                1.227    0.158    7.761    0.000
##     V8                1.307    0.156    8.407    0.000
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   satis ~                                             
##     conscious         0.770    0.110    6.992    0.000
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##  .V3 ~~                                               
##    .V4                0.150    0.046    3.283    0.001
##  .V4 ~~                                               
##    .V5                0.100    0.048    2.092    0.036
##    .V8               -0.079    0.038   -2.087    0.037
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##    .V1                0.370    0.058    6.370    0.000
##    .V2                0.480    0.066    7.254    0.000
##    .V3                0.613    0.069    8.853    0.000
##    .V4                0.512    0.056    9.086    0.000
##    .V5                0.730    0.084    8.664    0.000
##    .V6                0.588    0.070    8.341    0.000
##    .V7                0.613    0.078    7.855    0.000
##    .V8                0.348    0.058    5.984    0.000
##     conscious         0.566    0.099    5.710    0.000
##    .satis             0.112    0.040    2.778    0.005

参考文献

豊田秀樹編,2014,『共分散構造分析[R編]: 構造方程式モデリング』東京図書.