奥村太一先生の資料をもとに学習したものです。

data01 <- read.csv("path.csv",header=T)
head(data01, n=3)
gakuryoku ict ses kyomi oya
90 63 13 15 17
70 35 11 12 6
48 22 9 18 12
cor(data01)
##             gakuryoku       ict         ses      kyomi        oya
## gakuryoku  1.00000000 0.1233890 -0.01299692 0.30491146 0.07625496
## ict        0.12338902 1.0000000  0.21546595 0.19848925 0.26132689
## ses       -0.01299692 0.2154659  1.00000000 0.08931247 0.26962953
## kyomi      0.30491146 0.1984892  0.08931247 1.00000000 0.18238574
## oya        0.07625496 0.2613269  0.26962953 0.18238574 1.00000000
#cov01 <- cov(data01)
attach(data01)
model01 <-  '
  gakuryoku ~ kyomi + ict
  kyomi     ~ oya   + ict
  ict       ~ ses  '
  
sem01 <- sem(model01, data = data01, estimator = "ML")
sem01
## lavaan 0.6.15 ended normally after 1 iteration
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                         8
## 
##   Number of observations                           200
## 
## Model Test User Model:
##                                                       
##   Test statistic                                10.370
##   Degrees of freedom                                 4
##   P-value (Chi-square)                           0.035

0.0.1 標準化解

whatLabels = “stand”でパス係数は標準化解 目的変数の右の数値は誤差分散.

semPaths(sem01, what = "stand", style = "lisrel", layout = "tree", rotation = 2, nCharNodes = 0, nCharEdges = 0, fade = FALSE, optimizeLatRes = TRUE, edge.width = 0.2, label.scale = FALSE, label.cex = 0.5, theme = 'gray', asize = 6.0, node.width = 1.5)

0.0.2 非標準化解.

whatLabels = “est”でパス係数は非標準化解 目的変数の右の数値は誤差分散.

semPaths(sem01, what = "est", style = "lisrel", layout = "tree", rotation = 2, nCharNodes = 0, nCharEdges = 0, fade = FALSE, optimizeLatRes = TRUE, edge.width = 0.2, label.scale = FALSE, label.cex = 0.6, theme = 'gray', asize = 6.0, node.width = 1.5)

0.0.3 回帰係数との関係.

非標準化解のパス係数は偏回帰係数と一致

model.kyomi <- lm(gakuryoku ~ kyomi+ict, data = data01)
model.kyomi$coef
## (Intercept)       kyomi         ict 
## 45.24228859  1.16161564  0.06423574
model.ses <- lm(ict ~ ses, data = data01)
summary(model.ses)
## 
## Call:
## lm(formula = ict ~ ses, data = data01)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -47.647 -14.171  -0.143  11.888  51.238 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  36.2577     3.1571  11.484  < 2e-16 ***
## ses           0.8761     0.2822   3.105  0.00218 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 19.46 on 198 degrees of freedom
## Multiple R-squared:  0.04643,    Adjusted R-squared:  0.04161 
## F-statistic:  9.64 on 1 and 198 DF,  p-value: 0.002183
model.ses$coef
## (Intercept)         ses 
##  36.2576582   0.8761015

0.0.4 データを標準化

d <- data.frame(scale(data01[1:5]))
attach(d)
## The following objects are masked from data01:
## 
##     gakuryoku, ict, kyomi, oya, ses
model.kyomi <- lm(gakuryoku ~ kyomi+ict, data = d)
model.kyomi$coef
##  (Intercept)        kyomi          ict 
## 1.874986e-16 2.919212e-01 6.544580e-02
model.ses <- lm(ict ~ ses, data = d)
summary(model.ses)
## 
## Call:
## lm(formula = ict ~ ses, data = d)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -2.39723 -0.71299 -0.00717  0.59813  2.57790 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)   
## (Intercept) 1.335e-16  6.922e-02   0.000  1.00000   
## ses         2.155e-01  6.940e-02   3.105  0.00218 **
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.979 on 198 degrees of freedom
## Multiple R-squared:  0.04643,    Adjusted R-squared:  0.04161 
## F-statistic:  9.64 on 1 and 198 DF,  p-value: 0.002183
model.ses$coef
##  (Intercept)          ses 
## 1.334674e-16 2.154659e-01