今回も前回の続きlavaanパッケージのinspect関数についてである。
たくさんあるな中で、利用頻度の高そうな初期値、モデル相関行列、決定係数について求め方を書いた。
https://lavaan.ugent.be/tutorial/inspect.htmllavaan.ugent.be
前準備
まずは適当に使ったモデルオブジェクトfitに格納しておく。
library(lavaan)
model <- '
# measurement model
ind60 =~ x1 + x2 + x3
dem60 =~ y1 + y2 + y3 + y4
# regressions
dem60 ~ ind60
'
fit <- sem(model=model, data=PoliticalDemocracy, estimator="ML")
最適化計算の初期値
最適化計算はモデルの当てはまりが良くなるまで繰り返し計算をする。基準をクリアした時にその値を推定値とする。この計算が最適化計算である。
inspect(fit, what="start")
出力。
$lambda
ind60 dem60
x1 1.000 0.000
x2 2.193 0.000
x3 1.824 0.000
y1 0.000 1.000
y2 0.000 1.296
y3 0.000 1.055
y4 0.000 1.294
$theta
x1 x2 x3 y1 y2 y3 y4
x1 0.265
x2 0.000 1.126
x3 0.000 0.000 0.975
y1 0.000 0.000 0.000 3.393
y2 0.000 0.000 0.000 0.000 7.686
y3 0.000 0.000 0.000 0.000 0.000 5.310
y4 0.000 0.000 0.000 0.000 0.000 0.000 5.535
$psi
ind60 dem60
ind60 0.05
dem60 0.00 0.05
$beta
ind60 dem60
ind60 0 0
dem60 0 0
sem()やlavaan()は推定法は最尤法がデフォルトであり、推定法を指定しない限り、潜在変数の分散は0.05,観測変数の誤差分散は観測変数の分散の1/2,他のすべての母数はOを初期値となつている。因子負荷の初期値は2段階最小2乗推定法である。
モデルの相関行列
モデルの相関行列を示すのは"cor.all"である。観測変数と潜在変数の両方のモデル化された相関行列を出力する。
inspect(fit, what="cor.all")
モデルの分散共分散行列は下記。
inspect(fit, what="cov.all")
いずれも、標本の行列と近い方がモデルのフィッテングがよいことを意味している。
決定係数R二乗
標本データとモデルによる予測値が近い方がモデルのフィッテングがよいことを意味している。その指標として重相関係数が利用される。この相関係数を二乗した値が決定係数である。
inspect(fit, what="rsquare")
このように各変数に対するR二乗が出力される。
x1 x2 x3 y1 y2 y3 y4 dem60 0.846 0.947 0.761 0.646 0.574 0.495 0.807 0.212
普段使うsummary()にR二乗値を同時に出力するにはrsquare=TRUEというオプションを設定すればよい。
summary(fit, rsquare=TRUE)
結果。
lavaan 0.6-6 ended normally after 41 iterations
Estimator ML
Optimization method NLMINB
Number of free parameters 15
Number of observations 75
Model Test User Model:
Test statistic 23.738
Degrees of freedom 13
P-value (Chi-square) 0.034
Parameter Estimates:
Standard errors Standard
Information Expected
Information saturated (h1) model Structured
Latent Variables:
Estimate Std.Err z-value P(>|z|)
ind60 =~
x1 1.000
x2 2.180 0.139 15.633 0.000
x3 1.818 0.152 11.966 0.000
dem60 =~
y1 1.000
y2 1.419 0.203 7.005 0.000
y3 1.095 0.171 6.396 0.000
y4 1.428 0.171 8.341 0.000
Regressions:
Estimate Std.Err z-value P(>|z|)
dem60 ~
ind60 1.439 0.379 3.801 0.000
Variances:
Estimate Std.Err z-value P(>|z|)
.x1 0.081 0.020 4.123 0.000
.x2 0.120 0.072 1.676 0.094
.x3 0.467 0.091 5.153 0.000
.y1 2.404 0.516 4.663 0.000
.y2 6.552 1.289 5.082 0.000
.y3 5.363 0.996 5.384 0.000
.y4 2.137 0.719 2.973 0.003
ind60 0.449 0.087 5.170 0.000
.dem60 3.453 0.875 3.947 0.000
R-Square:
Estimate
x1 0.846
x2 0.947
x3 0.761
y1 0.646
y2 0.574
y3 0.495
y4 0.807
dem60 0.212