共分散行列を利用5

lavaan、semPlot パッケージ Inkscape

(参考)blue backs「原因をさぐる統計学」
R-SVG.org
SVG画像

図はsvg形式で出力した後、Inkscapeを使って編集。

原因を探る統計学

p.167 競合する3つのモデル 図表 補-5 p.239
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
library(lavaan)
library(semPlot)
mat<-'
1
0.57 1
0.48 0.59 1
0.3 0.3 0.32 1
0.15 0.29 0.3 0.29 1
0.29 0.41 0.35 0.42 0.44 1
0.18 0.33 0.3 0.49 0.46 0.63 1
0.38 0.42 0.37 0.51 0.3 0.45 0.56 1
0.33 0.28 0.3 0.52 0.36 0.37 0.56 0.63 1
0.29 0.36 0.29 0.37 0.21 0.31 0.24 0.28 0.22 1
0.2 0.39 0.29 0.34 0.18 0.39 0.29 0.23 0.24 0.51 1
0.17 0.21 0.15 0.31 0.37 0.29 0.4 0.29 0.4 0.2 0.28 1
'
wheaton.cov <- getCov(mat,names=c("x1","x2","x3","x4","x5","x6","x7","x8","x9","x10","x11","x12"))
sd<-c(0.78, 1.32, 0.83, 1.01, 1.55, 1.36, 1.09, 1.28, 0.7, 0.73, 1.29,1.17)
#共分散行列に変換
full.cov <- lavaan:::cor2cov(wheaton.cov,sd,names=c("x1","x2","x3","x4","x5","x6","x7","x8","x9","x10","x11","x12"))
model1<-'
F1=~x1+x2+x3
F2=~x4
F3=~x5+x6+x7
F4=~x8+x9
F5=~x10+x11
F6=~x12
F1~~F2
F1~~F3
F2~~F3
F4~F1+F2+F3
F5~F1+F2+F4
F6~F4+F5
x4~~0.06*x4
x12~~0.43*x12
'
#F2,F6を測定している観測変数がそれぞれ1つだけ(x4,x12)
#p.171~p.173の図の数値と一致させるには図表 補-5 p.239に記載されている E4=0.06,E12=0.43が必要。
fit <- lavaan:::sem(model1, sample.cov=full.cov, sample.nobs=151)
summary(fit, standardized=TRUE)
manifests<-c("x1","x2","x3","x4","x5","x6","x7","x8","x9","x10","x11","x12")
latents<-c("F1","F2","F3","F4","F5","F6")
labels=c("x1","x2","x3","x4","x5","x6","x7","x8","x9","x10","x11","x12",
"セールスマン\nと顧客の類\n似性","セールスマン\nの専門性","関係を拡げる\nための努力","セールスマン\nと顧客の関係\nの質","これまでの\nセールスの\n実績","将来の継続的\n取引の意志")
svg("graph.svg", family="Takao P明朝", width=12, height=10)
semPaths(fit,"std",fade=F,manifests=manifests,latents=latents,nodeLabels=labels,style="lisrel",gray=T,
edge.label.cex=0.7,esize=TRUE,fixedStyle=c("black",1), freeStyle=c("black",1),layout="tree2")
dev.off()

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
model2<-'
F1=~x1+x2+x3
F2=~x4
F3=~x5+x6+x7
F4=~x8+x9
F5=~x10+x11
F6=~x12
F1~~F2
F1~~F3
F2~~F3
F4~F1+F2+F3
F5~F1+F2
F6~F4+F5
x4~~0.06*x4
x12~~0.43*x12
'
#F2,F6を測定している観測変数がそれぞれ1つだけ(x4,x12)
#p.171~p.173の図の数値と一致させるには図表 補-5 p.239に記載されている E4=0.06,E12=0.43が必要。
fit <- lavaan:::sem(model2, sample.cov=full.cov, sample.nobs=151)
summary(fit, standardized=TRUE)
manifests<-c("x1","x2","x3","x4","x5","x6","x7","x8","x9","x10","x11","x12")
latents<-c("F1","F2","F3","F4","F5","F6")
labels=c("x1","x2","x3","x4","x5","x6","x7","x8","x9","x10","x11","x12",
"セールスマン\nと顧客の類\n似性","セールスマン\nの専門性","関係を拡げる\nための努力","セールスマン\nと顧客の関係\nの質","これまでの\nセールスの\n実績","将来の継続的\n取引の意志")
svg("graph.svg", family="Takao P明朝", width=12, height=10)
semPaths(fit,"std",fade=F,manifests=manifests,latents=latents,nodeLabels=labels,style="lisrel",gray=T,
edge.label.cex=0.7,esize=TRUE,fixedStyle=c("black",1), freeStyle=c("black",1),layout="tree2")
dev.off()

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
model3<-'
F1=~x1+x2+x3
F2=~x4
F3=~x5+x6+x7
F4=~x8+x9
F5=~x10+x11
F6=~x12
F1~~F2
F1~~F3
F2~~F3
F4~F1+F2+F3
F5~F1+F2+F4
F6~F5
x4~~0.06*x4
x12~~0.43*x12
'
#F2,F6を測定している観測変数がそれぞれ1つだけ(x4,x12)
#p.171~p.173の図の数値と一致させるには図表 補-5 p.239に記載されている E4=0.06,E12=0.43が必要。
fit <- lavaan:::sem(model3, sample.cov=full.cov, sample.nobs=151)
summary(fit, standardized=TRUE)
manifests<-c("x1","x2","x3","x4","x5","x6","x7","x8","x9","x10","x11","x12")
latents<-c("F1","F2","F3","F4","F5","F6")
labels=c("x1","x2","x3","x4","x5","x6","x7","x8","x9","x10","x11","x12",
"セールスマン\nと顧客の類\n似性","セールスマン\nの専門性","関係を拡げる\nための努力","セールスマン\nと顧客の関係\nの質","これまでの\nセールスの\n実績","将来の継続的\n取引の意志")
svg("graph.svg", family="Takao P明朝", width=12, height=10)
semPaths(fit,"std",fade=F,manifests=manifests,latents=latents,nodeLabels=labels,style="lisrel",gray=T,
edge.label.cex=0.7,esize=TRUE,fixedStyle=c("black",1), freeStyle=c("black",1),layout="tree2")
dev.off()