구조모형(structural model) 혹인 인과모형(causal model)이라 불리는데, 그 이유는 원인이 되는 예측변수와 결과가 되는 결과변수의 관계를 추정하기 때문이다. 한가지 주의점은 인과관계라고 주장할 수 있는 이유는 연구자의 연구설계에 의해 정당화되는 것이다. ***
### 패키지 불러오기
library(lavaan)
## Warning: package 'lavaan' was built under R version 3.4.4
## This is lavaan 0.5-23.1097
## lavaan is BETA software! Please report any bugs.
library(data.table)
## Warning: package 'data.table' was built under R version 3.4.2
library(QuantPsyc)
## Warning: package 'QuantPsyc' was built under R version 3.4.4
## Loading required package: boot
## Loading required package: MASS
## Warning: package 'MASS' was built under R version 3.4.1
##
## Attaching package: 'QuantPsyc'
## The following object is masked from 'package:base':
##
## norm
library(systemfit)
## Warning: package 'systemfit' was built under R version 3.4.4
## Loading required package: Matrix
## Loading required package: car
## Warning: package 'car' was built under R version 3.4.1
##
## Attaching package: 'car'
## The following object is masked from 'package:boot':
##
## logit
## Loading required package: lmtest
## Warning: package 'lmtest' was built under R version 3.4.1
## Loading required package: zoo
##
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
##
## Please cite the 'systemfit' package as:
## Arne Henningsen and Jeff D. Hamann (2007). systemfit: A Package for Estimating Systems of Simultaneous Equations in R. Journal of Statistical Software 23(4), 1-40. http://www.jstatsoft.org/v23/i04/.
##
## If you have questions, suggestions, or comments regarding the 'systemfit' package, please use a forum or 'tracker' at systemfit's R-Forge site:
## https://r-forge.r-project.org/projects/systemfit/
### 파일불러오기
pm <- fread("pathmodel.csv")
mycor <- cor(pm)
mymean <- apply(pm,2,mean)
mysd <- apply(pm,2, sd)
### 다중회귀분석의 경우
myols <- lm(v4~v1+v2+v3, data=pm)
summary(myols)
##
## Call:
## lm(formula = v4 ~ v1 + v2 + v3, data = pm)
##
## Residuals:
## Min 1Q Median 3Q Max
## -2.36903 -0.64324 -0.02091 0.57418 2.49146
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1.57020 0.31403 5.000 1.08e-06 ***
## v1 0.05008 0.06795 0.737 0.4618
## v2 0.36965 0.06192 5.970 8.11e-09 ***
## v3 0.16308 0.06634 2.458 0.0146 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.8957 on 250 degrees of freedom
## Multiple R-squared: 0.2143, Adjusted R-squared: 0.2048
## F-statistic: 22.72 on 3 and 250 DF, p-value: 4.824e-13
### myols 표준화계수
# install.packages("QuantPsyc")
lm.beta(myols)
## v1 v2 v3
## 0.04852476 0.37078595 0.15242990
### 구조방정식을 이용한 회귀분석
mypml <- " v4 ~ v1+v2+v3
v1~~v1; v2~~v2; v3~~v3
v1~~v2; v1~~v3; v2~~v3
v4~~v4"
obj.mypml <- sem(mypml, fixed.x=F, data=pm)
summary(obj.mypml, fit.measure=TRUE, standardized=TRUE, rsquare=TRUE)
## lavaan (0.5-23.1097) converged normally after 22 iterations
##
## Number of observations 254
##
## Estimator ML
## Minimum Function Test Statistic 0.000
## Degrees of freedom 0
## Minimum Function Value 0.0000000000000
##
## Model test baseline model:
##
## Minimum Function Test Statistic 161.404
## Degrees of freedom 6
## P-value 0.000
##
## User model versus baseline model:
##
## Comparative Fit Index (CFI) 1.000
## Tucker-Lewis Index (TLI) 1.000
##
## Loglikelihood and Information Criteria:
##
## Loglikelihood user model (H0) -1339.027
## Loglikelihood unrestricted model (H1) -1339.027
##
## Number of free parameters 10
## Akaike (AIC) 2698.054
## Bayesian (BIC) 2733.428
## Sample-size adjusted Bayesian (BIC) 2701.726
##
## Root Mean Square Error of Approximation:
##
## RMSEA 0.000
## 90 Percent Confidence Interval 0.000 0.000
## P-value RMSEA <= 0.05 NA
##
## Standardized Root Mean Square Residual:
##
## SRMR 0.000
##
## Parameter Estimates:
##
## Information Expected
## Standard Errors Standard
##
## Regressions:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## v4 ~
## v1 0.050 0.067 0.743 0.458 0.050 0.049
## v2 0.370 0.061 6.017 0.000 0.370 0.371
## v3 0.163 0.066 2.478 0.013 0.163 0.152
##
## Covariances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## v1 ~~
## v2 0.409 0.066 6.154 0.000 0.409 0.419
## v3 0.378 0.062 6.113 0.000 0.378 0.415
## v2 ~~
## v3 0.250 0.061 4.086 0.000 0.250 0.265
##
## Variances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## v1 0.943 0.084 11.269 0.000 0.943 1.000
## v2 1.011 0.090 11.269 0.000 1.011 1.000
## v3 0.878 0.078 11.269 0.000 0.878 1.000
## .v4 0.790 0.070 11.269 0.000 0.790 0.786
##
## R-Square:
## Estimate
## v4 0.214
### 오차상관통제회귀분석(SUR) 이용한 경로모형
# install.packages("systemfit")
reg2 <- v2~v1
reg3 <- v3~v1
reg4 <- v4~v1
SUR234 <- systemfit(list(OLS2=reg2,OLS3=reg3,OLS4=reg4), data=pm)
summary(SUR234)
##
## systemfit results
## method: OLS
##
## N DF SSR detRCov OLS-R2 McElroy-R2
## system 762 756 633.396 0.483867 0.138318 0.112947
##
## N DF SSR MSE RMSE R2 Adj R2
## OLS2 254 252 211.814 0.840532 0.916805 0.175237 0.171965
## OLS3 254 252 184.536 0.732286 0.855737 0.172493 0.169209
## OLS4 254 252 237.046 0.940660 0.969876 0.071315 0.067630
##
## The covariance matrix of the residuals
## OLS2 OLS3 OLS4
## OLS2 0.8405321 0.0868039 0.324860
## OLS3 0.0868039 0.7322856 0.151508
## OLS4 0.3248599 0.1515076 0.940660
##
## The correlations of the residuals
## OLS2 OLS3 OLS4
## OLS2 1.000000 0.110643 0.365345
## OLS3 0.110643 1.000000 0.182548
## OLS4 0.365345 0.182548 1.000000
##
##
## OLS estimates for 'OLS2' (equation 1)
## Model Formula: v2 ~ v1
##
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 2.2614124 0.2476038 9.13319 < 2.22e-16 ***
## v1 0.4333862 0.0592278 7.31727 3.3786e-12 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.916805 on 252 degrees of freedom
## Number of observations: 254 Degrees of Freedom: 252
## SSR: 211.814082 MSE: 0.840532 Root MSE: 0.916805
## Multiple R-Squared: 0.175237 Adjusted R-Squared: 0.171965
##
##
## OLS estimates for 'OLS3' (equation 2)
## Model Formula: v3 ~ v1
##
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 2.4038840 0.2311109 10.40143 < 2.22e-16 ***
## v1 0.4006714 0.0552827 7.24769 5.1741e-12 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.855737 on 252 degrees of freedom
## Number of observations: 254 Degrees of Freedom: 252
## SSR: 184.53598 MSE: 0.732286 Root MSE: 0.855737
## Multiple R-Squared: 0.172493 Adjusted R-Squared: 0.169209
##
##
## OLS estimates for 'OLS4' (equation 3)
## Model Formula: v4 ~ v1
##
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 2.7981616 0.2619368 10.68258 < 2.22e-16 ***
## v1 0.2756264 0.0626563 4.39902 1.6058e-05 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.969876 on 252 degrees of freedom
## Number of observations: 254 Degrees of Freedom: 252
## SSR: 237.046228 MSE: 0.94066 Root MSE: 0.969876
## Multiple R-Squared: 0.071315 Adjusted R-Squared: 0.06763
### 구조방정식 이용한 경로모형
mypm2 <- "v2~v1; v3~v1; v4~v1
v1~~v1
v2~~v2; v3~~v3; v4~~v4
v2~~v3; v2~~v4; v3~~v4
v1~1
v2~1;v3~1;v4~1"
obj.mypm2 <- sem(mypm2, fixed.x=F, data=pm)
summary(obj.mypm2, fit.measure=TRUE, standardized=TRUE, rsquare=TRUE)
## lavaan (0.5-23.1097) converged normally after 27 iterations
##
## Number of observations 254
##
## Estimator ML
## Minimum Function Test Statistic 0.000
## Degrees of freedom 0
## Minimum Function Value 0.0000000000000
##
## Model test baseline model:
##
## Minimum Function Test Statistic 161.404
## Degrees of freedom 6
## P-value 0.000
##
## User model versus baseline model:
##
## Comparative Fit Index (CFI) 1.000
## Tucker-Lewis Index (TLI) 1.000
##
## Loglikelihood and Information Criteria:
##
## Loglikelihood user model (H0) -1339.027
## Loglikelihood unrestricted model (H1) -1339.027
##
## Number of free parameters 14
## Akaike (AIC) 2706.054
## Bayesian (BIC) 2755.577
## Sample-size adjusted Bayesian (BIC) 2711.194
##
## Root Mean Square Error of Approximation:
##
## RMSEA 0.000
## 90 Percent Confidence Interval 0.000 0.000
## P-value RMSEA <= 0.05 NA
##
## Standardized Root Mean Square Residual:
##
## SRMR 0.000
##
## Parameter Estimates:
##
## Information Expected
## Standard Errors Standard
##
## Regressions:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## v2 ~
## v1 0.433 0.059 7.346 0.000 0.433 0.419
## v3 ~
## v1 0.401 0.055 7.276 0.000 0.401 0.415
## v4 ~
## v1 0.276 0.062 4.416 0.000 0.276 0.267
##
## Covariances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## .v2 ~~
## .v3 0.086 0.049 1.753 0.080 0.086 0.111
## .v4 0.322 0.059 5.469 0.000 0.322 0.365
## .v3 ~~
## .v4 0.150 0.053 2.862 0.004 0.150 0.183
##
## Intercepts:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## v1 4.066 0.061 66.721 0.000 4.066 4.186
## .v2 2.261 0.247 9.169 0.000 2.261 2.249
## .v3 2.404 0.230 10.443 0.000 2.404 2.566
## .v4 2.798 0.261 10.725 0.000 2.798 2.791
##
## Variances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## v1 0.943 0.084 11.269 0.000 0.943 1.000
## .v2 0.834 0.074 11.269 0.000 0.834 0.825
## .v3 0.727 0.064 11.269 0.000 0.727 0.828
## .v4 0.933 0.083 11.269 0.000 0.933 0.929
##
## R-Square:
## Estimate
## v2 0.175
## v3 0.172
## v4 0.071
### 오차의 공분산 추정-토플리츠 행렬 가정 <p.100>
mypm2a <- "v2~v1; v3~v1; v4~v1
v1~~v1
v2~~e1*v2; v3~~e1*v3; v4~~e1*v4
v2~~e2*v3; v2~~e3*v4; v3~~e2*v4
v1~1
v2~1;v3~1;v4~1"
obj.mypm2a <- sem(mypm2a, fixed.x=F, data=pm)
summary(obj.mypm2a, fit.measure=TRUE, standardized=TRUE, rsquare=TRUE)
## lavaan (0.5-23.1097) converged normally after 25 iterations
##
## Number of observations 254
##
## Estimator ML
## Minimum Function Test Statistic 5.027
## Degrees of freedom 3
## P-value (Chi-square) 0.170
##
## Model test baseline model:
##
## Minimum Function Test Statistic 161.404
## Degrees of freedom 6
## P-value 0.000
##
## User model versus baseline model:
##
## Comparative Fit Index (CFI) 0.987
## Tucker-Lewis Index (TLI) 0.974
##
## Loglikelihood and Information Criteria:
##
## Loglikelihood user model (H0) -1341.541
## Loglikelihood unrestricted model (H1) -1339.027
##
## Number of free parameters 11
## Akaike (AIC) 2705.081
## Bayesian (BIC) 2743.992
## Sample-size adjusted Bayesian (BIC) 2709.119
##
## Root Mean Square Error of Approximation:
##
## RMSEA 0.052
## 90 Percent Confidence Interval 0.000 0.128
## P-value RMSEA <= 0.05 0.393
##
## Standardized Root Mean Square Residual:
##
## SRMR 0.045
##
## Parameter Estimates:
##
## Information Expected
## Standard Errors Standard
##
## Regressions:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## v2 ~
## v1 0.433 0.059 7.373 0.000 0.433 0.420
## v3 ~
## v1 0.401 0.059 6.817 0.000 0.401 0.393
## v4 ~
## v1 0.276 0.059 4.689 0.000 0.276 0.282
##
## Covariances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## .v2 ~~
## .v3 (e2) 0.123 0.043 2.850 0.004 0.123 0.149
## .v4 (e3) 0.288 0.051 5.608 0.000 0.288 0.349
## .v3 ~~
## .v4 (e2) 0.123 0.043 2.850 0.004 0.123 0.149
##
## Intercepts:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## v1 4.066 0.061 66.721 0.000 4.066 4.186
## .v2 2.261 0.246 9.203 0.000 2.261 2.256
## .v3 2.404 0.246 9.783 0.000 2.404 2.429
## .v4 2.798 0.246 11.388 0.000 2.798 2.950
##
## Variances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## v1 0.943 0.084 11.269 0.000 0.943 1.000
## .v2 (e1) 0.828 0.045 18.541 0.000 0.828 0.824
## .v3 (e1) 0.828 0.045 18.541 0.000 0.828 0.845
## .v4 (e1) 0.828 0.045 18.541 0.000 0.828 0.920
##
## R-Square:
## Estimate
## v2 0.176
## v3 0.155
## v4 0.080
### BK를 이용한 매개모형 추정
### 매개효과(1)
bk.step1 <-lm(cbind(v2,v3)~v1, data=pm)
summary(bk.step1)
## Response v2 :
##
## Call:
## lm(formula = v2 ~ v1, data = pm)
##
## Residuals:
## Min 1Q Median 3Q Max
## -2.24825 -0.74167 -0.05499 0.65167 2.99830
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 2.26141 0.24760 9.133 < 2e-16 ***
## v1 0.43339 0.05923 7.317 3.38e-12 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.9168 on 252 degrees of freedom
## Multiple R-squared: 0.1752, Adjusted R-squared: 0.172
## F-statistic: 53.54 on 1 and 252 DF, p-value: 3.379e-12
##
##
## Response v3 :
##
## Call:
## lm(formula = v3 ~ v1, data = pm)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.96684 -0.56684 0.03417 0.59343 2.71262
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 2.40388 0.23111 10.401 < 2e-16 ***
## v1 0.40067 0.05528 7.248 5.17e-12 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.8557 on 252 degrees of freedom
## Multiple R-squared: 0.1725, Adjusted R-squared: 0.1692
## F-statistic: 52.53 on 1 and 252 DF, p-value: 5.174e-12
### 매개효과(2)
bk.step2 <-lm(v4~v1, data=pm)
summary(bk.step2)
##
## Call:
## lm(formula = v4 ~ v1, data = pm)
##
## Residuals:
## Min 1Q Median 3Q Max
## -2.68017 -0.66445 -0.02823 0.65480 2.99546
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 2.79816 0.26194 10.683 < 2e-16 ***
## v1 0.27563 0.06266 4.399 1.61e-05 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.9699 on 252 degrees of freedom
## Multiple R-squared: 0.07131, Adjusted R-squared: 0.06763
## F-statistic: 19.35 on 1 and 252 DF, p-value: 1.606e-05
### 매개효과(3)
bk.step3 <-lm(v4~v1+v2+v3, data=pm)
summary(bk.step3)
##
## Call:
## lm(formula = v4 ~ v1 + v2 + v3, data = pm)
##
## Residuals:
## Min 1Q Median 3Q Max
## -2.36903 -0.64324 -0.02091 0.57418 2.49146
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1.57020 0.31403 5.000 1.08e-06 ***
## v1 0.05008 0.06795 0.737 0.4618
## v2 0.36965 0.06192 5.970 8.11e-09 ***
## v3 0.16308 0.06634 2.458 0.0146 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.8957 on 250 degrees of freedom
## Multiple R-squared: 0.2143, Adjusted R-squared: 0.2048
## F-statistic: 22.72 on 3 and 250 DF, p-value: 4.824e-13
#총효과=직접효과+간접효과 계산 필요
### 구조방정식을 이용한 매개모형 추정
mypm3 <- "v2~v1; v3~v1; v4~v1
v4~v2+v3
v1~~v1
v2~~v2; v3~~v3; v4~~v4
v2~~v3
v1~1
v2~1; v3~1; v4~1"
obj.mypm3 <- sem(mypm3, fixed.x=F, data=pm)
summary(obj.mypm3, fit.measure=TRUE, standardized=TRUE, rsquare=TRUE)
## lavaan (0.5-23.1097) converged normally after 26 iterations
##
## Number of observations 254
##
## Estimator ML
## Minimum Function Test Statistic 0.000
## Degrees of freedom 0
## Minimum Function Value 0.0000000000000
##
## Model test baseline model:
##
## Minimum Function Test Statistic 161.404
## Degrees of freedom 6
## P-value 0.000
##
## User model versus baseline model:
##
## Comparative Fit Index (CFI) 1.000
## Tucker-Lewis Index (TLI) 1.000
##
## Loglikelihood and Information Criteria:
##
## Loglikelihood user model (H0) -1339.027
## Loglikelihood unrestricted model (H1) -1339.027
##
## Number of free parameters 14
## Akaike (AIC) 2706.054
## Bayesian (BIC) 2755.577
## Sample-size adjusted Bayesian (BIC) 2711.194
##
## Root Mean Square Error of Approximation:
##
## RMSEA 0.000
## 90 Percent Confidence Interval 0.000 0.000
## P-value RMSEA <= 0.05 NA
##
## Standardized Root Mean Square Residual:
##
## SRMR 0.000
##
## Parameter Estimates:
##
## Information Expected
## Standard Errors Standard
##
## Regressions:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## v2 ~
## v1 0.433 0.059 7.346 0.000 0.433 0.419
## v3 ~
## v1 0.401 0.055 7.276 0.000 0.401 0.415
## v4 ~
## v1 0.050 0.067 0.743 0.458 0.050 0.049
## v2 0.370 0.061 6.017 0.000 0.370 0.371
## v3 0.163 0.066 2.478 0.013 0.163 0.152
##
## Covariances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## .v2 ~~
## .v3 0.086 0.049 1.753 0.080 0.086 0.111
##
## Intercepts:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## v1 4.066 0.061 66.721 0.000 4.066 4.186
## .v2 2.261 0.247 9.169 0.000 2.261 2.249
## .v3 2.404 0.230 10.443 0.000 2.404 2.566
## .v4 1.570 0.312 5.040 0.000 1.570 1.566
##
## Variances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## v1 0.943 0.084 11.269 0.000 0.943 1.000
## .v2 0.834 0.074 11.269 0.000 0.834 0.825
## .v3 0.727 0.064 11.269 0.000 0.727 0.828
## .v4 0.790 0.070 11.269 0.000 0.790 0.786
##
## R-Square:
## Estimate
## v2 0.175
## v3 0.172
## v4 0.214
### 구조방정식 이용한 총효과 계산
mypm3a <- "v2~g12*v1; v3~g13*v1; v4~g14*v1
v4~b24*v2+b34*v3
v1~~v1
v2~~v2; v3~~v3; v4~~v4
v2~~v3
v1~1
v2~1; v3~1; v4~1
DE:= g14
IE2 := g12*b24
IE3 := g13*b34
IE := g12*b24+g13*b34
TE := g14+(g12*b24+g13*b34)"
obj.mypm3a <- sem(mypm3a, fixed.x=F, data=pm)
summary(obj.mypm3a, fit.measure=TRUE, standardized=TRUE, rsquare=TRUE)
## lavaan (0.5-23.1097) converged normally after 26 iterations
##
## Number of observations 254
##
## Estimator ML
## Minimum Function Test Statistic 0.000
## Degrees of freedom 0
## Minimum Function Value 0.0000000000000
##
## Model test baseline model:
##
## Minimum Function Test Statistic 161.404
## Degrees of freedom 6
## P-value 0.000
##
## User model versus baseline model:
##
## Comparative Fit Index (CFI) 1.000
## Tucker-Lewis Index (TLI) 1.000
##
## Loglikelihood and Information Criteria:
##
## Loglikelihood user model (H0) -1339.027
## Loglikelihood unrestricted model (H1) -1339.027
##
## Number of free parameters 14
## Akaike (AIC) 2706.054
## Bayesian (BIC) 2755.577
## Sample-size adjusted Bayesian (BIC) 2711.194
##
## Root Mean Square Error of Approximation:
##
## RMSEA 0.000
## 90 Percent Confidence Interval 0.000 0.000
## P-value RMSEA <= 0.05 NA
##
## Standardized Root Mean Square Residual:
##
## SRMR 0.000
##
## Parameter Estimates:
##
## Information Expected
## Standard Errors Standard
##
## Regressions:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## v2 ~
## v1 (g12) 0.433 0.059 7.346 0.000 0.433 0.419
## v3 ~
## v1 (g13) 0.401 0.055 7.276 0.000 0.401 0.415
## v4 ~
## v1 (g14) 0.050 0.067 0.743 0.458 0.050 0.049
## v2 (b24) 0.370 0.061 6.017 0.000 0.370 0.371
## v3 (b34) 0.163 0.066 2.478 0.013 0.163 0.152
##
## Covariances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## .v2 ~~
## .v3 0.086 0.049 1.753 0.080 0.086 0.111
##
## Intercepts:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## v1 4.066 0.061 66.721 0.000 4.066 4.186
## .v2 2.261 0.247 9.169 0.000 2.261 2.249
## .v3 2.404 0.230 10.443 0.000 2.404 2.566
## .v4 1.570 0.312 5.040 0.000 1.570 1.566
##
## Variances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## v1 0.943 0.084 11.269 0.000 0.943 1.000
## .v2 0.834 0.074 11.269 0.000 0.834 0.825
## .v3 0.727 0.064 11.269 0.000 0.727 0.828
## .v4 0.790 0.070 11.269 0.000 0.790 0.786
##
## R-Square:
## Estimate
## v2 0.175
## v3 0.172
## v4 0.214
##
## Defined Parameters:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## DE 0.050 0.067 0.743 0.458 0.050 0.049
## IE2 0.160 0.034 4.655 0.000 0.160 0.155
## IE3 0.065 0.028 2.346 0.019 0.065 0.063
## IE 0.226 0.043 5.246 0.000 0.226 0.219
## TE 0.276 0.062 4.416 0.000 0.276 0.267
### 두 매개변수(v2,v3) 효과의 동등성 검증
temp <- "diff.IE := g12*b24-g13*b34"
mypm3b <- paste(mypm3a, temp, sep="\n")
obj.mypm3b <- sem(mypm3b, fixed.x=F, data=pm)
summary(obj.mypm3b, fit.measure=TRUE, standardized=TRUE, rsquare=TRUE)
## lavaan (0.5-23.1097) converged normally after 26 iterations
##
## Number of observations 254
##
## Estimator ML
## Minimum Function Test Statistic 0.000
## Degrees of freedom 0
## Minimum Function Value 0.0000000000000
##
## Model test baseline model:
##
## Minimum Function Test Statistic 161.404
## Degrees of freedom 6
## P-value 0.000
##
## User model versus baseline model:
##
## Comparative Fit Index (CFI) 1.000
## Tucker-Lewis Index (TLI) 1.000
##
## Loglikelihood and Information Criteria:
##
## Loglikelihood user model (H0) -1339.027
## Loglikelihood unrestricted model (H1) -1339.027
##
## Number of free parameters 14
## Akaike (AIC) 2706.054
## Bayesian (BIC) 2755.577
## Sample-size adjusted Bayesian (BIC) 2711.194
##
## Root Mean Square Error of Approximation:
##
## RMSEA 0.000
## 90 Percent Confidence Interval 0.000 0.000
## P-value RMSEA <= 0.05 NA
##
## Standardized Root Mean Square Residual:
##
## SRMR 0.000
##
## Parameter Estimates:
##
## Information Expected
## Standard Errors Standard
##
## Regressions:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## v2 ~
## v1 (g12) 0.433 0.059 7.346 0.000 0.433 0.419
## v3 ~
## v1 (g13) 0.401 0.055 7.276 0.000 0.401 0.415
## v4 ~
## v1 (g14) 0.050 0.067 0.743 0.458 0.050 0.049
## v2 (b24) 0.370 0.061 6.017 0.000 0.370 0.371
## v3 (b34) 0.163 0.066 2.478 0.013 0.163 0.152
##
## Covariances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## .v2 ~~
## .v3 0.086 0.049 1.753 0.080 0.086 0.111
##
## Intercepts:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## v1 4.066 0.061 66.721 0.000 4.066 4.186
## .v2 2.261 0.247 9.169 0.000 2.261 2.249
## .v3 2.404 0.230 10.443 0.000 2.404 2.566
## .v4 1.570 0.312 5.040 0.000 1.570 1.566
##
## Variances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## v1 0.943 0.084 11.269 0.000 0.943 1.000
## .v2 0.834 0.074 11.269 0.000 0.834 0.825
## .v3 0.727 0.064 11.269 0.000 0.727 0.828
## .v4 0.790 0.070 11.269 0.000 0.790 0.786
##
## R-Square:
## Estimate
## v2 0.175
## v3 0.172
## v4 0.214
##
## Defined Parameters:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## DE 0.050 0.067 0.743 0.458 0.050 0.049
## IE2 0.160 0.034 4.655 0.000 0.160 0.155
## IE3 0.065 0.028 2.346 0.019 0.065 0.063
## IE 0.226 0.043 5.246 0.000 0.226 0.219
## TE 0.276 0.062 4.416 0.000 0.276 0.267
## diff.IE 0.095 0.046 2.084 0.037 0.095 0.092
##### z=2.084, v2변수를 경유하는 매개효과가 v3변수를 매개하는 매개효과보다 통계적으로 유의미하게 큼
### 순환모형 추정 <p.117> -텍스트형태를 상관계수행렬 오브젝트로 변환
lower <- "
1.000
0.2220 1.0000
0.4105 0.3240 1.0000
0.3355 0.2302 0.2995 1.0000
0.1861 0.2707 0.2930 0.2950 1.0000
0.2598 0.2786 0.4216 0.5007 0.3607 1.000
"
dhp1968 <- getCov(lower, names=c("r_intel", "r_ses", "r_occasp", "f_intel", "f_ses", "f_occasp"))
### 공분산행렬을 이용한 구조방정식모형 추정 <p.118>
mypm4 <- " r_occasp ~ r_intel+r_ses+f_ses
f_occasp ~ f_intel+f_ses+r_ses
r_occasp ~ f_occasp
f_occasp ~ r_occasp
r_intel~~r_intel; r_ses~~r_ses;
f_intel~~f_intel; f_ses~~f_ses;
r_intel~~r_ses; r_intel~~f_intel; r_intel~~f_ses;
r_ses~~f_intel; r_ses~~f_ses;
f_intel~~f_ses;
f_occasp~~f_occasp; r_occasp~~r_occasp
f_occasp~~r_occasp
r_intel~1; r_ses~1
f_intel~1; f_ses~1
f_occasp~1;r_occasp~1"
obj.mypm4 <- sem(mypm4, fixed.x=F, sample.cov = dhp1968, sample.nobs = 329)
summary(obj.mypm4, fit.measure=TRUE, standardized=TRUE, rsquare=TRUE)
## lavaan (0.5-23.1097) converged normally after 29 iterations
##
## Number of observations 329
##
## Estimator ML
## Minimum Function Test Statistic 0.000
## Degrees of freedom 0
## Minimum Function Value 0.0000000000000
##
## Model test baseline model:
##
## Minimum Function Test Statistic 361.862
## Degrees of freedom 15
## P-value 0.000
##
## User model versus baseline model:
##
## Comparative Fit Index (CFI) 1.000
## Tucker-Lewis Index (TLI) 1.000
##
## Loglikelihood and Information Criteria:
##
## Loglikelihood user model (H0) -2617.049
## Loglikelihood unrestricted model (H1) -2617.049
##
## Number of free parameters 27
## Akaike (AIC) 5288.098
## Bayesian (BIC) 5390.591
## Sample-size adjusted Bayesian (BIC) 5304.948
##
## Root Mean Square Error of Approximation:
##
## RMSEA 0.000
## 90 Percent Confidence Interval 0.000 0.000
## P-value RMSEA <= 0.05 NA
##
## Standardized Root Mean Square Residual:
##
## SRMR 0.000
##
## Parameter Estimates:
##
## Information Expected
## Standard Errors Standard
##
## Regressions:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## r_occasp ~
## r_intel 0.285 0.052 5.469 0.000 0.285 0.285
## r_ses 0.157 0.053 2.977 0.003 0.157 0.157
## f_ses 0.097 0.060 1.612 0.107 0.097 0.097
## f_occasp ~
## f_intel 0.369 0.056 6.620 0.000 0.369 0.369
## f_ses 0.168 0.054 3.092 0.002 0.168 0.168
## r_ses 0.079 0.059 1.348 0.178 0.079 0.079
## r_occasp ~
## f_occasp 0.277 0.129 2.154 0.031 0.277 0.277
## f_occasp ~
## r_occasp 0.212 0.156 1.354 0.176 0.212 0.212
##
## Covariances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## r_intel ~~
## r_ses 0.221 0.056 3.931 0.000 0.221 0.222
## f_intel 0.334 0.058 5.769 0.000 0.334 0.335
## f_ses 0.186 0.056 3.319 0.001 0.186 0.186
## r_ses ~~
## f_intel 0.230 0.056 4.069 0.000 0.230 0.230
## f_ses 0.270 0.057 4.739 0.000 0.270 0.271
## f_ses ~~
## f_intel 0.294 0.057 5.132 0.000 0.294 0.295
## .r_occasp ~~
## .f_occasp -0.154 0.144 -1.065 0.287 -0.154 -0.233
##
## Intercepts:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## r_intel 0.000 0.055 0.000 1.000 0.000 0.000
## r_ses 0.000 0.055 0.000 1.000 0.000 0.000
## f_intel 0.000 0.055 0.000 1.000 0.000 0.000
## f_ses 0.000 0.055 0.000 1.000 0.000 0.000
## .f_occasp 0.000 0.044 0.000 1.000 0.000 0.000
## .r_occasp 0.000 0.046 0.000 1.000 0.000 0.000
##
## Variances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## r_intel 0.997 0.078 12.826 0.000 0.997 1.000
## r_ses 0.997 0.078 12.826 0.000 0.997 1.000
## f_intel 0.997 0.078 12.826 0.000 0.997 1.000
## f_ses 0.997 0.078 12.826 0.000 0.997 1.000
## .f_occasp 0.636 0.050 12.680 0.000 0.636 0.638
## .r_occasp 0.687 0.054 12.814 0.000 0.687 0.689
##
## R-Square:
## Estimate
## f_occasp 0.362
## r_occasp 0.311
### 동등성 제약을 이용하여 상호 인과관계의 차이 검증
mypm4a <- "
r_occasp ~ r_intel+r_ses+f_ses
f_occasp ~ f_intel+f_ses+r_ses
r_occasp ~ b*f_occasp
f_occasp ~ b*r_occasp
r_intel~~r_intel; r_ses~~r_ses;
f_intel~~f_intel; f_ses~~f_ses;
r_intel~~r_ses; r_intel~~f_intel; r_intel~~f_ses;
r_ses~~f_intel; r_ses~~f_ses;
f_intel~~f_ses;
f_occasp~~f_occasp; r_occasp~~r_occasp
f_occasp~~r_occasp
r_intel~1; r_ses~1
f_intel~1; f_ses~1
f_occasp~1;r_occasp~1"
obj.mypm4a <- sem(mypm4a, fixed.x=F, sample.cov = dhp1968, sample.nobs = 329)
summary(obj.mypm4, fit.measure=TRUE, standardized=TRUE, rsquare=TRUE)
## lavaan (0.5-23.1097) converged normally after 29 iterations
##
## Number of observations 329
##
## Estimator ML
## Minimum Function Test Statistic 0.000
## Degrees of freedom 0
## Minimum Function Value 0.0000000000000
##
## Model test baseline model:
##
## Minimum Function Test Statistic 361.862
## Degrees of freedom 15
## P-value 0.000
##
## User model versus baseline model:
##
## Comparative Fit Index (CFI) 1.000
## Tucker-Lewis Index (TLI) 1.000
##
## Loglikelihood and Information Criteria:
##
## Loglikelihood user model (H0) -2617.049
## Loglikelihood unrestricted model (H1) -2617.049
##
## Number of free parameters 27
## Akaike (AIC) 5288.098
## Bayesian (BIC) 5390.591
## Sample-size adjusted Bayesian (BIC) 5304.948
##
## Root Mean Square Error of Approximation:
##
## RMSEA 0.000
## 90 Percent Confidence Interval 0.000 0.000
## P-value RMSEA <= 0.05 NA
##
## Standardized Root Mean Square Residual:
##
## SRMR 0.000
##
## Parameter Estimates:
##
## Information Expected
## Standard Errors Standard
##
## Regressions:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## r_occasp ~
## r_intel 0.285 0.052 5.469 0.000 0.285 0.285
## r_ses 0.157 0.053 2.977 0.003 0.157 0.157
## f_ses 0.097 0.060 1.612 0.107 0.097 0.097
## f_occasp ~
## f_intel 0.369 0.056 6.620 0.000 0.369 0.369
## f_ses 0.168 0.054 3.092 0.002 0.168 0.168
## r_ses 0.079 0.059 1.348 0.178 0.079 0.079
## r_occasp ~
## f_occasp 0.277 0.129 2.154 0.031 0.277 0.277
## f_occasp ~
## r_occasp 0.212 0.156 1.354 0.176 0.212 0.212
##
## Covariances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## r_intel ~~
## r_ses 0.221 0.056 3.931 0.000 0.221 0.222
## f_intel 0.334 0.058 5.769 0.000 0.334 0.335
## f_ses 0.186 0.056 3.319 0.001 0.186 0.186
## r_ses ~~
## f_intel 0.230 0.056 4.069 0.000 0.230 0.230
## f_ses 0.270 0.057 4.739 0.000 0.270 0.271
## f_ses ~~
## f_intel 0.294 0.057 5.132 0.000 0.294 0.295
## .r_occasp ~~
## .f_occasp -0.154 0.144 -1.065 0.287 -0.154 -0.233
##
## Intercepts:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## r_intel 0.000 0.055 0.000 1.000 0.000 0.000
## r_ses 0.000 0.055 0.000 1.000 0.000 0.000
## f_intel 0.000 0.055 0.000 1.000 0.000 0.000
## f_ses 0.000 0.055 0.000 1.000 0.000 0.000
## .f_occasp 0.000 0.044 0.000 1.000 0.000 0.000
## .r_occasp 0.000 0.046 0.000 1.000 0.000 0.000
##
## Variances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## r_intel 0.997 0.078 12.826 0.000 0.997 1.000
## r_ses 0.997 0.078 12.826 0.000 0.997 1.000
## f_intel 0.997 0.078 12.826 0.000 0.997 1.000
## f_ses 0.997 0.078 12.826 0.000 0.997 1.000
## .f_occasp 0.636 0.050 12.680 0.000 0.636 0.638
## .r_occasp 0.687 0.054 12.814 0.000 0.687 0.689
##
## R-Square:
## Estimate
## f_occasp 0.362
## r_occasp 0.311
anova(obj.mypm4, obj.mypm4a)
## Chi Square Difference Test
##
## Df AIC BIC Chisq Chisq diff Df diff Pr(>Chisq)
## obj.mypm4 0 5288.1 5390.6 0.0000
## obj.mypm4a 1 5286.2 5384.9 0.1123 0.11231 1 0.7375
### 내생변수에 대한 외생변수의 직접효과, 간접효과, 총효과 추정결과
mypm4b <- " r_occasp ~ g11*r_intel+g21*r_ses+g31*f_ses
f_occasp ~ g42*f_intel+g32*f_ses+g22*r_ses
r_occasp ~ b21*f_occasp
f_occasp ~ b12*r_occasp
r_intel~~r_intel; r_ses~~r_ses;
f_intel~~f_intel; f_ses~~f_ses;
r_intel~~r_ses; r_intel~~f_intel; r_intel~~f_ses;
r_ses~~f_intel; r_ses~~f_ses;
f_intel~~f_ses;
f_occasp~~f_occasp; r_occasp~~r_occasp
f_occasp~~r_occasp
r_intel~1; r_ses~1
f_intel~1; f_ses~1
f_occasp~1;r_occasp~1
DE11 := g11
DE21 := g21; DE22 := g22
DE31 := g31; DE32 := g32
DE42 := g42
IE12 := g11*b12
IE21 := g22*b21; IE22 := g21*b12
IE31 := g32*b21; IE32 := g31*b12
IE41 := g42*b21
TE11 := DE11; TE12 := IE12
TE21 := DE21+IE21; TE22 := DE22+IE22
TE31 := DE31+IE31; TE32 := DE32+IE32
TE41 := IE41; TE42 := DE42
diff.IE := IE41-IE12"
obj.mypm4b <- sem(mypm4b, fixed.x=F, sample.cov = dhp1968, sample.nobs = 329)
summary(obj.mypm4b, fit.measure=TRUE, standardized=TRUE, rsquare=TRUE)
## lavaan (0.5-23.1097) converged normally after 29 iterations
##
## Number of observations 329
##
## Estimator ML
## Minimum Function Test Statistic 0.000
## Degrees of freedom 0
## Minimum Function Value 0.0000000000000
##
## Model test baseline model:
##
## Minimum Function Test Statistic 361.862
## Degrees of freedom 15
## P-value 0.000
##
## User model versus baseline model:
##
## Comparative Fit Index (CFI) 1.000
## Tucker-Lewis Index (TLI) 1.000
##
## Loglikelihood and Information Criteria:
##
## Loglikelihood user model (H0) -2617.049
## Loglikelihood unrestricted model (H1) -2617.049
##
## Number of free parameters 27
## Akaike (AIC) 5288.098
## Bayesian (BIC) 5390.591
## Sample-size adjusted Bayesian (BIC) 5304.948
##
## Root Mean Square Error of Approximation:
##
## RMSEA 0.000
## 90 Percent Confidence Interval 0.000 0.000
## P-value RMSEA <= 0.05 NA
##
## Standardized Root Mean Square Residual:
##
## SRMR 0.000
##
## Parameter Estimates:
##
## Information Expected
## Standard Errors Standard
##
## Regressions:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## r_occasp ~
## r_intel (g11) 0.285 0.052 5.469 0.000 0.285 0.285
## r_ses (g21) 0.157 0.053 2.977 0.003 0.157 0.157
## f_ses (g31) 0.097 0.060 1.612 0.107 0.097 0.097
## f_occasp ~
## f_intel (g42) 0.369 0.056 6.620 0.000 0.369 0.369
## f_ses (g32) 0.168 0.054 3.092 0.002 0.168 0.168
## r_ses (g22) 0.079 0.059 1.348 0.178 0.079 0.079
## r_occasp ~
## f_occasp (b21) 0.277 0.129 2.154 0.031 0.277 0.277
## f_occasp ~
## r_occasp (b12) 0.212 0.156 1.354 0.176 0.212 0.212
##
## Covariances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## r_intel ~~
## r_ses 0.221 0.056 3.931 0.000 0.221 0.222
## f_intel 0.334 0.058 5.769 0.000 0.334 0.335
## f_ses 0.186 0.056 3.319 0.001 0.186 0.186
## r_ses ~~
## f_intel 0.230 0.056 4.069 0.000 0.230 0.230
## f_ses 0.270 0.057 4.739 0.000 0.270 0.271
## f_ses ~~
## f_intel 0.294 0.057 5.132 0.000 0.294 0.295
## .r_occasp ~~
## .f_occasp -0.154 0.144 -1.065 0.287 -0.154 -0.233
##
## Intercepts:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## r_intel 0.000 0.055 0.000 1.000 0.000 0.000
## r_ses 0.000 0.055 0.000 1.000 0.000 0.000
## f_intel 0.000 0.055 0.000 1.000 0.000 0.000
## f_ses 0.000 0.055 0.000 1.000 0.000 0.000
## .f_occasp 0.000 0.044 0.000 1.000 0.000 0.000
## .r_occasp 0.000 0.046 0.000 1.000 0.000 0.000
##
## Variances:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## r_intel 0.997 0.078 12.826 0.000 0.997 1.000
## r_ses 0.997 0.078 12.826 0.000 0.997 1.000
## f_intel 0.997 0.078 12.826 0.000 0.997 1.000
## f_ses 0.997 0.078 12.826 0.000 0.997 1.000
## .f_occasp 0.636 0.050 12.680 0.000 0.636 0.638
## .r_occasp 0.687 0.054 12.814 0.000 0.687 0.689
##
## R-Square:
## Estimate
## f_occasp 0.362
## r_occasp 0.311
##
## Defined Parameters:
## Estimate Std.Err z-value P(>|z|) Std.lv Std.all
## DE11 0.285 0.052 5.469 0.000 0.285 0.285
## DE21 0.157 0.053 2.977 0.003 0.157 0.157
## DE22 0.079 0.059 1.348 0.178 0.079 0.079
## DE31 0.097 0.060 1.612 0.107 0.097 0.097
## DE32 0.168 0.054 3.092 0.002 0.168 0.168
## DE42 0.369 0.056 6.620 0.000 0.369 0.369
## IE12 0.060 0.043 1.391 0.164 0.060 0.060
## IE21 0.022 0.019 1.149 0.251 0.022 0.022
## IE22 0.033 0.027 1.228 0.220 0.033 0.033
## IE31 0.047 0.027 1.754 0.079 0.047 0.047
## IE32 0.021 0.020 1.045 0.296 0.021 0.021
## IE41 0.102 0.047 2.197 0.028 0.102 0.102
## TE11 0.285 0.052 5.469 0.000 0.285 0.285
## TE12 0.060 0.043 1.391 0.164 0.060 0.060
## TE21 0.179 0.049 3.652 0.000 0.179 0.179
## TE22 0.113 0.047 2.414 0.016 0.113 0.113
## TE31 0.144 0.049 2.914 0.004 0.144 0.144
## TE32 0.189 0.048 3.955 0.000 0.189 0.189
## TE41 0.102 0.047 2.197 0.028 0.102 0.102
## TE42 0.369 0.056 6.620 0.000 0.369 0.369
## diff.IE 0.042 0.070 0.598 0.550 0.042 0.042