Steps to test a structural equation model using R

Steps to perform a structural equation model.

1st Step: Define a model!

 model <- '   
   F =~ MOV + SD + BLD + DFN + OBS  
 '  


2nd Step: Test your model!

 library(lavaan)  
 fit <- lavaan::cfa(model, data = PAPDdata, estimator = "MLM")  
 summary(fit, fit.measures = TRUE)  
 summary(fit, standardized=TRUE, rsq=TRUE)  
 parameterestimates(fit)  
 fitMeasures(fit) 
 standardizedSolution(fit) 

3rd Step: Check multivariate normality

 library(MVN)  
 result = mardiaTest(mardiadata, qqplot = TRUE)  
 result  


 Output:

   Mardia's Multivariate Normality Test   
 ---------------------------------------   
   data : mardiadata   
   g1p      : 8.130499   
   chi.skew    : 971.5946   
   p.value.skew  : 2.68991e-181   
   g2p      : 64.29887   
   z.kurtosis   : 46.88472   
   p.value.kurt  : 0   
   chi.small.skew : 977.0206   
   p.value.small : 1.955776e-182   
   Result     : Data are not multivariate normal.   
 ---------------------------------------   

4th Step: If data are not multivariate normal then report the robust estimations based on Satorra - Bentler correction. If multivariate normality is not reject then report Maximum Likehood estimations (only the first lines of the output are presented!).

 lavaan (0.5-23.1097) converged normally after 30 iterations  
  Number of observations              717  
  Estimator                                  ML   Robust  
  Minimum Function Test Statistic        13.090    7.469  
  Degrees of freedom                           5      5  
  P-value (Chi-square)                     0.023    0.188  
  Scaling correction factor                         1.753  
   for the Satorra-Bentler correction  


5th Step: Get the necessary plots to visualise your results.

 library(semPlot)  
 semPaths(fit, intercepts=F, layout="tree", exoCov = T, fade=FALSE, node.label.cex = 7, sizeMan=6)   
 semPaths(fit, what='std', layout="tree", intercepts=F, node.label.cex = 7, residuals = T, sizeMan=6, edge.label.cex=1.25, title=F, exoCov = T, fade=F)   

6th Step: If you need a publication quality image (12cm x 8 cm, 300dpi) then create it using the code:

 png("/home/YOUR_HOME_FOLDER_HERE/std_coeffs_model.png", res = 300, units = "mm", width=120, height=80)  
 semPaths(fit, what='std', layout="tree", node.label.cex = 7, residuals = TRUE, sizeMan=6, edge.label.cex=1.25, title=FALSE, exoCov = FALSE, fade=FALSE)  
 dev.off()  


Enjoy!

Comments