# principles and practice of sem, 5th ed. # rex b. kline, guilford press, 2023 # chapter 15, table 15.1, analysis 4 # partial SR model of cognitive level and symptom unawareness # with single-indicator specification # to avoid the problem that some R packages share the same name # for different functions, all functions are specified next as # package::function # which prevents masking, or the default hiding of # a function with a redundant name from a package used next date() v <- R.Version() print(paste0(v$language, " version ", v$major, ".", v$minor, " (", v$year, "-", v$month, "-", v$day, ")")) library(lavaan) library(semTools) # get citation information citation("lavaan", auto = TRUE) citation("semTools", auto = TRUE) # 6 csb tests # isl, international shopping list test # islr, international shopping list delayed recall # gml, groton maze learning test # gmr, groton maze learning rask delayed recall # ocl, one-card learning test # cpal, continuous paired associate learning test # input the correlations in lower diagnonal form sauveLower.cor <- ' 1.000 .753 1.000 .329 .334 1.000 .316 .307 .672 1.000 .398 .347 .411 .451 1.000 .430 .439 .526 .532 .470 1.000 -.144 -.155 -.215 -.108 -.146 -.143 1.000 ' # name the variables and convert to full correlation matrix sauve.cor <- lavaan::getCov(sauveLower.cor, names = c("isl", "islr", "gml", "gmr", "ocl", "cpal", "sumd")) # add the standard deviations and convert to covariances sauve.cov <- lavaan::cor2cov(sauve.cor, sds = c(4.713,2.670,1.664, 1.009,.116,.121,1.225)) # display correlations and covariances options(width = "120") sauve.cor sauve.cov # maccallum-rmsea for whole model # exact fit test # power at N = 193 semTools::findRMSEApower(0, .05, 12, 193, .05, 1) # minimum N for power at least .90 semTools::findRMSEAsamplesize(0, .05, 12, .90, .05, 1) # sumd reliability is median coefficient among # .77, .98, .75, .68 from rafford et al. 2010 # median = .76, error variance fixed to # (1 - .76) * 1.225**2 = .360 sauveSUMD.model <- ' # measurement model # cognitive factor with error correlations Cognitive =~ isl + islr + gml + ocl + cpal + gmr isl ~~ islr gml ~~ gmr # sumd single indicator with reliability SUMDFactor =~ sumd sumd ~~ .360*sumd # structural model SUMDFactor ~ Cognitive ' # fit model to data sauveSUMD <- lavaan::sem(sauveSUMD.model, sample.cov = sauve.cov, sample.nobs = 193) lavaan::summary(sauveSUMD, fit.measures = TRUE, standardized = TRUE, rsquare = TRUE) lavaan::standardizedSolution(sauveSUMD) lavaan::fitted(sauveSUMD) # predicted correlation matrix for indicators lavaan::lavInspect(sauveSUMD, "cor.ov") # predicted correlation matrix for factors lavaan::lavInspect(sauveSUMD, "cor.lv") lavaan::residuals(sauveSUMD, type = "raw") lavaan::residuals(sauveSUMD, type = "standardized.mplus") lavaan::residuals(sauveSUMD, type = "cor.bollen") lavaan::modindices(sauveSUMD)