#install required libraries library(lavaan) library(semPlot) #to create 8 factor SCoA model SCoA6.model <- ' Bad =~ bd1 + bd2 + bd3 + bd4 + bd5 CE =~ ce1 + ce2 + ce3 + ce4 + ce5 + ce6 IG =~ ig1 + ig2 + ig3 PE =~ pe1 + pe2 SF =~ sf1 + sf2 + sf3 + sf4 SI =~ si1 + si2 + si3 + si4 + si5 SQ =~ sq1 + sq2 TI =~ ti1 + ti2 + ti3 + ti4 + ti5 + ti6 ' #do CFA analysis of model SCoA_fit <- cfa (SCoA6.model, data=NZSCoAVI) #get results of cfa summary (SCoA_fit, standardized=TRUE, fit.measures = TRUE, rsquare=True) #to get gamma hat fit index library(semTools) moreFitIndices(SCoA_fit) #to get x2/df ratio and p-value fm <- fitMeasures(SCoA_fit) fm[["chisq"]] / fm[["df"]] # upper/right-tail p value #ENTER VALUE FROM PREVIOUS COMMAND INTO q=xxxxx #enter df = 1 pchisq(q = xxxx , df = 1, lower.tail = FALSE) #to get conventional correlated factors diagram semPaths(SCoA_fit, intercept = FALSE, whatLabel = "std", residuals = FALSE, exoCov = TRUE) #to get lavaanplot style chart library(LavaanPlot) lavaanPlot(model = SCoA_fit, node_options = list(shape = "box", fontname = "Helvetica"), edge_options = list(color = "grey"), coefs = TRUE, covs = TRUE, stars = TRUE)