SEM Path Analysis

2017/10/01

The system of variables:

Generate data to represent the system above:

cov_matrix = matrix(c(1.0, 0.02, 0.02, 0.04, 0.01,
                      0.02, 1.0, 0.08, 0.16, 0.28,
                      0.02, 0.08, 1.0, 0.35, 0.47,
                      0.04, 0.16, 0.35, 1.0, 0.02,
                      0.01, 0.28, 0.47, 0.02, 1.0), 5, 5)

library(MASS)
N = 800
Mu = c(0,0,0,0,0)

data_f = data.frame(mvrnorm(N, Mu, cov_matrix))
names(data_f) = c("x1", "x2", "x3","y1", "y2")

Estimate the parameters using SEM:

sem_model = "

# Regressions
y1 ~ G11*x1 + G12*x2 + G13*x3
y2 ~ G22*x2 + G23*x3 + B21*y1

# Variance:
y1 ~~ y1
y2 ~~ y2

x1 ~~ x1
x2 ~~ x2
x3 ~~ x3

# Covariance:

x1 ~~ x2 + x3
x2 ~~ x3

"

library(lavaan)
sem_model_fit = sem(sem_model, data = data_f)

The results:

summary(sem_model_fit)
## lavaan (0.5-23.1097) converged normally after  17 iterations
## 
##   Number of observations                           800
## 
##   Estimator                                         ML
##   Minimum Function Test Statistic                0.190
##   Degrees of freedom                                 1
##   P-value (Chi-square)                           0.663
## 
## Parameter Estimates:
## 
##   Information                                 Expected
##   Standard Errors                             Standard
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   y1 ~                                                
##     x1       (G11)   -0.010    0.035   -0.286    0.775
##     x2       (G12)    0.166    0.034    4.910    0.000
##     x3       (G13)    0.272    0.034    7.969    0.000
##   y2 ~                                                
##     x2       (G22)    0.222    0.028    7.848    0.000
##     x3       (G23)    0.534    0.029   18.317    0.000
##     y1       (B21)   -0.249    0.029   -8.553    0.000
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   x1 ~~                                               
##     x2               -0.010    0.035   -0.277    0.782
##     x3               -0.011    0.035   -0.327    0.744
##   x2 ~~                                               
##     x3                0.136    0.037    3.719    0.000
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##    .y1                0.935    0.047   20.000    0.000
##    .y2                0.633    0.032   20.000    0.000
##     x1                0.957    0.048   20.000    0.000
##     x2                1.037    0.052   20.000    0.000
##     x3                1.021    0.051   20.000    0.000