The powergrid package is intended to allow users to easily evaluate a function across a grid of input parameters. The utilities in the package are aimed at performing analyses of power and sample size, allowing for easy search of minimum n (or min/max of any other parameter) to achieve a minimal level of power (or a maximum of any value). Also, plotting functions are included that present the dependency of n and power in relation to further parameters.
The package (version 0.6.2) is available from CRAN and may be installed through your favorite mirror.
Note that the package is developed further here on SCTO’s github. If you
want to use a development version (newer than the CRAN version), make
sure you explicitly refer to the current release when loading the
package in your code, using argument tag to install_github.
devtools::install_github("SwissClinicalTrialOrganisation/powergrid",
## tag = 'v0.6.2', # replace with a specific
## development version, or omit to install the current
## release
build_vignette = TRUE)
library(powergrid)Powergrid is a package originally developed by Gilles Dutilh, partly funded by a Statistical programming grant from the SCTO. Since then, many great contributions have been made by Richard Allen of the statistics team at DKF basel.
The strengths of the powergrid package are:
- Any number of input parameters to search along may be included easily.
- Any number of output parameters are handled intuitively.
- Thether performing simulation-based or closed-form power-analyses, the powergrid utilities behave the same way.
- The objective may be to achieve at least a certain value (in the case of power), but also at most a certain value (as in the case of expected credence intervals).
- The parameter that is optimized to achieve the objective may be something you want to be small (e.g., n), or allow to be large (e.g., the maximal permissible SD).
- Two different plot function are supplied to show the relation between input parameters and the objective: not only showing a single sample size to achieve a certain power, but an illustration of the dynamics of sample size, power, and other parameters.
- Hassle-free parallel computing.
Define a grid of parameters to evaluate a function across:
sse_pars <- list( # a simple list
n = seq(from = 10, to = 60, by = 5), # sample size
sd = seq(from = 0.1, to = 1, by = 0.1) # standard deviation
)Define a function to evaluate the parameters across the grid. The
function should take the parameters as input and return a single value
(e.g., power, sample size, etc.). For example, we can use the
power.t.test function from the stats package to calculate power for
a t-test:
PowFun <- function(n, sd){
ptt = power.t.test(n = n/2,
delta = .6,
sd = sd,
sig.level = 0.05)
return(ptt$power)
}Evaluate the function at each grid node:
power <- PowerGrid(pars = sse_pars, fun = PowFun)Display the results:
PowerPlot(power)See the vignette for more details on how to use the package and its functions.
Please don’t hesitate making an issue above or contributing through a pull request. You may also contact Gilles by email.

