#import data into RStudio library(haven) UETALQ_survey_data <- read_sav("C:/Users/gbro008/Google Drive/1995 to 2025 All PUBS/Teachers/working folders/2017 Xu & Brown TALQ/UETALQ-survey-data.sav") View(UETALQ_survey_data) #lavaan code UETALQ 24 item dichotomous test analysis #create model TALQ.model <- 'TALQ =~ q1 +q2 + q3 +q4 +q5 + q6 + q7 + q8 + q9 + q10 + q11 + q12 + q13 + q14 + q15 + q16 + q17 + q18 + q19 + q20 + q21 + q22 + q23 + q24' #cfa analysis with WLS=ADF estimator, ordered command to inform CFA that this is ordered scores TALQ_fit <-cfa (TALQ.model, data=UETALQ_survey_data, ordered=c("q1", "q2", "q3", "q4", "q5", "q6", "q7", "q8", "q9", "q10", "q11", "q12", "q13", "q14", "q15", "q16", "q17", "q18", "q19", "q20", "q21", "q22", "q23", "q24"), estimator="wls") #standard output of fit and values summary(TALQ_fit, standardized=TRUE) #detailed fit indices fitmeasures(TALQ_fit) #to get gamma hat fit index library(semTools) moreFitIndices(TALQ_fit) #to get x2/df ratio and p-value-thanks to Terry Jorgensen UvA (amsterdam) fm <- fitMeasures(TALQ_fit) fm[["chisq"]] / fm[["df"]] fm["pvalue"] #get a picture,standardised scores shown library(lavaanPlot) lavaanPlot(model = TALQ_fit, node_options = list(shape = "box", fontname = "Helvetica"), edge_options = list(color = "grey"), coefs = TRUE, stand=TRUE)