Learn R Programming

⚠️There's a newer version (2.1.1) of this package.Take me there.

semPower

semPower is an R-package that provides several functions to perform a-priori, post-hoc, and compromise power analyses for structural equation models (SEM).

Basic functionality is also provided as a shiny app, which you can use online at https://sempower.shinyapps.io/sempower.

Installation

Install semPower via CRAN or as follows:

install.packages("devtools")
devtools::install_github("moshagen/semPower")

Manual

Read the manual by typing

vignette("semPower")

or view the manual online. I also warmly recommend this in-depth tutorial on power analyses in SEM using semPower:

Jobst, L., Bader, M., & Moshagen, M. (in press). A Tutorial on Assessing Statistical Power and Determining Sample Size for Structural Equation Models. Psychological Methods. https://doi.org/10.1037/met0000423 preprint

Quick Examples

Determine the required sample size to detect misspecifications of a model (involving df = 100 degrees of freedom) corresponding to RMSEA = .05 with a power of 80% on an alpha error of .05:

ap <- semPower.aPriori(effect = .05, effect.measure = 'RMSEA', 
                       alpha = .05, power = .80, df = 100)
summary(ap)

Determine the achieved power with a sample size of N = 1000 to detect misspecifications of a model (involving df = 100 degrees of freedom) corresponding to RMSEA = .05 on an alpha error of .05:

ph <- semPower.postHoc(effect = .05, effect.measure = 'RMSEA', 
                       alpha = .05, N = 1000, df = 100)
summary(ph)

Determine the critical chi-square such that the associated alpha and beta errors are equal, assuming sample size of N = 1000, a model involving df = 100 degrees of freedom, and misspecifications corresponding to RMSEA = .05:

cp <- semPower.compromise(effect = .05, effect.measure = 'RMSEA', 
                          abratio = 1, N = 1000, df = 100)
summary(cp)

Plot power as function of the sample size to detect misspecifications corresponding to RMSEA = .05 (assuming df = 100) on alpha = .05:

semPower.powerPlot.byN(effect = .05, effect.measure = 'RMSEA', 
                       alpha = .05, df = 100, power.min = .05, power.max = .99)

Plot power as function of the magnitude of effect (measured through the RMSEA assuming df = 100) at N = 500 on alpha = .05:

semPower.powerPlot.byEffect(effect.measure = 'RMSEA', alpha = .05, N = 500, 
                            df = 100, effect.min = .001, effect.max = .10)

Obtain the df of a model provided as lavaan model string (this requires the lavaan package):

lavModel <- '
f1 =~ x1 + x2 + x3
f2 =~ x4 + x5 + x6
'
semPower.getDf(lavModel)

Determine the required sample size on alpha = .05 to detect (with a power of 80%) a correlation of a least .20 between two factors in a standard CFA model involving three factors with 10, 5, and 7 indicators, respectively, and loadings sampled from a normal distribution with given mean and sd for each factor (this requires the lavaan package):

phi <- matrix(c(
                 c(1.0, 0.2, 0.5),
                 c(0.2, 1.0, 0.3),
                 c(0.5, 0.3, 1.0)
                ), byrow = TRUE, ncol = 3)
cfapower <- semPower.powerCFA(type = 'a-priori', 
                              phi = phi, nullCor = c(1, 2), 
                              nIndicator = c(10, 5, 7),
                              loadM = c(.5, .7, .6), 
                              loadSD = c(.15, .01, .05),
                              alpha = .05, power = .80)
summary(cfapower$power)				

For more details and for a description how to express the magnitude of effect in terms of model parameters, see the manual.

Citation

If you use semPower in publications, please cite the package as follows:

Moshagen, M., & Erdfelder, E. (2016). A new strategy for testing structural equation models. Structural Equation Modeling, 23, 54-60. doi: 10.1080/10705511.2014.950896

Copy Link

Version

Install

install.packages('semPower')

Monthly Downloads

890

Version

1.2.0

License

LGPL

Issues

Pull Requests

Stars

Forks

Maintainer

Morten Moshagen

Last Published

November 1st, 2021

Functions in semPower (1.2.0)

checkPositive

checkPositive
getF.RMSEA

getF.RMSEA
getF.GFI

getF.GFI
getCFI.Sigma.mgroups

getCFI.Sigma.mgroups
getF.AGFI

getF.AGFI
getSRMR.Sigma

getSRMR.Sigma
getRMSEA.F

getRMSEA.F
getErrorDiff

getErrorDiff
semPower.powerPlot.byN

sempower.powerPlot.byN
getCFI.Sigma

getCFI.Sigma
getF.Sigma

getF.Sigma
getGFI.F

getGFI.F
semPower.showPlot

semPower.showPlot
getFormattedResults

getFormattedResults
getNCP

getNCP
getMc.F

getMc.F
getF

getF calculates minimum of the ML-fit-function from known fit indices
semPower.postHoc

semPower.postHoc
summary.semPower.postHoc

semPower.postHoc.summary
validateInput

validateInput
semPower.getDf

semPower.getDf
semPower.aPriori

semPower.aPriori
getF.Mc

getF.Mc
semPower.compromise

sempower.compromise
semPower.powerCFA

semPower.powerCFA
semPower.powerPlot.byEffect

sempower.powerPlot.byEffect
getIndices.F

getIndices.F
getSRMR.Sigma.mgroups

getSRMR.Sigma.mgroups
semPower

semPower: Power analyses for structural equation models (SEM).
summary.semPower.compromise

summary.sempower.compromise
summary.semPower.aPriori

summary.semPower.aPriori
getChiSquare.F

getChiSquare.F
getChiSquare.NCP

getChiSquare.NCP
checkPositiveDefinite

checkPositiveDefinite
checkBounded

checkBounded
getAGFI.F

getAGFI.F
getBetadiff

getBetadiff
checkPowerTypes

checkPowerTypes