1. 예제 자료

library(readxl)
library(dplyr)

mydf = as.data.frame(read_excel(path = '/cloud/project/mydata.xlsx'))

names(mydf) = c('agree', 'age', 'sex', 'edu', 'marital',
                  paste0('bpns', 1:18),
                  paste0('ctq', 1:10)) 

mydf3 = mydf %>% filter(bpns14<=5 & ctq7<=4 & ctq9<=4 & ctq10<=4) %>% 
  filter(rowSums(is.na(.))==0) %>%
  mutate(bpns1r = 6 - bpns1,
         bpns2r = 6 - bpns2,
         bpns3r = 6 - bpns3,
         bpns6r = 6 - bpns6,
         bpns14r = 6 - bpns14,
         ctq6r = 5 - ctq6,
         ctq7r = 5 - ctq7,
         ctq8r = 5 - ctq8,
         ctq9r = 5 - ctq9,
         ctq10r = 5 - ctq10) %>% 
  mutate(autonomy = rowSums(select(.,bpns1r,bpns2r,bpns3r,bpns4,bpns5,bpns6r)),
         competence = rowSums(select(.,bpns7:bpns12)),
         related = rowSums(select(.,bpns13,bpns14r,bpns15:bpns18)),
         abuse = rowSums(select(.,ctq1:ctq5)),
         neglect = rowSums(select(.,ctq6r:ctq10r)))

2. lavaan 패키지를 사용한 SEM 분석

2-1. 확인적 요인분석(Confirmatory Factor Analysis)

install.packages('lavaan')
library(lavaan)

model.cfa = 'autonomy =~ bpns1r + bpns2r + bpns3r + bpns4 + bpns5 + bpns6r
             competence =~ bpns7 + bpns8 + bpns9 + bpns10 + bpns11 + bpns12
             relatedness =~ bpns13 + bpns14r + bpns15 + bpns16 + bpns17 + bpns18'
             

fit.cfa = cfa(model = model.cfa, data = mydf3)
summary(fit.cfa, fit.measures = T, standardized = T)

# lavaan 0.6.16 ended normally after 37 iterations
# 
# Estimator                                         ML
# Optimization method                           NLMINB
# Number of model parameters                        39
# 
# Number of observations                           307
# 
# Model Test User Model:
#   
# Test statistic                               386.839
# Degrees of freedom                               132
# P-value (Chi-square)                           0.000
# 
# Model Test Baseline Model:
#   
# Test statistic                              2005.130
# Degrees of freedom                               153
# P-value                                        0.000
# 
# User Model versus Baseline Model:
#   
# Comparative Fit Index (CFI)                    0.862
# Tucker-Lewis Index (TLI)                       0.841
# 
# Loglikelihood and Information Criteria:
#   
# Loglikelihood user model (H0)              -6166.063
# Loglikelihood unrestricted model (H1)      -5972.643
# 
# Akaike (AIC)                               12410.126
# Bayesian (BIC)                             12555.473
# Sample-size adjusted Bayesian (SABIC)      12431.782
# 
# Root Mean Square Error of Approximation:
#   
# RMSEA                                          0.079
# 90 Percent confidence interval - lower         0.070
# 90 Percent confidence interval - upper         0.089
# P-value H_0: RMSEA <= 0.050                    0.000
# P-value H_0: RMSEA >= 0.080                    0.460
# 
# Standardized Root Mean Square Residual:
#   
#   SRMR                                         0.078
# 
# Parameter Estimates:
#   
# Standard errors                             Standard
# Information                                 Expected
# Information saturated (h1) model          Structured
# 
# Latent Variables:
#                Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
# Autonomy =~                                                           
# bpns1r            1.000                               0.699    0.689
# bpns2r            0.947    0.089   10.592    0.000    0.662    0.715
# bpns3r            1.032    0.096   10.805    0.000    0.722    0.733
# bpns4             0.701    0.082    8.512    0.000    0.490    0.555
# bpns5             0.718    0.080    8.963    0.000    0.502    0.588
# bpns6r            0.794    0.089    8.968    0.000    0.556    0.588
# Competence =~                                                         
# bpns7             1.000                               0.630    0.646
# bpns8             0.859    0.090    9.565    0.000    0.541    0.673
# bpns9             0.770    0.086    8.952    0.000    0.485    0.618
# bpns10            1.007    0.097   10.403    0.000    0.634    0.758
# bpns11            0.829    0.094    8.818    0.000    0.522    0.607
# bpns12            0.808    0.098    8.207    0.000    0.508    0.556
# Relatedness =~                                                        
# bpns13            1.000                               0.526    0.627
# bpns14r           0.979    0.121    8.118    0.000    0.515    0.565
# bpns15            0.839    0.091    9.195    0.000    0.441    0.665
# bpns16            0.972    0.103    9.451    0.000    0.511    0.691
# bpns17            0.916    0.101    9.083    0.000    0.481    0.654
# bpns18            0.990    0.110    8.962    0.000    0.520    0.642
# 
# Covariances:
#                  Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
# Autonomy ~~                                                           
#   Competence        0.211    0.038    5.497    0.000    0.479    0.479
# Relatedness         0.197    0.034    5.817    0.000    0.536    0.536
# Competence ~~                                                         
#   Relatedness       0.187    0.032    5.870    0.000    0.565    0.565
# 
# Variances:
#                  Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
# .bpns1r            0.541    0.054   10.115    0.000    0.541    0.525
# .bpns2r            0.420    0.043    9.759    0.000    0.420    0.489
# .bpns3r            0.448    0.047    9.457    0.000    0.448    0.462
# .bpns4             0.539    0.048   11.278    0.000    0.539    0.692
# .bpns5             0.477    0.043   11.070    0.000    0.477    0.654
# .bpns6r            0.583    0.053   11.068    0.000    0.583    0.654
# .bpns7             0.553    0.052   10.584    0.000    0.553    0.582
# .bpns8             0.354    0.034   10.302    0.000    0.354    0.547
# .bpns9             0.380    0.035   10.835    0.000    0.380    0.618
# .bpns10            0.297    0.033    8.969    0.000    0.297    0.425
# .bpns11            0.467    0.043   10.926    0.000    0.467    0.632
# .bpns12            0.577    0.051   11.267    0.000    0.577    0.690
# .bpns13            0.426    0.040   10.702    0.000    0.426    0.606
# .bpns14r           0.565    0.051   11.175    0.000    0.565    0.681
# .bpns15            0.246    0.024   10.328    0.000    0.246    0.558
# .bpns16            0.286    0.029   10.008    0.000    0.286    0.523
# .bpns17            0.311    0.030   10.448    0.000    0.311    0.573
# .bpns18            0.387    0.037   10.567    0.000    0.387    0.588
# Autonomy           0.489    0.077    6.334    0.000    1.000    1.000
# Competence         0.396    0.068    5.834    0.000    1.000    1.000
# Relatedness        0.276    0.049    5.603    0.000    1.000    1.000

<aside> 📎

적합도 지수

2-2. 구조방정식(Structural Equation Modeling)