> # principles and practice of sem, 5th ed. > # rex b. kline, guilford press, 2023 > > # chapter 18, table 18.1, analysis 1 > # single-factor model for ordinal data, > # option WLSMV (DWLS estimator with mean- > # and variance-corrected test statistic > # and robust standard errors) > > # single-factor model for ordinal data, > # wlsmv estimator with robust standard errors > > # 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] "Fri Apr 14 08:41:53 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. > > 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}, } > > # read in external comma separated values (.csv) file, > # radloff.csv > > # ** IMPORTANT ** > # set the R working directory to the path for the location > # of the data file on your own computer > # the specification listed next is for my computer > # and will not work on your computer > > setwd("C:/Users/Rex Kline/Desktop/") > #display working directory > getwd() [1] "C:/Users/Rex Kline/Desktop" > > # copy data from csv file to a data frame > > radloff.data = read.csv("radloff.csv") > > # 4-point likert scale response format > # 0 = "< 1 day", 1 = "1-2 days", > # 3 = "3-4 days", 4 = "5-7 days" > > # display for each item frequencies, > # cumulative proportions, normal deviates > # for cumulative proportions, and thresholds > > # item statistics > > # item x1 > > x1_frequencies <- table(radloff.data$x1) > x1_cum_proportions <- cumsum(table(radloff.data$x1)/2004) > x1_thresholds <- qnorm(cumsum(table(radloff.data$x1)/2004)) > x1_frequencies 0 1 2 3 1563 285 95 61 > x1_cum_proportions 0 1 2 3 0.7799401 0.9221557 0.9695609 1.0000000 > x1_thresholds 0 1 2 3 0.771991 1.419722 1.874379 Inf > > # item x2 > > x2_frequencies <- table(radloff.data$x2) > x2_cum_proportions <- cumsum(table(radloff.data$x2)/2004) > x2_thresholds <- qnorm(cumsum(table(radloff.data$x2)/2004)) > x2_frequencies 0 1 2 3 1707 174 62 61 > x2_cum_proportions 0 1 2 3 0.8517964 0.9386228 0.9695609 1.0000000 > x2_thresholds 0 1 2 3 1.044169 1.543314 1.874379 Inf > > # item x3 > > x3_frequencies <- table(radloff.data$x3) > x3_cum_proportions <- cumsum(table(radloff.data$x3)/2004) > x3_thresholds <- qnorm(cumsum(table(radloff.data$x3)/2004)) > x3_frequencies 0 1 2 3 1414 340 117 133 > x3_cum_proportions 0 1 2 3 0.7055888 0.8752495 0.9336327 1.0000000 > x3_thresholds 0 1 2 3 0.5405434 1.1515623 1.5034054 Inf > > # item x4 > > x4_frequencies <- table(radloff.data$x4) > x4_cum_proportions <- cumsum(table(radloff.data$x4)/2004) > x4_thresholds <- qnorm(cumsum(table(radloff.data$x4)/2004)) > x4_frequencies 0 1 2 3 1229 457 184 134 > x4_cum_proportions 0 1 2 3 0.6132735 0.8413174 0.9331337 1.0000000 > x4_thresholds 0 1 2 3 0.2878611 0.9998868 1.4995441 Inf > > # item x5 > > x5_frequencies <- table(radloff.data$x5) > x5_cum_proportions <- cumsum(table(radloff.data$x5)/2004) > x5_thresholds <- qnorm(cumsum(table(radloff.data$x5)/2004)) > x5_frequencies 0 1 2 3 1426 367 124 87 > x5_cum_proportions 0 1 2 3 0.7115768 0.8947106 0.9565868 1.0000000 > x5_thresholds 0 1 2 3 0.5579972 1.2519754 1.7123817 Inf > > # specify 1-factor model > > radloff.model <- ' + Depression =~ x1 + x2 + x3 + x4 + x5 ' > > # analysis options specify that all > # observed variables are ordinal > # estimator is mean- and variance-adjusted weighted least squares > # with computation of robust standard errors > # parameterization is delta > # threshold parameter estimates are just the sample values > > # a special symbol in the output, “~*~,” > # represents scaling factors for the variances > # of latent response variables, such as 1.0 in > # delta scaling, or their implied variances after > # fixing the variances of their error terms to 1.0 > # in theta scaling > > radloff <- lavaan::cfa(radloff.model, data = radloff.data, + parameterization = "delta", estimator = "wlsmv", + ordered = TRUE) > > # parameter estimates > > # note that loadings and error variances refer > # to latent response variables, but thresholds > # refer to the observed likert-scale items > lavaan::summary(radloff, fit = TRUE, standardized = TRUE, + rsquare = TRUE) lavaan 0.6.15 ended normally after 18 iterations Estimator DWLS Optimization method NLMINB Number of model parameters 20 Number of observations 2004 Model Test User Model: Standard Scaled Test Statistic 8.786 17.895 Degrees of freedom 5 5 P-value (Chi-square) 0.118 0.003 Scaling correction factor 0.494 Shift parameter 0.104 simple second-order correction Model Test Baseline Model: Test statistic 3117.695 2336.488 Degrees of freedom 10 10 P-value 0.000 0.000 Scaling correction factor 1.336 User Model versus Baseline Model: Comparative Fit Index (CFI) 0.999 0.994 Tucker-Lewis Index (TLI) 0.998 0.989 Robust Comparative Fit Index (CFI) 0.988 Robust Tucker-Lewis Index (TLI) 0.976 Root Mean Square Error of Approximation: RMSEA 0.019 0.036 90 Percent confidence interval - lower 0.000 0.019 90 Percent confidence interval - upper 0.040 0.055 P-value H_0: RMSEA <= 0.050 0.995 0.887 P-value H_0: RMSEA >= 0.080 0.000 0.000 Robust RMSEA 0.061 90 Percent confidence interval - lower 0.032 90 Percent confidence interval - upper 0.093 P-value H_0: Robust RMSEA <= 0.050 0.236 P-value H_0: Robust RMSEA >= 0.080 0.177 Standardized Root Mean Square Residual: SRMR 0.022 0.022 Parameter Estimates: Standard errors Robust.sem Information Expected Information saturated (h1) model Unstructured Latent Variables: Estimate Std.Err z-value P(>|z|) Std.lv Std.all Depression =~ x1 1.000 0.609 0.609 x2 1.070 0.065 16.572 0.000 0.651 0.651 x3 1.285 0.065 19.815 0.000 0.782 0.782 x4 1.004 0.056 17.924 0.000 0.611 0.611 x5 1.266 0.065 19.391 0.000 0.771 0.771 Intercepts: Estimate Std.Err z-value P(>|z|) Std.lv Std.all .x1 0.000 0.000 0.000 .x2 0.000 0.000 0.000 .x3 0.000 0.000 0.000 .x4 0.000 0.000 0.000 .x5 0.000 0.000 0.000 Depression 0.000 0.000 0.000 Thresholds: Estimate Std.Err z-value P(>|z|) Std.lv Std.all x1|t1 0.772 0.031 24.697 0.000 0.772 0.772 x1|t2 1.420 0.041 34.535 0.000 1.420 1.420 x1|t3 1.874 0.056 33.628 0.000 1.874 1.874 x2|t1 1.044 0.034 30.421 0.000 1.044 1.044 x2|t2 1.543 0.044 34.894 0.000 1.543 1.543 x2|t3 1.874 0.056 33.628 0.000 1.874 1.874 x3|t1 0.541 0.030 18.297 0.000 0.541 0.541 x3|t2 1.152 0.036 32.062 0.000 1.152 1.152 x3|t3 1.503 0.043 34.830 0.000 1.503 1.503 x4|t1 0.288 0.028 10.125 0.000 0.288 0.288 x4|t2 1.000 0.034 29.639 0.000 1.000 1.000 x4|t3 1.500 0.043 34.822 0.000 1.500 1.500 x5|t1 0.558 0.030 18.821 0.000 0.558 0.558 x5|t2 1.252 0.038 33.262 0.000 1.252 1.252 x5|t3 1.712 0.049 34.630 0.000 1.712 1.712 Variances: Estimate Std.Err z-value P(>|z|) Std.lv Std.all .x1 0.630 0.630 0.630 .x2 0.576 0.576 0.576 .x3 0.388 0.388 0.388 .x4 0.627 0.627 0.627 .x5 0.406 0.406 0.406 Depression 0.370 0.034 10.937 0.000 1.000 1.000 Scales y*: Estimate Std.Err z-value P(>|z|) Std.lv Std.all x1 1.000 1.000 1.000 x2 1.000 1.000 1.000 x3 1.000 1.000 1.000 x4 1.000 1.000 1.000 x5 1.000 1.000 1.000 R-Square: Estimate x1 0.370 x2 0.424 x3 0.612 x4 0.373 x5 0.594 > > # standardized estimates with standard errors > lavaan::standardizedSolution(radloff) lhs op rhs est.std se z pvalue ci.lower ci.upper 1 Depression =~ x1 0.609 0.028 21.874 0 0.554 0.663 2 Depression =~ x2 0.651 0.029 22.136 0 0.593 0.709 3 Depression =~ x3 0.782 0.020 38.599 0 0.742 0.822 4 Depression =~ x4 0.611 0.023 26.935 0 0.566 0.655 5 Depression =~ x5 0.771 0.021 35.920 0 0.729 0.813 6 x1 | t1 0.772 0.031 24.697 0 0.711 0.833 7 x1 | t2 1.420 0.041 34.535 0 1.339 1.500 8 x1 | t3 1.874 0.056 33.628 0 1.765 1.984 9 x2 | t1 1.044 0.034 30.421 0 0.977 1.111 10 x2 | t2 1.543 0.044 34.894 0 1.457 1.630 11 x2 | t3 1.874 0.056 33.628 0 1.765 1.984 12 x3 | t1 0.541 0.030 18.297 0 0.483 0.598 13 x3 | t2 1.152 0.036 32.062 0 1.081 1.222 14 x3 | t3 1.503 0.043 34.830 0 1.419 1.588 15 x4 | t1 0.288 0.028 10.125 0 0.232 0.344 16 x4 | t2 1.000 0.034 29.639 0 0.934 1.066 17 x4 | t3 1.500 0.043 34.822 0 1.415 1.584 18 x5 | t1 0.558 0.030 18.821 0 0.500 0.616 19 x5 | t2 1.252 0.038 33.262 0 1.178 1.326 20 x5 | t3 1.712 0.049 34.630 0 1.615 1.809 21 x1 ~~ x1 0.630 0.034 18.595 0 0.563 0.696 22 x2 ~~ x2 0.576 0.038 15.046 0 0.501 0.651 23 x3 ~~ x3 0.388 0.032 12.247 0 0.326 0.450 24 x4 ~~ x4 0.627 0.028 22.635 0 0.573 0.681 25 x5 ~~ x5 0.406 0.033 12.275 0 0.341 0.471 26 Depression ~~ Depression 1.000 0.000 NA NA 1.000 1.000 27 x1 ~*~ x1 1.000 0.000 NA NA 1.000 1.000 28 x2 ~*~ x2 1.000 0.000 NA NA 1.000 1.000 29 x3 ~*~ x3 1.000 0.000 NA NA 1.000 1.000 30 x4 ~*~ x4 1.000 0.000 NA NA 1.000 1.000 31 x5 ~*~ x5 1.000 0.000 NA NA 1.000 1.000 32 x1 ~1 0.000 0.000 NA NA 0.000 0.000 33 x2 ~1 0.000 0.000 NA NA 0.000 0.000 34 x3 ~1 0.000 0.000 NA NA 0.000 0.000 35 x4 ~1 0.000 0.000 NA NA 0.000 0.000 36 x5 ~1 0.000 0.000 NA NA 0.000 0.000 37 Depression ~1 0.000 0.000 NA NA 0.000 0.000 > > # predicted correlations and residuals > > # IMPORTANT > # note that labels x1-x5 in matrices for predicted > # correlations or for residuals refer to the latent > # response variables, not the observed variables > > # model-implied correlation matrix, > # means, and thresholds > # all predicted means equal zero > # thresholds designated as, e.g., > # x1|t1 for the 1st of 3 thresholds for item x1 > lavaan::fitted(radloff) $cov x1 x2 x3 x4 x5 x1 1.000 x2 0.396 1.000 x3 0.476 0.509 1.000 x4 0.372 0.398 0.478 1.000 x5 0.469 0.502 0.603 0.471 1.000 $mean x1 x2 x3 x4 x5 0 0 0 0 0 $th x1|t1 x1|t2 x1|t3 x2|t1 x2|t2 x2|t3 x3|t1 x3|t2 x3|t3 x4|t1 x4|t2 x4|t3 x5|t1 0.772 1.420 1.874 1.044 1.543 1.874 0.541 1.152 1.503 0.288 1.000 1.500 0.558 x5|t2 x5|t3 1.252 1.712 > > # correlation residuals, z tests, and confidence > # intervals, exact-fit and close-fit tests > # based on the srmr as described by shi et al. (2020) > # all mean residuals and threshold residuals equal zero > lavaan::lavResiduals(radloff, type = "cor.bentler") $type [1] "cor.bentler" $cov x1 x2 x3 x4 x5 x1 0.000 x2 0.041 0.000 x3 -0.005 -0.029 0.000 x4 0.030 0.020 -0.024 0.000 x5 -0.046 -0.013 0.024 -0.005 0.000 $mean x1 x2 x3 x4 x5 0 0 0 0 0 $th x1|t1 x1|t2 x1|t3 x2|t1 x2|t2 x2|t3 x3|t1 x3|t2 x3|t3 x4|t1 x4|t2 x4|t3 x5|t1 0 0 0 0 0 0 0 0 0 0 0 0 0 x5|t2 x5|t3 0 0 $cov.z x1 x2 x3 x4 x5 x1 0.000 x2 2.043 0.000 x3 -0.391 -2.102 0.000 x4 1.699 1.046 -2.112 0.000 x5 -3.545 -0.918 3.610 -0.503 0.000 $mean.z x1 x2 x3 x4 x5 0 0 0 0 0 NA NA NA NA NA NA NA NA NA NA $th.z x1|t1 x1|t2 x1|t3 x2|t1 x2|t2 x2|t3 x3|t1 x3|t2 x3|t3 x4|t1 x4|t2 x4|t3 x5|t1 0 0 0 0 0 0 0 0 0 0 0 0 0 x5|t2 x5|t3 0 0 $summary cor thresholds total srmr 0.022 0.00 0.016 srmr.se 0.004 NA 0.003 srmr.exactfit.z 2.809 NA 2.809 srmr.exactfit.pvalue 0.002 NA 0.002 usrmr 0.019 0.00 0.013 usrmr.se 0.006 NA 0.001 usrmr.ci.lower 0.010 NA 0.011 usrmr.ci.upper 0.029 NA 0.016 usrmr.closefit.h0.value 0.050 0.05 0.050 usrmr.closefit.z -5.337 NA -24.829 usrmr.closefit.pvalue 1.000 NA 1.000