Description Usage Arguments Details Value Author(s) References Examples
Support is provided for sample size estimation, power, testing, confidence intervals and simulation for fixed sample size trials (that is, not group sequential or adaptive) with two arms and binary outcomes. Both superiority and noninferiority trials are considered. While all routines default to comparisons of riskdifference, options to base computations on riskratio and oddsratio are also included.
nBinomial()
computes sample size or power using the method of Farrington and
Manning (1990) for a trial to test the difference between two binomial event rates.
The routine can be used for a test of superiority or noninferiority.
For a design that tests for superiority nBinomial()
is consistent with the method of Fleiss, Tytun, and Ury (but without the continuity correction) to test for differences between event rates.
This routine is consistent with the Hmisc package routines bsamsize
and bpower
for superiority designs.
Vector arguments allow computing sample sizes for multiple scenarios for comparative purposes.
testBinomial()
computes a Z or Chisquarestatistic that compares two binomial event rates using
the method of Miettinen and Nurminen (1980). This can be used for superiority or noninferiority testing.
Vector arguments allow easy incorporation into simulation routines for fixed, group sequential and adaptive designs.
ciBinomial()
computes confidence intervals for 1) the difference between two rates, 2) the riskratio for two rates
or 3) the oddsratio for two rates. This procedure provides inference that is consistent with testBinomial()
in that
the confidence intervals are produced by inverting the testing procedures in testBinomial()
.
The Type I error alpha
input to ciBinomial
is always interpreted as 2sided.
simBinomial()
performs simulations to estimate the power for a Miettinen and Nurminen (1985) test
comparing two binomial rates for superiority or noninferiority.
As noted in documentation for bpower.sim()
in the HMisc package, by using testBinomial()
you can see that the formulas without any continuity correction are quite accurate.
In fact, Type I error for a continuitycorrected test is significantly lower (Gordon and Watson, 1996) than the nominal rate.
Thus, as a default no continuity corrections are performed.
varBinomial
computes blinded estimates of the variance of the estimate of 1) event rate differences, 2) logarithm of the risk ratio, or 3) logarithm of the odds ratio. This is intended for blinded sample size reestimation for comparative trials with a binary outcome.
1 2 3 4 5 6 7 8  nBinomial(p1, p2, alpha=.025, beta=0.1, delta0=0, ratio=1,
sided=1, outtype=1, scale="Difference", n=NULL)
testBinomial(x1, x2, n1, n2, delta0=0, chisq=0, adj=0,
scale="Difference", tol=.1e10)
ciBinomial(x1, x2, n1, n2, alpha=.05, adj=0, scale="Difference")
simBinomial(p1, p2, n1, n2, delta0=0, nsim=10000, chisq=0, adj=0,
scale="Difference")
varBinomial(x,n,delta0=0,ratio=1,scale="Difference")

For simBinomial()
and ciBinomial()
all arguments must have length 1.
For testBinomial()
, x2, x2, n1, n2, delta0, chisq,
and adj
may be vectors.
For nBinomial()
, p1, p2, beta, delta0
and ratio
may be vectors.
For varBinomial()
, x
may be a vector.
For nBinomial()
, testBinomial()
and varBinomial()
, when one or more arguments is a vector, the routines return a vector of sample sizes or powers (nBinomial
), test statistics (testBinomial
), or variance estimates (varBinomial
).
Where vector arguments are allowed, there may be a mix of scalar and vector arguments.
All arguments specified using vectors must have the same length.
p1 
event rate in group 1 under the alternative hypothesis 
p2 
event rate in group 2 under the alternative hypothesis 
alpha 
type I error; see 
beta 
type II error 
delta0 
A value of 0 (the default) always represents no difference between treatment groups under the null hypothesis.

ratio 
sample size ratio for group 2 divided by group 1 
sided 
2 for 2sided test, 1 for 1sided test 
outtype 

n 
If power is to be computed in 
x 
Number of “successes” in the combined control and experimental groups. 
x1 
Number of “successes” in the control group 
x2 
Number of “successes” in the experimental group 
n1 
Number of observations in the control group 
n2 
Number of observations in the experimental group 
chisq 
An indicator of whether or not a chisquare (as opposed to Z) statistic is to be computed.
If 
adj 
With 
scale 
“Difference”, “RR”, “OR”; see the 
nsim 
The number of simulations to be performed in 
tol 
Default should probably be used; this is used to deal with a rounding issue in interim calculations 
Testing is 2sided when a Chisquare statistic is used and 1sided when a Zstatistic is used. Thus, these 2 options will produce substantially different results, in general. For noninferiority, 1sided testing is appropriate.
You may wish to round sample sizes up using ceiling()
.
Farrington and Manning (1990) begin with event rates p1
and p2
under the alternative hypothesis
and a difference between these rates under the null hypothesis, delta0
.
From these values, actual rates under the null hypothesis are computed, which are labeled p10
and p20
when outtype=3
.
The rates p1
and p2
are used to compute a variance for a Ztest comparing rates under the alternative hypothesis,
while p10
and p20
are used under the null hypothesis. This computational method is also used to estimate variances in varBinomial()
based on the overall event rate observed and the input treatment difference specified in delta0
.
Sample size with scale="Difference"
produces an error if p1p2=delta0
.
Normally, the alternative hypothesis under consideration would be p1p2delta0
$>0$.
However, the alternative can have p1p2delta0
$<0$.
testBinomial()
and simBinomial()
each return a vector of either Chisquare or Z test statistics.
These may be compared to an appropriate cutoff point (e.g., qnorm(.975)
for normal or qchisq(.95,1)
for chisquare).
ciBinomial()
returns a data frame with 1 row with a confidence interval; variable names are lower
and upper
.
varBinomial()
returns a vector of (blinded) variance estimates of the difference of event rates (scale="Difference"
), logarithm of the oddsratio (scale="OR"
) or logarithm of the riskratio (scale="RR"
).
With the default outtype=1
, nBinomial()
returns a vector of total sample sizes is returned.
With outtype=2
, nBinomial()
returns a data frame containing two vectors n1
and n2
containing
sample sizes for groups 1 and 2, respectively; if n
is input, this option also returns the power in a third vector, Power
.
With outtype=3
, nBinomial()
returns a data frame with the following columns:
n 
A vector with total samples size required for each event rate comparison specified 
n1 
A vector of sample sizes for group 1 for each event rate comparison specified 
n2 
A vector of sample sizes for group 2 for each event rate comparison specified 
alpha 
As input 
sided 
As input 
beta 
As input; if 
Power 
If 
sigma0 
A vector containing the standard deviation of the treatment effect difference under the null hypothesis times 
sigma1 
A vector containing the values as 
p1 
As input 
p2 
As input 
p10 
group 1 event rate used for null hypothesis 
p20 
group 2 event rate used for null hypothesis 
Keaven Anderson keaven\[email protected]
Farrington, CP and Manning, G (1990), Test statistics and sample size formulae for comparative binomial trials with null hypothesis of nonzero risk difference or nonunity relative risk. Statistics in Medicine; 9: 14471454.
Fleiss, JL, Tytun, A and Ury (1980), A simple approximation for calculating sample sizes for comparing independent proportions. Biometrics;36:343346.
Gordon, I and Watson R (1985), The myth of continuitycorrected sample size formulae. Biometrics; 52: 7176.
Miettinen, O and Nurminen, M (1985), Comparative analysis of two rates. Statistics in Medicine; 4 : 213226.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88  # Compute ztest test statistic comparing 39/500 to 13/500
# use continuity correction in variance
x < testBinomial(x1=39, x2=13, n1=500, n2=500, adj=1)
x
pnorm(x, lower.tail=FALSE)
# Compute with unadjusted variance
x0 < testBinomial(x1=39, x2=23, n1=500, n2=500)
x0
pnorm(x0, lower.tail=FALSE)
# Perform 50k simulations to test validity of the above
# asymptotic pvalues
# (you may want to perform more to reduce standard error of estimate)
sum(as.double(x0) <=
simBinomial(p1=.078, p2=.078, n1=500, n2=500, nsim=10000)) / 10000
sum(as.double(x0) <=
simBinomial(p1=.052, p2=.052, n1=500, n2=500, nsim=10000)) / 10000
# Perform a noninferiority test to see if p2=400 / 500 is within 5% of
# p1=410 / 500 use a zstatistic with unadjusted variance
x < testBinomial(x1=410, x2=400, n1=500, n2=500, delta0= .05)
x
pnorm(x, lower.tail=FALSE)
# since chisquare tests equivalence (a 2sided test) rather than
# noninferiority (a 1sided test),
# the result is quite different
pchisq(testBinomial(x1=410, x2=400, n1=500, n2=500, delta0= .05,
chisq=1, adj=1), 1, lower.tail=FALSE)
# now simulate the zstatistic witthout continuity corrected variance
sum(qnorm(.975) <=
simBinomial(p1=.8, p2=.8, n1=500, n2=500, nsim=100000)) / 100000
# compute a sample size to show noninferiority
# with 5% margin, 90% power
nBinomial(p1=.2, p2=.2, delta0=.05, alpha=.025, sided=1, beta=.1)
# assuming a slight advantage in the experimental group lowers
# sample size requirement
nBinomial(p1=.2, p2=.19, delta0=.05, alpha=.025, sided=1, beta=.1)
# compute a sample size for comparing 15% vs 10% event rates
# with 1 to 2 randomization
nBinomial(p1=.15, p2=.1, beta=.2, ratio=2, alpha=.05)
# now look at total sample size using 11 randomization
n < nBinomial(p1=.15, p2=.1, beta=.2, alpha=.05)
n
# check if inputing sample size returns the desired power
nBinomial(p1=.15, p2=.1, beta=.2, alpha=.05,n=n)
# redo with alternate output types
nBinomial(p1=.15, p2=.1, beta=.2, alpha=.05, outtype=2)
nBinomial(p1=.15, p2=.1, beta=.2, alpha=.05, outtype=3)
# look at power plot under different control event rate and
# relative risk reductions
p1 < seq(.075, .2, .000625)
p2 < p1 * 2 / 3
y1 < nBinomial(p1, p2, beta=.2, outtype=1, alpha=.025, sided=1)
p2 < p1 * .75
y2 < nBinomial(p1, p2, beta=.2, outtype=1, alpha=.025, sided=1)
p2 < p1 * .6
y3 < nBinomial(p1, p2, beta=.2, outtype=1, alpha=.025, sided=1)
p2 < p1 * .5
y4 < nBinomial(p1, p2, beta=.2, outtype=1, alpha=.025, sided=1)
plot(p1, y1, type="l", ylab="Sample size",
xlab="Control group event rate", ylim=c(0, 6000), lwd=2)
title(main="Binomial sample size computation for 80 pct power")
lines(p1, y2, lty=2, lwd=2)
lines(p1, y3, lty=3, lwd=2)
lines(p1, y4, lty=4, lwd=2)
legend(x=c(.15, .2),y=c(4500, 6000),lty=c(2, 1, 3, 4), lwd=2,
legend=c("25 pct reduction", "33 pct reduction",
"40 pct reduction", "50 pct reduction"))
# compute blinded estimate of treatment effect difference
x1 < rbinom(n=1,size=100,p=.2)
x2 < rbinom(n=1,size=200,p=.1)
# blinded estimate of risk difference variance
varBinomial(x=x1+x2,n=300,ratio=2,delta0=0)
# blnded estimate of logriskratio
varBinomial(x=x1+x2,n=300,ratio=2,delta0=0,scale="RR")
# blinded estimate of logoddsratio
varBinomial(x=x1+x2,n=300,ratio=2,delta0=0,scale="OR")

Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.