> # principles and practice of sem, 5th ed. > # rex b. kline, guilford press, 2023 > > # chapter 11, table 11.2, analysis 2 > # fit equivalent versions of the romney et al. (1992) > # conventional medical model to the same data > > # 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() [1] "Thu Apr 13 21:22:50 2023" > > v <- R.Version() > print(paste0(v$language, " version ", v$major, ".", + v$minor, " (", v$year, "-", v$month, "-", v$day, ")")) [1] "R version 4.2.3 (2023-03-15)" > > library(lavaan) This is lavaan 0.6-15 lavaan is FREE software! Please report any bugs. > > # get citation information > citation("lavaan", auto = TRUE) To cite package ‘lavaan’ in publications use: Rosseel Y, Jorgensen TD, Rockwood N (2023). _lavaan: Latent Variable Analysis_. R package version 0.6-15, . A BibTeX entry for LaTeX users is @Manual{, title = {lavaan: Latent Variable Analysis}, author = {Yves Rosseel and Terrence D. Jorgensen and Nicholas Rockwood}, year = {2023}, note = {R package version 0.6-15}, url = {https://CRAN.R-project.org/package=lavaan}, } > > # input the correlations in lower diagnonal form > romneyLower.cor <- ' + 1.00 + .53 1.00 + .15 .18 1.00 + .52 .29 -.05 1.00 + .30 .34 .23 .09 1.00 ' > > # name the variables and convert to full correlation matrix > romney.cor <- lavaan::getCov(romneyLower.cor, names = c("morale", "symptoms", + "dysfunction", "relations", "ses")) > > # display the correlations > romney.cor morale symptoms dysfunction relations ses morale 1.00 0.53 0.15 0.52 0.30 symptoms 0.53 1.00 0.18 0.29 0.34 dysfunction 0.15 0.18 1.00 -0.05 0.23 relations 0.52 0.29 -0.05 1.00 0.09 ses 0.30 0.34 0.23 0.09 1.00 > > # add the standard deviations and convert to covariances > romney.cov <- lavaan::cor2cov(romney.cor, sds = c(3.75,17.00,19.50, + 3.50,24.70)) > > # display the covariances > romney.cov morale symptoms dysfunction relations ses morale 14.06250 33.7875 10.96875 6.8250 27.7875 symptoms 33.78750 289.0000 59.67000 17.2550 142.7660 dysfunction 10.96875 59.6700 380.25000 -3.4125 110.7795 relations 6.82500 17.2550 -3.41250 12.2500 7.7805 ses 27.78750 142.7660 110.77950 7.7805 610.0900 > > # specify fit statistics for abbreviated output > fit.stats = c("chisq", "df", "pvalue", "cfi", "srmr", + "rmsea", "rmsea.ci.lower", "rmsea.ci.upper") > > # specify original and 3 equivalent models > > # original conventional medical model > # figure 11.2(a) > > original.model <- ' + ses ~ symptoms + dysfunction + morale ~ symptoms + ses + relations ~ dysfunction + morale ' > > # equivalent model 1 > # figure 11.2(b) > > equivalent1.model <- ' + ses ~ symptoms + dysfunction + morale ~ symptoms + ses + relations ~ dysfunction + morale + dysfunction ~ symptoms ' > > # equivalent model 2 > # figure 11.3(c) > > equivalent2.model <- ' + ses ~ symptoms + morale ~ symptoms + ses + relations ~ dysfunction + morale + dysfunction ~ symptoms + ses ' > > # equivalent model 3 > # figure 11.3(d) > > equivalent3.model <- ' + ses ~ symptoms + morale + morale ~ symptoms + relations ~ dysfunction + morale + dysfunction ~ symptoms + ses ' > > # fit models to data > > original <- lavaan::sem(original.model, sample.cov = romney.cov, + sample.nobs = 469, fixed.x = FALSE, sample.cov.rescale = FALSE) > > equivalent1 <- lavaan::sem(equivalent1.model, sample.cov = romney.cov, + sample.nobs = 469, fixed.x = FALSE, sample.cov.rescale = FALSE) > > equivalent2 <- lavaan::sem(equivalent2.model, sample.cov = romney.cov, + sample.nobs = 469, fixed.x = FALSE, sample.cov.rescale = FALSE) > > equivalent3 <- lavaan::sem(equivalent3.model, sample.cov = romney.cov, + sample.nobs = 469, fixed.x = FALSE, sample.cov.rescale = FALSE) > > # global fit statistics > # same for all models > > lavaan::fitMeasures(original, fit.stats) chisq df pvalue cfi srmr 3.245 3.000 0.355 0.999 0.016 rmsea rmsea.ci.lower rmsea.ci.upper 0.013 0.000 0.080 > lavaan::fitMeasures(equivalent1, fit.stats) chisq df pvalue cfi srmr 3.245 3.000 0.355 0.999 0.016 rmsea rmsea.ci.lower rmsea.ci.upper 0.013 0.000 0.080 > lavaan::fitMeasures(equivalent2, fit.stats) chisq df pvalue cfi srmr 3.245 3.000 0.355 0.999 0.016 rmsea rmsea.ci.lower rmsea.ci.upper 0.013 0.000 0.080 > lavaan::fitMeasures(equivalent3, fit.stats) chisq df pvalue cfi srmr 3.245 3.000 0.355 0.999 0.016 rmsea rmsea.ci.lower rmsea.ci.upper 0.013 0.000 0.080 > > # residuals > # same for all models for each of residual > > # raw residuals > lavaan::residuals(original, type = "raw") $type [1] "raw" $cov ses morale reltns symptm dysfnc ses 0.000 morale 0.000 0.000 relations -3.611 -0.055 -0.055 symptoms 0.000 0.000 1.640 0.000 dysfunction 0.000 2.321 1.169 0.000 0.000 > lavaan::residuals(equivalent1, type = "raw") $type [1] "raw" $cov ses morale reltns dysfnc symptm ses 0.000 morale 0.000 0.000 relations -3.611 -0.055 -0.055 dysfunction 0.000 2.321 1.169 0.000 symptoms 0.000 0.000 1.640 0.000 0.000 > lavaan::residuals(equivalent2, type = "raw") $type [1] "raw" $cov ses morale reltns dysfnc symptm ses 0.000 morale 0.000 0.000 relations -3.611 -0.055 -0.055 dysfunction 0.000 2.321 1.169 0.000 symptoms 0.000 0.000 1.640 0.000 0.000 > lavaan::residuals(equivalent3, type = "raw") $type [1] "raw" $cov ses morale reltns dysfnc symptm ses 0.000 morale 0.000 0.000 relations -3.611 -0.055 -0.055 dysfunction 0.000 2.321 1.169 0.000 symptoms 0.000 0.000 1.640 0.000 0.000 > > # standardized residuals > lavaan::residuals(original, type = "standardized.mplus") $type [1] "standardized.mplus" $cov ses morale reltns symptm dysfnc ses 0.000 morale 0.000 0.000 relations -1.161 -1.818 NA symptoms 0.000 0.000 0.833 0.000 dysfunction 0.000 0.842 0.862 0.000 0.000 > lavaan::residuals(equivalent1, type = "standardized.mplus") $type [1] "standardized.mplus" $cov ses morale reltns dysfnc symptm ses 0.000 morale 0.000 0.000 relations -1.161 -1.818 NA dysfunction 0.000 0.842 0.862 0.000 symptoms 0.000 0.000 0.833 0.000 0.000 > lavaan::residuals(equivalent2, type = "standardized.mplus") $type [1] "standardized.mplus" $cov ses morale reltns dysfnc symptm ses 0.000 morale 0.000 0.000 relations -1.161 -1.818 NA dysfunction 0.000 0.842 0.862 0.000 symptoms 0.000 0.000 0.833 0.000 0.000 > lavaan::residuals(equivalent3, type = "standardized.mplus") $type [1] "standardized.mplus" $cov ses morale reltns dysfnc symptm ses 0.000 morale 0.000 0.000 relations -1.161 -1.818 NA dysfunction 0.000 0.842 0.862 0.000 symptoms 0.000 0.000 0.833 0.000 0.000 > > # correlation residuals > lavaan::residuals(original, type = "cor.bollen") $type [1] "cor.bollen" $cov ses morale reltns symptm dysfnc ses 0.000 morale 0.000 0.000 relations -0.041 -0.003 0.000 symptoms 0.000 0.000 0.028 0.000 dysfunction 0.000 0.032 0.017 0.000 0.000 > lavaan::residuals(equivalent1, type = "cor.bollen") $type [1] "cor.bollen" $cov ses morale reltns dysfnc symptm ses 0.000 morale 0.000 0.000 relations -0.041 -0.003 0.000 dysfunction 0.000 0.032 0.017 0.000 symptoms 0.000 0.000 0.028 0.000 0.000 > lavaan::residuals(equivalent2, type = "cor.bollen") $type [1] "cor.bollen" $cov ses morale reltns dysfnc symptm ses 0.000 morale 0.000 0.000 relations -0.041 -0.003 0.000 dysfunction 0.000 0.032 0.017 0.000 symptoms 0.000 0.000 0.028 0.000 0.000 > lavaan::residuals(equivalent3, type = "cor.bollen") $type [1] "cor.bollen" $cov ses morale reltns dysfnc symptm ses 0.000 morale 0.000 0.000 relations -0.041 -0.003 0.000 dysfunction 0.000 0.032 0.017 0.000 symptoms 0.000 0.000 0.028 0.000 0.000 > > # parameter estimates > # these results vary over models > > lavaan::summary(original, fit.measures = FALSE, header = FALSE, + standardized = TRUE) Parameter Estimates: Standard errors Standard Information Expected Information saturated (h1) model Structured Regressions: Estimate Std.Err z-value P(>|z|) Std.lv Std.all ses ~ symptoms 0.448 0.063 7.110 0.000 0.448 0.309 dysfunction 0.221 0.055 4.019 0.000 0.221 0.174 morale ~ symptoms 0.107 0.009 11.756 0.000 0.107 0.484 ses 0.021 0.006 3.291 0.001 0.021 0.135 relations ~ dysfunction -0.024 0.007 -3.335 0.001 -0.024 -0.131 morale 0.504 0.037 13.745 0.000 0.504 0.538 Covariances: Estimate Std.Err z-value P(>|z|) Std.lv Std.all symptoms ~~ dysfunction 59.670 15.553 3.836 0.000 59.670 0.180 Variances: Estimate Std.Err z-value P(>|z|) Std.lv Std.all .ses 521.598 34.062 15.313 0.000 521.598 0.855 .morale 9.884 0.645 15.313 0.000 9.884 0.703 .relations 8.732 0.570 15.313 0.000 8.732 0.710 symptoms 289.000 18.872 15.313 0.000 289.000 1.000 dysfunction 380.250 24.831 15.313 0.000 380.250 1.000 > lavaan::summary(equivalent1, fit.measures = FALSE, header = FALSE, + standardized = TRUE) Parameter Estimates: Standard errors Standard Information Expected Information saturated (h1) model Structured Regressions: Estimate Std.Err z-value P(>|z|) Std.lv Std.all ses ~ symptoms 0.448 0.063 7.110 0.000 0.448 0.309 dysfunction 0.221 0.055 4.019 0.000 0.221 0.174 morale ~ symptoms 0.107 0.009 11.756 0.000 0.107 0.484 ses 0.021 0.006 3.291 0.001 0.021 0.135 relations ~ dysfunction -0.024 0.007 -3.335 0.001 -0.024 -0.131 morale 0.504 0.037 13.745 0.000 0.504 0.538 dysfunction ~ symptoms 0.206 0.052 3.963 0.000 0.206 0.180 Variances: Estimate Std.Err z-value P(>|z|) Std.lv Std.all .ses 521.598 34.062 15.313 0.000 521.598 0.855 .morale 9.884 0.645 15.313 0.000 9.884 0.703 .relations 8.732 0.570 15.313 0.000 8.732 0.710 .dysfunction 367.930 24.027 15.313 0.000 367.930 0.968 symptoms 289.000 18.872 15.313 0.000 289.000 1.000 > lavaan::summary(equivalent2, fit.measures = FALSE, header = FALSE, + standardized = TRUE) Parameter Estimates: Standard errors Standard Information Expected Information saturated (h1) model Structured Regressions: Estimate Std.Err z-value P(>|z|) Std.lv Std.all ses ~ symptoms 0.494 0.063 7.830 0.000 0.494 0.340 morale ~ symptoms 0.107 0.009 11.756 0.000 0.107 0.484 ses 0.021 0.006 3.291 0.001 0.021 0.135 relations ~ dysfunction -0.024 0.007 -3.335 0.001 -0.024 -0.131 morale 0.504 0.037 13.745 0.000 0.504 0.538 dysfunction ~ symptoms 0.132 0.054 2.424 0.015 0.132 0.115 ses 0.151 0.037 4.019 0.000 0.151 0.191 Variances: Estimate Std.Err z-value P(>|z|) Std.lv Std.all .ses 539.564 35.235 15.313 0.000 539.564 0.884 .morale 9.884 0.645 15.313 0.000 9.884 0.703 .relations 8.732 0.570 15.313 0.000 8.732 0.710 .dysfunction 355.679 23.227 15.313 0.000 355.679 0.935 symptoms 289.000 18.872 15.313 0.000 289.000 1.000 > lavaan::summary(equivalent3, fit.measures = FALSE, header = FALSE, + standardized = TRUE) Parameter Estimates: Standard errors Standard Information Expected Information saturated (h1) model Structured Regressions: Estimate Std.Err z-value P(>|z|) Std.lv Std.all ses ~ symptoms 0.366 0.074 4.972 0.000 0.366 0.252 morale 1.097 0.333 3.291 0.001 1.097 0.167 morale ~ symptoms 0.117 0.009 13.535 0.000 0.117 0.530 relations ~ dysfunction -0.024 0.007 -3.335 0.001 -0.024 -0.131 morale 0.504 0.037 13.745 0.000 0.504 0.538 dysfunction ~ symptoms 0.132 0.054 2.424 0.015 0.132 0.115 ses 0.151 0.037 4.019 0.000 0.151 0.191 Variances: Estimate Std.Err z-value P(>|z|) Std.lv Std.all .ses 527.387 34.440 15.313 0.000 527.387 0.864 .morale 10.112 0.660 15.313 0.000 10.112 0.719 .relations 8.732 0.570 15.313 0.000 8.732 0.710 .dysfunction 355.679 23.227 15.313 0.000 355.679 0.935 symptoms 289.000 18.872 15.313 0.000 289.000 1.000