> # principles and practice of sem, 5th ed. > # rex b. kline, guilford press, 2023 > > # chapter 10, table 10.1, analysis 2 > # conduct power and precision analyses for the > # roth et al. (1989) parametric path model of illness: > > # 1. maccallum-rmsea for whole model (semTools) > # 2. monte carlo for individual parameters (WebPower) > # 3. kelley-lai precision (MBESS) > > # 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:09:28 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. > library(semTools) ############################################################################### This is semTools 0.5-6 All users of R (or SEM) are invited to submit functions or ideas for functions. ############################################################################### > library(WebPower) Loading required package: MASS Loading required package: lme4 Loading required package: Matrix Loading required package: parallel Loading required package: PearsonDS > library(MBESS) Attaching package: ‘MBESS’ The following object is masked from ‘package:lavaan’: cor2cov > > # get citation information > citation("semTools", auto = TRUE) To cite package ‘semTools’ in publications use: Jorgensen TD, Pornprasertmanit S, Schoemann AM, Rosseel Y (2022). _semTools: Useful Tools for Structural Equation Modeling_. R package version 0.5-6, . A BibTeX entry for LaTeX users is @Manual{, title = {semTools: Useful Tools for Structural Equation Modeling}, author = {Terrence D. Jorgensen and Sunthud Pornprasertmanit and Alexander M. Schoemann and Yves Rosseel}, year = {2022}, note = {R package version 0.5-6}, url = {https://CRAN.R-project.org/package=semTools}, } > 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}, } > citation("WebPower", auto = TRUE) To cite package ‘WebPower’ in publications use: Zhang Z, Mai Y (2023). _WebPower: Basic and Advanced Statistical Power Analysis_. R package version 0.8.7, . A BibTeX entry for LaTeX users is @Manual{, title = {WebPower: Basic and Advanced Statistical Power Analysis}, author = {Zhiyong Zhang and Yujiao Mai}, year = {2023}, note = {R package version 0.8.7}, url = {https://CRAN.R-project.org/package=WebPower}, } > citation("MBESS", auto = TRUE) To cite package ‘MBESS’ in publications use: Kelley K (2022). _MBESS: The MBESS R Package_. R package version 4.9.2, . A BibTeX entry for LaTeX users is @Manual{, title = {MBESS: The MBESS R Package}, author = {Ken Kelley}, year = {2022}, note = {R package version 4.9.2}, url = {https://CRAN.R-project.org/package=MBESS}, } > > # 1a. maccallum-rmsea for whole model > # power at N = 373 > > # exact fit > semTools::findRMSEApower(0, .05, 5, 373, .05, 1) [1] 0.3378327 > # close fit > semTools::findRMSEApower(.05, .08, 5, 373, .05, 1) [1] 0.3172584 > # not-close fit > semTools::findRMSEApower(.05, .01, 5, 373, .05, 1) [1] 0.2291066 > # poor fit > semTools::findRMSEApower(.10, .05, 5, 373, .05, 1) [1] 0.6127939 > > # 1b. maccallum-rmsea for whole model > # minimum N for power at least .90 > > # exact fit > semTools::findRMSEAsamplesize(0, .05, 5, .90, .05, 1) [1] 1319 > # close fit > semTools::findRMSEAsamplesize(.05, .08, 5, .90, .05, 1) [1] 1997 > # not-close fit > semTools::findRMSEAsamplesize(.05, .01, 5, .90, .05, 1) [1] 1527 > # poor fit > semTools::findRMSEAsamplesize(.10, .05, 5, .90, .05, 1) [1] 758 > > # 2. monte carlo for individual parameters > # specify model with fixed parameter values > > roth.model <- ' + # direct effects + fitness ~ a*exercise + start(.05)*exercise + stress ~ c*hardy + start(-.18)*hardy + illness ~ b*fitness + start(-.35)*fitness + d*stress + start(.38)*stress + # variances and covariances for exogenous variables + exercise ~~ start(4500.00)*exercise + hardy ~~ start(1400.00)*hardy + exercise ~~ start(251.00)*hardy + fitness ~~ start(304.00)*fitness + stress ~~ start(1045.00)*stress + illness ~~ start(3600.00)*illness ' > > roth.indirect <- ' + ab := a*b + cd := c*d ' > > roth.model.ml <- wp.mc.sem.basic(model = roth.model, + indirect = roth.indirect, nobs = 373, nrep = 1000) fitness ~ exercise stress ~ hardy illness ~ fitness 0.960 0.986 0.508 illness ~ stress exercise ~~ exercise hardy ~~ hardy 0.989 1.000 1.000 exercise ~~ hardy fitness ~~ fitness stress ~~ stress 0.500 1.000 1.000 illness ~~ illness ab := a*b cd := c*d 1.000 0.329 0.928 > lavaan::summary(roth.model.ml) Basic information: Esimation method ML Standard error standard Number of requested replications 1000 Number of successful replications 1000 True Estimate MSE SD Power Coverage Regressions: fitness ~ exercise (a) 0.050 0.050 0.013 0.013 0.962 0.938 stress ~ hardy (c) -0.180 -0.181 0.045 0.045 0.988 0.949 illness ~ fitness (b) -0.350 -0.353 0.175 0.173 0.520 0.957 stress (d) 0.380 0.376 0.094 0.099 0.975 0.938 Covariances: exercise ~~ hardy 251.000 244.437 130.187 132.204 0.462 0.947 Variances: exercise 4500.000 4492.986 329.000 338.377 1.000 0.934 hardy 1400.000 1393.886 102.068 103.397 1.000 0.951 fitness 304.000 302.007 22.115 22.213 1.000 0.941 stress 1045.000 1040.931 76.222 78.167 1.000 0.933 illness 3600.000 3582.922 262.360 276.294 1.000 0.932 Indirect/Mediation effects: ab -0.017 -0.018 0.010 0.010 0.349 0.931 cd -0.068 -0.068 0.024 0.025 0.906 0.931 > > # 3. kelley-lai precision > MBESS::ss.aipe.rmsea(RMSEA = .04, df = 5, width = .035, conf.level = .95) Necessary sample size so that the expected width of the 95% confidence interval is no greater than 0.035, given a population RMSEA of 0.04, is: [1] 2760