# 因子分析，共分散構造分析 Factor Analysis Structural Equations Model

## Presentation on theme: "因子分析，共分散構造分析 Factor Analysis Structural Equations Model"— Presentation transcript:

主成分分析 Principal Components 第17章　共分散構造分析 Structural Equations Model (SEM) 1

(1) SEM (Structual Equations Model) From Package Menu 　メニューから Select a Mirror Site　CRANミラーサイト指定 Install the package　　プルダウンから選ぶ Type from Command Line コマンドラインから install.packages("sem") Make a Library in the Package Effective パッケージ内のライブラリーを有効にする library(sem)

(2) Lavaan (latent variable analysis) From Package Menu 　メニューから Select a Mirror Site　CRANミラーサイト指定 Type from Command Line コマンドラインから install.packages(c("lavaan", "psych", "qgraph")) Make a Library in the Package Effective library(lavaan) library(psych) library(qgraph)

# p312 specify the correlation coefficient matrix (as lower triangular matrix) coopd<- readMoments(names=c( "y1","y2","y3","y4","y5","y6","y7","y8","y9","y10","y11","y12")) 1.0

# p312 specify the correlation coefficient matrix (without diagonal values) coopd <- readMoments (diag=FALSE,names=as.character(paste("y",1:12, sep=""))) .160

SEMpackege Description of Equations 方程式の記述
model.coop <- specifyModel() mother -> y1, b11, NA mother-> y2, b21, NA mother-> y3, b31, NA mother-> y4, b41, NA interaction-> y5, NA, 1 interaction-> y6, b62, NA interaction-> y7, b72, NA interaction-> y8, b82, NA cooperative -> y9, NA, 1 cooperative -> y10, b103, NA cooperative -> y11, b113, NA cooperative -> y12, b123, NA mother-> interaction, g21, NA mother-> cooperative, g31, NA y1 <-> y1, e1, NA y2 <-> y2, e2, NA y3 <-> y3, e3, NA y4 <-> y4, e4, NA y5 <-> y5, e5, NA y6 <-> y6, e6, NA y7 <-> y7, e7, NA y8 <-> y8, e8, NA y9 <-> y9, e9, NA y10 <-> y10, e10, NA y11 <-> y11, e11, NA y12 <-> y12, e12, NA mother<-> mother, NA, 1 interaction<-> interaction, delta2, NA cooperative <-> cooperative, delta3, NA

Description of Relations(係数の記述) 変数　－＞　影響先,推定母数，固定母数 variable -> variable , estimated, fixed
model.coop <- specifyModel() mother -> y1, b11, NA mother-> y2, b21, NA mother-> y3, b31, NA mother-> y4, b41, NA interaction-> y5, NA, 1 interaction-> y6, b62, NA interaction-> y7, b72, NA interaction-> y8, b82, NA cooperative -> y9, NA, 1 cooperative -> y10, b103, NA cooperative -> y11, b113, NA cooperative -> y12, b123, NA mother-> interaction, g21, NA mother-> cooperative, g31, NA

Descrition of Variances(分散の記述) 内生変数の分散(変数<->変数),推定母数,固定母数 Variance of Endogenous Variables variable <-> variable, estimated parameter, fixed param. y1 <-> y1, e1, NA y2 <-> y2, e2, NA y3 <-> y3, e3, NA y4 <-> y4, e4, NA y5 <-> y5, e5, NA y6 <-> y6, e6, NA y7 <-> y7, e7, NA y8 <-> y8, e8, NA y9 <-> y9, e9, NA y10 <-> y10, e10, NA y11 <-> y11, e11, NA y12 <-> y12, e12, NA mother<-> mother, NA, 1 interaction<-> interaction, delta2, NA cooperative <-> cooperative, delta3, NA

SEM Package 推定母数の計算 sem(モデル名,相関係数行列，データ数)
sem.coop <- sem(model.coop, coopd, N=50) 推定結果の表示 Show the result stdCoef(sem.coop) summary(sem.coop)

SEM Package 標準化解 15 e1 0.81523858 y1 <--> y1
stdCoef(sem.coop, digit=4) Std. Estimate 1 b y1 <--- mother 2 b y2 <--- mother 3 b y3 <--- mother 4 b y4 <--- mother y5 <--- interaction 6 b y6 <--- interaction 7 b y7 <--- interaction 8 b y8 <--- interaction y9 <--- cooperative 10 b y10 <--- cooperative 11 b y11 <--- cooperative 12 b y12 <--- cooperative 13 g interaction <--- mother 14 g cooperative <--- mother e y1 <--> y1 e y2 <--> y2 e y3 <--> y3 e y4 <--> y4 e y5 <--> y5 e y6 <--> y6 e y7 <--> y7 e y8 <--> y8 e y9 <--> y9 24 e y10 <--> y10 25 e y11 <--> y11 26 e y12 <--> y12 mother <--> mother 28 delta interaction <--> interaction 29 delta cooperative <--> cooperative

summary(sem.coop) Model Chisquare = Df = 52 Pr(>Chisq) = Chisquare (null model) = Df = 66 Goodness-of-fit index = Adjusted goodness-of-fit index = RMSEA index = % CI: ( , ) Bentler-Bonnett NFI = Tucker-Lewis NNFI = Bentler CFI = SRMR = AIC = AICc = BIC = CAIC = Normalized Residuals Min. 1st Qu. Median Mean 3rd Qu. Max. R-square for Endogenous Variables y y y y4 interaction y5 y y y8 cooperative y y10 y y12 Parameter Estimates Estimate Std Error z value Pr(>|z|) b e-03 y1 <--- mother b e-03 y2 <--- mother b e-09 y3 <--- mother b e-04 y4 <--- mother b e-11 y6 <--- interaction b e-09 y7 <--- interaction b e-18 y8 <--- interaction b e-03 y10 <--- cooperative b e-03 y11 <--- cooperative b e-03 y12 <--- cooperative g e-06 interaction <--- mother g e-03 cooperative <--- mother e e-06 y1 <--> y1 e e-06 y2 <--> y2 e e-03 y3 <--> y3 e e-06 y4 <--> y4 e e-05 y5 <--> y5 e e-05 y6 <--> y6 e e-06 y7 <--> y7 e e-01 y8 <--> y8 e e-05 y9 <--> y9 e e-05 y10 <--> y10 e e-04 y11 <--> y11 e e-05 y12 <--> y12 delta e-03 interaction <--> interaction delta e-01 cooperative <--> cooperative Iterations = 48

pathDiagram(sem. coop, ignore. double=FALSE, edge
pathDiagram(sem.coop, ignore.double=FALSE, edge.labels="values", digits=3) > pathDiagram(sem.coop, ignore.double=FALSE, edge.labels="values", digits=3) digraph "sem.coop" { rankdir=LR; size="8,8"; node [fontname="Helvetica" fontsize=14 shape=box]; edge [fontname="Helvetica" fontsize=10]; center=1; "interaction" [shape=ellipse] "cooperative" [shape=ellipse] "mother" [shape=ellipse] "mother" -> "y1" [label="0.43"]; "mother" -> "y2" [label="0.488"]; "mother" -> "y3" [label="0.799"]; "mother" -> "y4" [label="0.521"]; "interaction" -> "y5" [label="1"]; "interaction" -> "y6" [label="0.937"]; "interaction" -> "y7" [label="0.858"]; "interaction" -> "y8" [label="1.138"]; "cooperative" -> "y9" [label="1"]; "cooperative" -> "y10" [label="1.155"]; "cooperative" -> "y11" [label="1.239"]; "cooperative" -> "y12" [label="1.097"]; "mother" -> "interaction" [label="0.597"]; "mother" -> "cooperative" [label="0.39"]; "y1" -> "y1" [label="0.815" dir=both]; "y2" -> "y2" [label="0.762" dir=both]; "y3" -> "y3" [label="0.361" dir=both]; "y4" -> "y4" [label="0.729" dir=both]; "y5" -> "y5" [label="0.298" dir=both]; "y6" -> "y6" [label="0.383" dir=both]; "y7" -> "y7" [label="0.484" dir=both]; "y8" -> "y8" [label="0.091" dir=both]; "y9" -> "y9" [label="0.708" dir=both]; "y10" -> "y10" [label="0.61" dir=both]; "y11" -> "y11" [label="0.552" dir=both]; "y12" -> "y12" [label="0.649" dir=both]; "mother" -> "mother" [label="1" dir=both]; "interaction" -> "interaction" [label="0.345" dir=both]; "cooperative" -> "cooperative" [label="0.14" dir=both]; } >

lavaan packege Description of Equations 方程式の記述
model.cooplv <- ' mother =~ y1+y2+y3+y4 interaction =~ y5+y6+y7+y8 cooperative =~ y9+y10+y11+y12 interaction ~ mother cooperative ~ mother ' {lavaan}パッケージでは以下のような記号の使い方をしています。 =~ 測定方程式 ~ 　構造程式（回帰） ~~ 残差の共分散（相関）

lavaan Package Estimation
result2 <- sem(model.cooplv,sample.cov=coopd, sample.nobs=50) summary(result2, fit.measures=TRUE, standardized=TRUE)

Estimated result from Lavaan
summary(result2) lavaan (0.5-11) converged normally after 45 iterations Number of observations 50 Estimator ML Minimum Function Test Statistic Degrees of freedom 51 P-value (Chi-square) Parameter estimates: Information Expected Standard Errors Standard Estimate Std.err Z-value P(>|z|) Latent variables: mother =~ y y y y interaction =~ y y y y cooperative =~ y y y y Regressions: interaction ~ mother cooperative ~ mother Covariances: interaction ~~ cooperative

Estimated result from Lavaan
diagram(result2, errors=TRUE, lr=FALSE) Variances: y y y y y y y y y y y y mother interaction cooperative

Estimated result from Lavaan