#図6-1の分析
#本書の分析に用いたソフトウェア(Mplus)とは異なるため,
#本書とは適合度がわずかに一致しない。
#図6-1のモデルと図6-3のモデルでは,扱っている変数が異なるため,
#欠測を含む標本のサイズも異なる。そのため,2つのモデルで
#標本サイズが1つ異なり,その影響で共分散行列も異なるが,その違いはわずかである。
#以上の理由で,2つのモデルの分析対象は図6-3に対する共分散行列で統一している。
library(lavaan)
#共分散行列の下三角要素の読み込み
lower
<- '
1.064,
0.515,1.006,
0.663,0.591,1.16,
0.525,0.573,0.711,1.067,
0.391,0.41,0.375,0.388,0.976,
0.044,0.125,-0.025,0.019,0.092,0.585,
-0.03,0.165,-0.003,0.07,0.146,0.195,1.413,
-0.003,0.11,-0.017,-0.01,0.08,0.334,0.474,1.052,
0.099,0.215,0.065,0.135,0.148,0.282,0.523,0.467,1.317,
0.066,0.163,0.092,0.089,0.163,0.284,0.423,0.412,0.591,1.14,
-0.036,0.03,-0.012,0.03,0.044,0.117,0.128,0.157,0.117,0.09,0.489,
0.022,0.04,0.072,0.074,0.01,0.118,0.214,0.135,0.212,0.175,0.039,1.093,
0.012,0.058,0.075,0.081,0.013,0.107,0.223,0.116,0.219,0.198,0.033,0.571,1.259,
0.134,0.217,0.084,0.125,0.146,0.134,0.248,0.155,0.259,0.249,0.094,0.162,0.102,0.718,
0.126,0.198,0.088,0.128,0.196,0.236,0.34,0.332,0.393,0.356,0.123,0.268,0.191,0.371,1.069,
0.099,0.219,0.075,0.124,0.158,0.208,0.229,0.254,0.406,0.318,0.127,0.228,0.205,0.345,0.611,0.957,
0.219,0.266,0.155,0.146,0.203,0.216,0.221,0.262,0.387,0.285,0.162,0.178,0.131,0.3,0.487,0.568,0.908,
0.093,0.169,0.061,0.078,0.174,0.177,0.309,0.243,0.363,0.312,0.139,0.229,0.196,0.349,0.562,0.614,0.47,1.031'
#共分散行列の作成
dep6.cov
<-
getCov(lower,names=c("harm1","harm2","harm3","harm4","harm5","friend1","friend2","friend3","friend4","friend5","parent1","parent2","parent3","dep1","dep2","dep3","dep4","dep5"))
#モデルの指定(図6-1)
model.fig6.1
<- '
f1
=~ 1*harm1+harm2+harm3+harm4+harm5
f2
=~ 1*friend1+friend2+friend3+friend4+friend5
f3
=~ 1*dep1+dep2+dep3+dep4+dep5
f3
~ f1+f2
'
#auto.var=TRUEで,観測変数の誤差分散と潜在変数の分散を推定する
#auto.cov.lv.x=TRUEで,外生的な潜在変数間の共分散を推定する
fit.fig6.1
<- lavaan(model.fig6.1, auto.var=TRUE, auto.cov.lv.x=TRUE,
sample.cov=dep6.cov, sample.nobs=515)
summary(fit.fig6.1,
standardized=T, rsquare=T, fit.measures=TRUE)
#====================================================
#図6-3の分析
#本書の分析に用いたソフトウェア(Mplus)とは異なるため,
#標準誤差が求まらなかったり,本書の推定値と一致していないところがある。
#図6-1のモデルと図6-3のモデルでは,扱っている変数が異なるため,
#欠測を含む標本のサイズも異なる。そのため,2つのモデルで
#標本サイズが1つ異なり,その影響で共分散行列も異なるが,その違いはわずかである。
#以上の理由で,2つのモデルの分析対象は図6-3に対する共分散行列で統一している。
library(lavaan)
#共分散行列の下三角要素の読み込み
lower
<- '
1.064,
0.515,1.006,
0.663,0.591,1.16,
0.525,0.573,0.711,1.067,
0.391,0.41,0.375,0.388,0.976,
0.044,0.125,-0.025,0.019,0.092,0.585,
-0.03,0.165,-0.003,0.07,0.146,0.195,1.413,
-0.003,0.11,-0.017,-0.01,0.08,0.334,0.474,1.052,
0.099,0.215,0.065,0.135,0.148,0.282,0.523,0.467,1.317,
0.066,0.163,0.092,0.089,0.163,0.284,0.423,0.412,0.591,1.14,
-0.036,0.03,-0.012,0.03,0.044,0.117,0.128,0.157,0.117,0.09,0.489,
0.022,0.04,0.072,0.074,0.01,0.118,0.214,0.135,0.212,0.175,0.039,1.093,
0.012,0.058,0.075,0.081,0.013,0.107,0.223,0.116,0.219,0.198,0.033,0.571,1.259,
0.134,0.217,0.084,0.125,0.146,0.134,0.248,0.155,0.259,0.249,0.094,0.162,0.102,0.718,
0.126,0.198,0.088,0.128,0.196,0.236,0.34,0.332,0.393,0.356,0.123,0.268,0.191,0.371,1.069,
0.099,0.219,0.075,0.124,0.158,0.208,0.229,0.254,0.406,0.318,0.127,0.228,0.205,0.345,0.611,0.957,
0.219,0.266,0.155,0.146,0.203,0.216,0.221,0.262,0.387,0.285,0.162,0.178,0.131,0.3,0.487,0.568,0.908,
0.093,0.169,0.061,0.078,0.174,0.177,0.309,0.243,0.363,0.312,0.139,0.229,0.196,0.349,0.562,0.614,0.47,1.031'
#共分散行列の作成
dep6.cov
<-
getCov(lower,names=c("harm1","harm2","harm3","harm4","harm5","friend1","friend2","friend3","friend4","friend5","parent1","parent2","parent3","dep1","dep2","dep3","dep4","dep5"))
#モデルの指定(図6-3)
model.fig6.3
<- '
f1
=~ 1*harm1+harm2+harm3+harm4+harm5
f2
=~ 1*friend1+friend2+friend3+friend4+friend5
f3
=~ 1*parent1+parent2+parent3
f4
=~ 1*dep1+dep2+dep3+dep4+dep5
f4
~ f1+f2+f3
f2
~ f1
f3
~ f1
f1
~~ f2
'
#auto.var=TRUEで,観測変数の誤差分散と潜在変数の分散を推定する
fit.fig6.3
<- lavaan(model.fig6.3, auto.var=TRUE, sample.cov=dep6.cov, sample.nobs=514)
summary(fit.fig6.3,
standardized=T, rsquare=T, fit.measures=TRUE)
#====================================================
#図6-5の分析(バージョン1)
#平均構造を含まないモデル
#本書の数値と一致しない
library(lavaan)
#変数名
varnames<-c("friend1","friend2","friend3","friend4","friend5","dep1","dep2","dep3","dep4","dep5")
#高群の共分散行列の下三角要素の読み込み
high
<- '
0.785,
0.232,1.62,
0.456,0.528,1.281,
0.398,0.671,0.612,1.513,
0.411,0.495,0.536,0.749,1.428,
0.181,0.303,0.201,0.287,0.271,0.74,
0.306,0.41,0.44,0.473,0.458,0.417,1.131,
0.267,0.346,0.349,0.468,0.408,0.427,0.693,1.128,
0.307,0.334,0.359,0.436,0.345,0.367,0.564,0.644,1.105,
0.223,0.42,0.302,0.423,0.367,0.435,0.662,0.763,0.549,1.174'
#高群の共分散行列の作成
high.cov
<- getCov(high,names=varnames)
#低群の共分散行列の下三角要素の読み込み
low
<- '
0.344,
0.113,1.156,
0.175,0.385,0.793,
0.096,0.304,0.261,1.014,
0.096,0.291,0.235,0.336,0.77,
0.016,0.117,0.051,0.122,0.13,0.566,
0.081,0.184,0.149,0.176,0.135,0.189,0.842,
0.07,0.034,0.092,0.22,0.118,0.123,0.373,0.63,
0.036,0.018,0.09,0.197,0.102,0.079,0.236,0.323,0.526,
0.059,0.122,0.12,0.185,0.154,0.147,0.317,0.335,0.243,0.763'
#低群の共分散行列の作成
low.cov
<- getCov(low,names=varnames)
#各群の標本サイズの指定
N<-list(highG=258,
lowG=254)
#各群の共分散行列をまとめる
full.cov<-list(highG=high.cov,
lowG=low.cov)
#等値ありモデルの指定(図6-5)
model.fig6.5
<- '
f1
=~ 1*friend1+friend2+friend3+friend4+friend5
f2
=~ 1*dep1+dep2+dep3+dep4+dep5
f2
~ c(a,a)*f1
'
#auto.var=TRUEで,観測変数の誤差分散と潜在変数の分散を推定する
fit.fig6.5
<- lavaan(model.fig6.5, auto.var=TRUE, sample.cov=full.cov, sample.nobs=N,
group.equal=c("loadings"))
summary(fit.fig6.5,
standardized=T, rsquare=T, fit.measures=TRUE)
#等値なしモデルの指定(図6-5)
model.fig6.5
<- '
f1
=~ 1*friend1+friend2+friend3+friend4+friend5
f2
=~ 1*dep1+dep2+dep3+dep4+dep5
f2
~ c(ahigh,alow)*f1
'
#auto.var=TRUEで,観測変数の誤差分散と潜在変数の分散を推定する
fit.fig6.5
<- lavaan(model.fig6.5, auto.var=TRUE, sample.cov=full.cov, sample.nobs=N,
group.equal=c("loadings"))
summary(fit.fig6.5,
standardized=T, rsquare=T, fit.measures=TRUE)
#====================================================
#図6-5の分析(バージョン2)
#平均構造を含めた場合のプログラム
#本書の数値と一致する
library(lavaan)
#変数名
varnames<-c("friend1","friend2","friend3","friend4","friend5","dep1","dep2","dep3","dep4","dep5")
#高群の共分散行列の下三角要素の読み込み
high
<- '
0.785,
0.232,1.62,
0.456,0.528,1.281,
0.398,0.671,0.612,1.513,
0.411,0.495,0.536,0.749,1.428,
0.181,0.303,0.201,0.287,0.271,0.74,
0.306,0.41,0.44,0.473,0.458,0.417,1.131,
0.267,0.346,0.349,0.468,0.408,0.427,0.693,1.128,
0.307,0.334,0.359,0.436,0.345,0.367,0.564,0.644,1.105,
0.223,0.42,0.302,0.423,0.367,0.435,0.662,0.763,0.549,1.174'
#高群の平均ベクトルの読み込み
high.means<-c(0.492,0.992,0.624,1.050,0.818,1.616,1.450,1.174,1.109,1.225)
#高群の共分散行列の作成
high.cov
<- getCov(high,names=varnames)
#低群の共分散行列の下三角要素の読み込み
low
<- '
0.344,
0.113,1.156,
0.175,0.385,0.793,
0.096,0.304,0.261,1.014,
0.096,0.291,0.235,0.336,0.77,
0.016,0.117,0.051,0.122,0.13,0.566,
0.081,0.184,0.149,0.176,0.135,0.189,0.842,
0.07,0.034,0.092,0.22,0.118,0.123,0.373,0.63,
0.036,0.018,0.09,0.197,0.102,0.079,0.236,0.323,0.526,
0.059,0.122,0.12,0.185,0.154,0.147,0.317,0.335,0.243,0.763'
#低群の平均ベクトルの読み込み
low.means<-c(0.205,0.677,0.374,0.587,0.413,1.094,0.874,0.618,0.496,0.732)
#低群の共分散行列の作成
low.cov
<- getCov(low,names=varnames)
#各群の標本サイズの指定
N<-list(highG=258,
lowG=254)
#各群の共分散行列をまとめる
full.cov<-list(highG=high.cov,
lowG=low.cov)
#各群の平均ベクトルをまとめる
full.means<-list(highG=high.means,
lowG=low.means)
#等値ありモデルの指定(図6-5)
model.fig6.5
<- '
f1
=~ 1*friend1+friend2+friend3+friend4+friend5
f2
=~ 1*dep1+dep2+dep3+dep4+dep5
f2
~ c(a,a)*f1
friend1
~ c1*1
friend2
~ c2*1
friend3
~ c3*1
friend4
~ c4*1
friend5
~ c5*1
dep1
~ c6*1
dep2
~ c7*1
dep3
~ c8*1
dep4
~ c9*1
dep5
~ c10*1
f1
~c(fm1h, fm1l)*1
fm1l==0
'
#auto.var=TRUEで,観測変数の誤差分散と潜在変数の分散を推定する
fit.fig6.5
<- lavaan(model.fig6.5, auto.var=TRUE, sample.cov=full.cov,
sample.mean=full.means, sample.nobs=N, group.equal=c("loadings",
"intercepts"))
summary(fit.fig6.5,
standardized=T, rsquare=T, fit.measures=TRUE)
#等値なしモデルの指定(図6-5)
model.fig6.5
<- '
f1
=~ 1*friend1+friend2+friend3+friend4+friend5
f2
=~ 1*dep1+dep2+dep3+dep4+dep5
f2
~ c(ahigh,alow)*f1
friend1
~ c1*1
friend2
~ c2*1
friend3
~ c3*1
friend4
~ c4*1
friend5
~ c5*1
dep1
~ c6*1
dep2
~ c7*1
dep3
~ c8*1
dep4
~ c9*1
dep5
~ c10*1
f1
~c(fm1h, fm1l)*1
fm1l==0
'
#auto.var=TRUEで,観測変数の誤差分散と潜在変数の分散を推定する
fit.fig6.5
<- lavaan(model.fig6.5, auto.var=TRUE, sample.cov=full.cov,
sample.mean=full.means, sample.nobs=N, group.equal=c("loadings",
"intercepts"))
summary(fit.fig6.5,
standardized=T, rsquare=T, fit.measures=TRUE)
#====================================================
#2014.09.22 尾崎幸謙・荘島宏二郎