
Spower Provides a general purpose simulation-based poweranalysis API for routine and customized simulation experimental designs.The package focuses exclusively on Monte Carlo simulation experimentvariants of (expected) prospective power analyses, criterion analyses,compromise analyses, sensitivity analyses, and a priori/post-hocanalyses. The default simulation experiment functions defined within thepackage provide stochastic variants of the power analysis subroutines inGPower 3.1 (Faul, Erdfelder, Buchner, and Lang, 2009), alongwith various other parametric and non-parametric power analysisapplications (e.g., mediation analyses) and support for Bayesian poweranalysis by way of Bayes factors or posterior probability evaluations.Additional functions for building empirical power curves, reanalyzingsimulation information, and for increasing the precision of theresulting power estimates are also included, each of which utilizesimilar API structures. For further details see the associatedpublication in Chalmers (2025).
You can installSpower from CRAN:
install.packages("Spower")To install the development version of theSpowerpackage, you need to install theremotes package then theSpower package.
install.packages("remotes")remotes::install_github("philchalmers/Spower")Spower requires only two components: an available functionused to generate exactly one simulation experiment that returns one ormorep-values given the null hypothesis of interest (oralternative criteria that returnlogical indicators orposterior probabilities), and the use of eitherSpower() orSpowerCurve() to perform the desired prospective/post-hoc,a priori, sensitivity, compromise, or criterion power analysis.
For example, the built-inp_t.test() function performst-tests using various inputs, where below a sample size of\(N=200\) is supplied(n = 100 per group) and a Cohen’s
library(Spower)p_t.test(n=100,d=0.5)## [1] 0.001231514To evaluate the prospective power of this test simply requirespassing the simulation function toSpower(), which willperform this experiment with 10,000 independent replications, collectingand summarizing all relevant information for the power analysis.
set.seed(42)p_t.test(n=100,d=0.5)|>Spower()#### Execution time (H:M:S): 00:00:02## Design conditions:#### # A tibble: 1 × 4## n d sig.level power## <dbl> <dbl> <dbl> <lgl>## 1 100 0.5 0.05 NA#### Estimate of power: 0.943## 95% Confidence Interval: [0.938, 0.947]Alternatively, for a priori and sensitive analyses, the respectiveinput to the simulation function must be set toNA, whilewithinSpower() the target power rate must be includedalong with a suitable searchinterval range. Below thetarget power is set to\(1-\beta =.95\), while the associated
set.seed(01123581321)# estimate the require n value to achieve a power of 1 - beta = .95p_t.test(n=NA,d=0.5)|>Spower(power=.95,interval=c(50,300))## Iter: 56; Median = 101; E(f(x)) = 0.00; Total.reps = 11000; k.tol = 2; Pred = 103.4#### Execution time (H:M:S): 00:00:05## Design conditions:#### # A tibble: 1 × 4## n d sig.level power## <dbl> <dbl> <dbl> <dbl>## 1 NA 0.5 0.05 0.95#### Estimate of n: 103.4## 95% Predicted Confidence Interval: [101.5, 105.4]To generate suitable power-curves for any given simulation or poweranalysis criteria, the simulation experiment can be passed toSpowerCurve() (or toSpowerBatch() first, andthen toSpowerCurve()). This function contains a similarspecification structure toSpower(), however differs inthat the arguments to vary are explicitly passed as named vectors toSpowerCurve(). Below is an example varying sample size(n), while the next example varies bothn andthe effect sized.
set.seed(8675309)# Jenny Jennyp_t.test(d=0.2)|>SpowerCurve(n=seq(50,550,by=100))
p_t.test()|>SpowerCurve(n=seq(50,350,by=50),d=c(.2, .3, .4, .5))
The package currently contains a vignette demonstrating several ofthe examples from theGPower 3.1 manual, providingsimulation-based replications of the same analyses, as well othervignettes showing more advanced applications of the package (ROPEs,Bayesian power analyses, precision criterion, Type S/M errors, etc).
To report bugs/issues/feature requests, please file anissue.
If you have a simulation experiment you’d like to contribute in theform of either
# returns a p-value, P(D|H0)p_yourSimulation()# returns a posterior probability, P(H1|D)pp_yourSimulation()# returns a logical (more complex experiments, perhaps involing ROPEs)l_yourSimulation()then feel free to document this function using theroxygen2 style syntax and open a pull request. Otherwise,contributions can be made to the online Wiki.