Lavaan example Fig 2.5

#import data
ch2.data <- '
1.00
.50 1.00
.10 .10 1.00
.20 .30 .20 1.00
'
# make symmetric matrix and name variables
ch2.cor <- getCov(ch2.data, names=c("A","B","C","D"))
#models
model.a <- '
G =~ a*A + b*B + c*C + d*D
'
model.b <- '
E =~ a*A + b*B
F =~ c*C + d*D
'
#fit models
fit.a <- cfa(model.a, sample.cov=ch2.cor, sample.nobs=100, std.lv=TRUE)
summary(fit.a)
## lavaan 0.6.15 ended normally after 16 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                         8
## 
##   Number of observations                           100
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 2.798
##   Degrees of freedom                                 2
##   P-value (Chi-square)                           0.247
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
## 
## Latent Variables:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   G =~                                                
##     A          (a)    0.608    0.141    4.309    0.000
##     B          (b)    0.808    0.166    4.880    0.000
##     C          (c)    0.156    0.117    1.338    0.181
##     D          (d)    0.367    0.118    3.107    0.002
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##    .A                 0.621    0.159    3.914    0.000
##    .B                 0.337    0.238    1.419    0.156
##    .C                 0.966    0.138    7.002    0.000
##    .D                 0.855    0.131    6.529    0.000
##     G                 1.000
fit.b <- cfa(model.b, sample.cov=ch2.cor,sample.nobs=100, std.lv=TRUE)
summary(fit.b)
## lavaan 0.6.15 ended normally after 30 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                         9
## 
##   Number of observations                           100
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.145
##   Degrees of freedom                                 1
##   P-value (Chi-square)                           0.703
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
## 
## Latent Variables:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   E =~                                                
##     A          (a)    0.582    0.149    3.895    0.000
##     B          (b)    0.850    0.191    4.455    0.000
##   F =~                                                
##     C          (c)    0.267    0.153    1.742    0.082
##     D          (d)    0.742    0.339    2.189    0.029
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   E ~~                                                
##     F                 0.469    0.236    1.982    0.047
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##    .A                 0.651    0.166    3.916    0.000
##    .B                 0.267    0.298    0.897    0.369
##    .C                 0.919    0.144    6.363    0.000
##    .D                 0.439    0.491    0.895    0.371
##     E                 1.000                           
##     F                 1.000

Including Plots

#semPlot: plot one- & two-factor
semPaths(fit.a, what="est", intercepts = FALSE)

semPaths(fit.b, what="est", intercepts = FALSE)

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.