> # principles and practice of sem, 5th ed. > # rex b. kline, guilford press > > # chapter 11, table 11.2, analysis 1 > # fit two nonnested path models by romney et al. (1992) > # to the same correlation matrix and plausible > # standard deviations, generate AIC and BIC > > # 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:24:27 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 psychosomatic path model > > somatic.model <- ' + # regressions + morale ~ ses + dysfunction + relations ~ morale + symptoms ~ morale + # without the zero constraint listed next, + # lavaan automatically specifies correlated + # disturbances for symptoms and relations, + # but their disturbances are independent in + # figure 11.1 + symptoms ~~ 0*relations + # unanalyzed association between ses and dysfunction + # automatically specified ' > > # specify conventional medical model > > medical.model <- ' + # regressions + ses ~ symptoms + dysfunction + morale ~ symptoms + ses + relations ~ dysfunction + morale + # unanalyzed association between symptoms and dysfunction + # automatically specified ' > > # fit models to sample covariance matrix, N = 469 > # variances and covariance of measured exogenous > # variables are free parameters > # variances calculated with N in the denominator > > somatic <- lavaan::sem(somatic.model, sample.cov = romney.cov, + sample.nobs = 469, fixed.x = FALSE, sample.cov.rescale = FALSE) > > # request output > lavaan::summary(somatic, fit.measures = TRUE, rsquare = TRUE) lavaan 0.6.15 ended normally after 1 iteration Estimator ML Optimization method NLMINB Number of model parameters 10 Number of observations 469 Model Test User Model: Test statistic 40.488 Degrees of freedom 5 P-value (Chi-square) 0.000 Model Test Baseline Model: Test statistic 390.816 Degrees of freedom 9 P-value 0.000 User Model versus Baseline Model: Comparative Fit Index (CFI) 0.907 Tucker-Lewis Index (TLI) 0.833 Loglikelihood and Information Criteria: Loglikelihood user model (H0) -8572.844 Loglikelihood unrestricted model (H1) -8552.599 Akaike (AIC) 17165.687 Bayesian (BIC) 17207.193 Sample-size adjusted Bayesian (SABIC) 17175.455 Root Mean Square Error of Approximation: RMSEA 0.123 90 Percent confidence interval - lower 0.090 90 Percent confidence interval - upper 0.159 P-value H_0: RMSEA <= 0.050 0.000 P-value H_0: RMSEA >= 0.080 0.982 Standardized Root Mean Square Residual: SRMR 0.065 Parameter Estimates: Standard errors Standard Information Expected Information saturated (h1) model Structured Regressions: Estimate Std.Err z-value P(>|z|) morale ~ ses 0.043 0.007 6.217 0.000 dysfunction 0.016 0.009 1.897 0.058 relations ~ morale 0.485 0.037 13.184 0.000 symptoms ~ morale 2.403 0.178 13.535 0.000 Covariances: Estimate Std.Err z-value P(>|z|) .relations ~~ .symptoms 0.000 ses ~~ dysfunction 110.779 22.821 4.854 0.000 Variances: Estimate Std.Err z-value P(>|z|) .morale 12.699 0.829 15.313 0.000 .relations 8.938 0.584 15.313 0.000 .symptoms 207.820 13.571 15.313 0.000 ses 610.090 39.840 15.313 0.000 dysfunction 380.250 24.831 15.313 0.000 R-Square: Estimate morale 0.097 relations 0.270 symptoms 0.281 > > # print residuals > lavaan::residuals(somatic, type = "standardized.mplus") $type [1] "standardized.mplus" $cov morale reltns symptm ses dysfnc morale 0.000 relations 0.000 0.000 symptoms 0.000 0.427 0.000 ses 0.000 -1.776 4.542 0.000 dysfunction 0.000 -3.291 2.549 0.000 0.000 > lavaan::residuals(somatic, type = "normalized") $type [1] "normalized" $cov morale reltns symptm ses dysfnc morale 0.000 relations 0.000 0.000 symptoms 0.000 0.300 0.000 ses 0.000 -1.424 3.711 0.000 dysfunction 0.000 -2.769 2.142 0.000 0.000 > lavaan::residuals(somatic, type = "cor.bollen") $type [1] "cor.bollen" $cov morale reltns symptm ses dysfnc morale 0.000 relations 0.000 0.000 symptoms 0.000 0.014 0.000 ses 0.000 -0.066 0.181 0.000 dysfunction 0.000 -0.128 0.100 0.000 0.000 > > medical <- lavaan::sem(medical.model, sample.cov=romney.cov, + sample.nobs = 469, fixed.x = FALSE, sample.cov.rescale = FALSE) > > # request output > lavaan::summary(medical, fit.measures = TRUE, rsquare = TRUE) lavaan 0.6.15 ended normally after 1 iteration Estimator ML Optimization method NLMINB Number of model parameters 12 Number of observations 469 Model Test User Model: Test statistic 3.245 Degrees of freedom 3 P-value (Chi-square) 0.355 Model Test Baseline Model: Test statistic 400.859 Degrees of freedom 9 P-value 0.000 User Model versus Baseline Model: Comparative Fit Index (CFI) 0.999 Tucker-Lewis Index (TLI) 0.998 Loglikelihood and Information Criteria: Loglikelihood user model (H0) -8554.222 Loglikelihood unrestricted model (H1) -8552.599 Akaike (AIC) 17132.444 Bayesian (BIC) 17182.251 Sample-size adjusted Bayesian (SABIC) 17144.166 Root Mean Square Error of Approximation: RMSEA 0.013 90 Percent confidence interval - lower 0.000 90 Percent confidence interval - upper 0.080 P-value H_0: RMSEA <= 0.050 0.742 P-value H_0: RMSEA >= 0.080 0.050 Standardized Root Mean Square Residual: SRMR 0.016 Parameter Estimates: Standard errors Standard Information Expected Information saturated (h1) model Structured Regressions: Estimate Std.Err z-value P(>|z|) ses ~ symptoms 0.448 0.063 7.110 0.000 dysfunction 0.221 0.055 4.019 0.000 morale ~ symptoms 0.107 0.009 11.756 0.000 ses 0.021 0.006 3.291 0.001 relations ~ dysfunction -0.024 0.007 -3.335 0.001 morale 0.504 0.037 13.745 0.000 Covariances: Estimate Std.Err z-value P(>|z|) symptoms ~~ dysfunction 59.670 15.553 3.836 0.000 Variances: Estimate Std.Err z-value P(>|z|) .ses 521.598 34.062 15.313 0.000 .morale 9.884 0.645 15.313 0.000 .relations 8.732 0.570 15.313 0.000 symptoms 289.000 18.872 15.313 0.000 dysfunction 380.250 24.831 15.313 0.000 R-Square: Estimate ses 0.145 morale 0.297 relations 0.290 > > # print residuals > lavaan::residuals(medical, 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(medical, type = "normalized") $type [1] "normalized" $cov ses morale reltns symptm dysfnc ses 0.000 morale 0.000 0.000 relations -0.901 -0.080 -0.069 symptoms 0.000 0.000 0.573 0.000 dysfunction 0.000 0.680 0.370 0.000 0.000 > lavaan::residuals(medical, 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