> # principles and practice of sem, 5th ed. > # rex b. kline, guilford press, 2023 > > # chapter 22, table 22.1, analysis 1 > # two-factor cfa model of divergent thinking > # analyzed in separate chinese and american samples > > # 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 09:25:32 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}, } > > subtest.name <- c("LM1", "LM2", "LM3", "RW1", "RW2") > > # chinese, n = 316, originality > chineseLower.cor <- ' + 1.000 + .715 1.000 + .631 .738 1.000 + .377 .408 .319 1.000 + .452 .495 .391 .445 1.000 ' > > # name the variables and convert to full correlation matrix > chinese.cor <- lavaan::getCov(chineseLower.cor, names = subtest.name) > > # add the standard deviations and convert to covariances > chinese.sd <- c(1.532, 1.878, 2.012, 1.002, 1.055) > chinese.cov <- lavaan::cor2cov(chinese.cor, sds = chinese.sd) > > # create mean vector > chinese.mean = c(1.24, 1.47, 1.86, .77, .89) > > # american, n = 302, originality > americanLower.cor <- ' + 1.000 + .519 1.000 + .543 .639 1.000 + .280 .321 .317 1.000 + .242 .380 .300 .665 1.000 ' > > # name the variables and convert to full correlation matrix > american.cor <- lavaan::getCov(americanLower.cor, names = subtest.name) > > # add the standard deviations and convert to covariances > american.sd <- c(1.094, 1.350, 1.494, 2.257, 1.541) > american.cov <- lavaan::cor2cov(american.cor, sds = american.sd) > > # create mean vector > american.mean = c(.88, 1.35, 1.27, 1.71, 1.37) > > # specify model for both single group analyses > > single.model <- ' + # turn off (NA) default reference variable scaling for + # first indicator + # label loadings and intercepts for both factors + LineMeaning =~ NA*LM1 + a*LM1 + b*LM2 + c*LM3 + LM1 ~ d*1 + LM2 ~ e*1 + LM3 ~ f*1 + RealWorld =~ NA*RW1 + g*RW1 + h*RW2 + RW1 ~ i*1 + RW2 ~ j*1 + # factor means are free parameters + LineMeaning ~ 1 + RealWorld ~ 1 ' > > # specify effects coding constraints for each factor: > # average loading is 1, average intercept is zero > > single.constraints <- ' + # LineMeaning factor + 3 - a - b - c == 0 + 0 - d - e - f == 0 + # RealWorld factor + 2 - g - h == 0 + 0 - i - j == 0' > > # specify fit statistics for output > fit.stats.1 = c("chisq", "df", "pvalue", "cfi", "srmr") > fit.stats.2 = c("rmsea", "rmsea.ci.lower", "rmsea.ci.upper", "srmr") > > # single group, chinese > > chinese <- lavaan::cfa(single.model, sample.cov = chinese.cov, + sample.mean = chinese.mean, sample.nobs = 316, + meanstructure = TRUE, constraints = single.constraints) > lavaan::fitMeasures(chinese, fit.stats.1) chisq df pvalue cfi srmr 4.377 4.000 0.357 0.999 0.015 > lavaan::fitMeasures(chinese, fit.stats.2) rmsea rmsea.ci.lower rmsea.ci.upper srmr 0.017 0.000 0.088 0.015 > lavaan::summary(chinese, standardized = TRUE, header = FALSE) Parameter Estimates: Standard errors Standard Information Expected Information saturated (h1) model Structured Latent Variables: Estimate Std.Err z-value P(>|z|) Std.lv Std.all LineMeaning =~ LM1 (a) 0.797 0.033 24.362 0.000 1.202 0.786 LM2 (b) 1.141 0.035 32.662 0.000 1.722 0.918 LM3 (c) 1.063 0.037 28.411 0.000 1.604 0.798 RealWorld =~ RW1 (g) 0.878 0.064 13.642 0.000 0.606 0.606 RW2 (h) 1.122 0.064 17.418 0.000 0.774 0.735 Covariances: Estimate Std.Err z-value P(>|z|) Std.lv Std.all LineMeaning ~~ RealWorld 0.759 0.090 8.478 0.000 0.729 0.729 Intercepts: Estimate Std.Err z-value P(>|z|) Std.lv Std.all .LM1 (d) 0.027 0.067 0.398 0.691 0.027 0.017 .LM2 (e) -0.268 0.068 -3.958 0.000 -0.268 -0.143 .LM3 (f) 0.241 0.076 3.182 0.001 0.241 0.120 .RW1 (i) 0.041 0.062 0.664 0.507 0.041 0.041 .RW2 (j) -0.041 0.062 -0.664 0.507 -0.041 -0.039 LineMeanng 1.523 0.091 16.791 0.000 1.009 1.009 RealWorld 0.830 0.049 16.902 0.000 1.203 1.203 Variances: Estimate Std.Err z-value P(>|z|) Std.lv Std.all .LM1 0.894 0.090 9.910 0.000 0.894 0.382 .LM2 0.551 0.116 4.755 0.000 0.551 0.157 .LM3 1.464 0.152 9.622 0.000 1.464 0.363 .RW1 0.634 0.066 9.581 0.000 0.634 0.633 .RW2 0.511 0.081 6.325 0.000 0.511 0.460 LineMeaning 2.278 0.207 10.983 0.000 1.000 1.000 RealWorld 0.476 0.065 7.307 0.000 1.000 1.000 Constraints: |Slack| 3-a-b-c - 0 0.000 0-d-e-f - 0 0.000 2-g-h - 0 0.000 0-i-j - 0 0.000 > lavaan::fitted(chinese) $cov LM1 LM2 LM3 RW1 RW2 LM1 2.340 LM2 2.070 3.516 LM3 1.928 2.761 4.035 RW1 0.531 0.761 0.709 1.001 RW2 0.678 0.972 0.905 0.469 1.110 $mean LM1 LM2 LM3 RW1 RW2 1.24 1.47 1.86 0.77 0.89 > lavaan::residuals(chinese, type = "raw") $type [1] "raw" $cov LM1 LM2 LM3 RW1 RW2 LM1 0.000 LM2 -0.019 0.000 LM3 0.011 0.019 0.000 RW1 0.045 0.004 -0.068 0.000 RW2 0.050 0.006 -0.078 0.000 0.000 $mean LM1 LM2 LM3 RW1 RW2 0 0 0 0 0 > lavaan::residuals(chinese, type = "standardized") $type [1] "standardized" $cov LM1 LM2 LM3 RW1 RW2 LM1 0.000 LM2 -1.934 0.000 LM3 0.332 1.450 0.000 RW1 1.070 0.195 -1.331 0.000 RW2 1.205 0.290 -1.602 0.000 0.000 $mean LM1 LM2 LM3 RW1 RW2 0 0 0 0 0 > lavaan::residuals(chinese, type = "cor.bollen") $type [1] "cor.bollen" $cov LM1 LM2 LM3 RW1 RW2 LM1 0.000 LM2 -0.007 0.000 LM3 0.004 0.005 0.000 RW1 0.030 0.002 -0.034 0.000 RW2 0.031 0.003 -0.037 0.000 0.000 $mean LM1 LM2 LM3 RW1 RW2 0 0 0 0 0 > > # single group, american > > american <- lavaan::cfa(single.model, sample.cov = american.cov, + sample.mean = american.mean, sample.nobs = 302, + meanstructure = TRUE, constraints = single.constraints) > lavaan::fitMeasures(american, fit.stats.1) chisq df pvalue cfi srmr 7.175 4.000 0.127 0.994 0.016 > lavaan::fitMeasures(american, fit.stats.2) rmsea rmsea.ci.lower rmsea.ci.upper srmr 0.051 0.000 0.111 0.016 > lavaan::fitted (american) $cov LM1 LM2 LM3 RW1 RW2 LM1 1.193 LM2 0.779 1.816 LM3 0.863 1.288 2.225 RW1 0.656 0.979 1.085 5.077 RW2 0.460 0.687 0.761 2.305 2.367 $mean LM1 LM2 LM3 RW1 RW2 0.88 1.35 1.27 1.71 1.37 > lavaan::summary(american, standardized = TRUE, header = FALSE) Parameter Estimates: Standard errors Standard Information Expected Information saturated (h1) model Structured Latent Variables: Estimate Std.Err z-value P(>|z|) Std.lv Std.all LineMeaning =~ LM1 (a) 0.724 0.047 15.528 0.000 0.723 0.662 LM2 (b) 1.080 0.053 20.432 0.000 1.078 0.800 LM3 (c) 1.196 0.055 21.767 0.000 1.194 0.801 RealWorld =~ RW1 (g) 1.175 0.062 18.953 0.000 1.813 0.804 RW2 (h) 0.825 0.062 13.299 0.000 1.272 0.827 Covariances: Estimate Std.Err z-value P(>|z|) Std.lv Std.all LineMeaning ~~ RealWorld 0.771 0.119 6.467 0.000 0.501 0.501 Intercepts: Estimate Std.Err z-value P(>|z|) Std.lv Std.all .LM1 (d) 0.036 0.067 0.530 0.596 0.036 0.033 .LM2 (e) 0.090 0.073 1.236 0.216 0.090 0.067 .LM3 (f) -0.126 0.076 -1.656 0.098 -0.126 -0.084 .RW1 (i) -0.100 0.105 -0.954 0.340 -0.100 -0.044 .RW2 (j) 0.100 0.105 0.954 0.340 0.100 0.065 LineMeanng 1.167 0.064 18.261 0.000 1.169 1.169 RealWorld 1.540 0.100 15.416 0.000 0.999 0.999 Variances: Estimate Std.Err z-value P(>|z|) Std.lv Std.all .LM1 0.671 0.067 10.083 0.000 0.671 0.562 .LM2 0.654 0.095 6.874 0.000 0.654 0.360 .LM3 0.798 0.117 6.847 0.000 0.798 0.359 .RW1 1.792 0.413 4.333 0.000 1.792 0.353 .RW2 0.749 0.200 3.747 0.000 0.749 0.317 LineMeaning 0.997 0.101 9.844 0.000 1.000 1.000 RealWorld 2.378 0.254 9.367 0.000 1.000 1.000 Constraints: |Slack| 3-a-b-c - 0 0.000 0-d-e-f - 0 0.000 2-g-h - 0 0.000 0-i-j - 0 0.000 > lavaan::residuals(american, type = "raw") $type [1] "raw" $cov LM1 LM2 LM3 RW1 RW2 LM1 0.000 LM2 -0.015 0.000 LM3 0.021 -0.003 0.000 RW1 0.033 -0.004 -0.019 0.000 RW2 -0.054 0.101 -0.073 0.000 0.000 $mean LM1 LM2 LM3 RW1 RW2 0 0 0 0 0 > lavaan::residuals(american, type = "standardized") $type [1] "standardized" $cov LM1 LM2 LM3 RW1 RW2 LM1 0.000 LM2 -1.046 0.000 LM3 1.281 -0.360 0.000 RW1 0.388 -0.061 -0.264 0.000 RW2 -0.947 2.108 -1.474 0.000 0.000 $mean LM1 LM2 LM3 RW1 RW2 0 0 0 0 0 > lavaan::residuals(american, type = "cor.bollen") $type [1] "cor.bollen" $cov LM1 LM2 LM3 RW1 RW2 LM1 0.000 LM2 -0.010 0.000 LM3 0.013 -0.002 0.000 RW1 0.013 -0.001 -0.006 0.000 RW2 -0.032 0.049 -0.032 0.000 0.000 $mean LM1 LM2 LM3 RW1 RW2 0 0 0 0 0