sim.power: Power calculations based on a simulation approach

Description Usage Arguments Value Author(s) References Examples

View source: R/SWSamp.R

Description

Simulation-based power calculations for a SWT with normally distributed outcome

Usage

1
2
3
4
sim.power(I, J, H = NULL, K, design = "cross-sec", mu = 0, b.trt, b.time = NULL,
sigma.y=NULL,sigma.e=NULL,rho,sigma.a=NULL,rho.ind=NULL,sigma.v=NULL,
n.sims=1000,formula=NULL,family="gaussian",natural.scale=TRUE,sig.level=0.05,
n.cores=NULL,method="lme",plot=FALSE,...)

Arguments

I

Number of clusters

J

Number of time points

H

Number of units randomised at each time point

K

Average size of each cluster

design

type of design. Can be 'cross-sec' (default) or 'cohort' (repeated measurements)

mu

baseline outcome value

b.trt

Treatment effect

b.time

Time effect

sigma.y

total standard deviation

sigma.e

individual standard deviation

rho

Intra-class correlation coefficient

sigma.a

the sd of the the cluster-level intercept (default at NULL)

rho.ind

individual-level ICC (for cohorts)

sigma.v

the sd of the cluster-level slope (by intervention, default at NULL)

n.sims

Number of simulations to be used (default=1000)

formula

Formula describing the model to be used

family

The model family to be used. Default value is 'gaussian' and other possibile choices are 'binomial' or 'poisson'

natural.scale

Indicator for whether the input is passed on the natural scale or on the scale of the linear predictor. By default is set to TRUE. In the case of family='gaussian' it does not have any effect, since the link for the linear predictor is the identity. But for family='binomial' or family='poisson', the user has to specify when the input is given on the logit or log scale

sig.level

Significance level (default=0.05)

n.cores

Specifies the number of processors to be used for the computation (default=NULL, which means that R will try and figure out)

method

A string specifying the method to be used for the calculation. The default value is lme, indicating a standard frequentist analysis, based on (generalised) linear model and including structured (random) effects, when necessary. An alternative version is framed in a Bayesian setting and uses Integrated Nested Laplace Approximation (INLA) to analyse the data and obtain the relevant estimates for the posterior distributions of the model parameters. This can be performed by setting method='inla'

plot

Shows a plot of the moving average of the resulting power after 10 the simulations. This helps assessing the convergence of the estimate towards some common value. The default is FALSE, in which case a graph is not shown.

...

Additional optional arguments. The user can specify a function named data, which defines the simulation of the 'virtual trial data'. These can be in any given form, with the only constraint that it should return a data frame containing the relevant variables. The function data can have no arguments at all, but this can be relaxed and there can be suitable inputs to this function. In this case, the user also needs to specify a list inpts including all the values for the arguments to be used with the user-defined function data. When using user-defined data generating processes, the user must be also pass a relevant formula, depending on what the model used (for both generation of the dataset and analysis) is. Another additional argument that can be passed to the call to sim.sw.cont is treatment, a string specifying the name of the treatment variable (if not present, SWSamp assumes that this is exactly 'treatment').

Value

power

The resulting estimated power, for the given configuration. If the model does not include random effects, this is based on the p-value computed by lm, which is used to analyse the simulated datasets. If the model does include random effects (which is the case for a SWT), then SWSample assesses whether the 'true' effect is correctly detected by computing the (1-alpha) whether it is entirely above or below 0. This is because it is difficult to assess the correct degrees of freedom of the resulting (linear) mixed model. The p-value could be computed using the Satterthwaite approximation, or by using a rougher Normal approximation, but in line with suggestions by Pinheiro, J. C., and D. M. Bates. 2000. Mixed-effects models in S and S-PLUS. Springer, New York, we sidestep the problem by focussing on estimation, rather than hypothesis testing for this.

time2run

Running time, in seconds

ci.power

Estimated 95% confidence interval for the power - based on normal approximation

theta

Estimated treatment effect with standard error

rnd.eff.sd

Estimated variance components

setting

A list summarising the assumptions in terms of number of clusters, time points, type of model, formula used

Author(s)

Gianluca Baio

References

Baio, G; Copas, A; Ambler, G; Hargreaves, J; Beard, E; and Omar, RZ Sample size calculation for a stepped wedge trial. Trials, 16:354. Aug 2015.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
mu1=0.3
b.trt=-0.3875
sigma.e=1.55
J=5
K=20
sig.level=0.05
n.sims=10
rho=0.5
pow.cont <- sim.power(I=14,J=J,H=NULL,K=K,rho=rho,mu=mu1,sigma.e=sigma.e,b.trt=b.trt,
                       formula=NULL,n.sims=n.sims,sig.level=sig.level,n.cores=2)
pow.cont$power
pow.cont$ci
pow.cont$time2run.sec
pow.cont$rnd.eff.sd^2

giabaio/SWSamp documentation built on July 15, 2017, 4:22 a.m.