7.3 Two Binomial Proportions
7.3.3 R Function nBinomial in gsDesign Library
The library gsDesign was created by Keaven Anderson (keaven_ [email protected]) to provide a set of functions to design and analyze
Sample Size Determination and Power Calculation in Clinical Trials 169 group sequential trials. The Binomial set provides statistical testing, confi- dence intervals and sample size calculation for comparing two binomial pro- portions. This set also provides simulation for two-arm trials with a binary endpoint for fixed sample size and therefore this simulation is not for group sequential or adaptive trials.
The library can be loaded into R as > library(gsDesign)
and the help menu can be displayed as library(help=gsDesign).
For this section to calculate sample size for comparing two binomial pro- portions, we can display the associated build-in functions as follows:
> help(nBinomial)
There are four functions associated with the Binomial set which are 1. nBinomial uses the method of Farrington and Manning (1990) to com-
pute the total sample sizes needed for comparing two binomial event rates in terms of superiority or non-inferiority,
2. testBinomial uses the method of Miettinin and Nurminen (1980) to com- pute a Z- or χ2-statistic for comparing two binomial event rates,
3. ciBinomial is used to compute confidence intervals on the difference between two rates or on the risk-ratio of two rates or on the odds-ratio of two rates, and
4. simBinomial is used to conduct simulations to estimate the power for the Miettinin and Nurminen (1980) test comparing two binomial rates for superiority or non-inferiority.
The common usage of sample size is as follows:
nBinomial(p1, p2, alpha=.025, beta=0.1, delta0=0, ratio=1, sided=1, outtype=1, scale="Difference")
where
• p1 is the event rate in treatment group1 (i.e., D) under the alternative hypothesis,
• p2 is the event rate in treatment group 2 (i.e., P ) under the alternative hypothesis,
• alpha is the Type-I error rate for either a 1-sided or 2-sided test as noted in sided,
170 Clinical Trial Data Analysis Using R
• delta0 is a parameter associated with the null hypothesis. The default 0 represents no difference between treatment groups under the null hy- pothesis. If scale = “Difference” (the default), then delta0 = p10− p20
under H0. If scale = “RR”, then delta0 = log
p
10 p20
. If scale = “LNOR”, then delta0 = log p10
1−p10 − log p20 1−p20 ,
• ratio is the sample size ratio for treatment 2 divided by treatment 1, • sided is 2 for 2-sided and 1 for 1-sided alternatives,
• outtype specifies the output type; default = total sample size, 2 provides sample size for each group (n1, n2), 3 and delta0=0 provides a list with
total sample size (n), sample size for each group (n1, n2), null and al-
ternate hypothesis variance (sigma0, sigma1), input event rates (p1, p2)
and null hypothesis event rates (p10, p20), and
• scale denotes the functional form of the comparison of the groups; i.e., “Difference”, “RR” or “OR”.
The sample size of 58 per treatment calculated in the previous section using
> power.prop.test(p1=0.75,p2=0.5, power=0.8) can be reproduced using nBinomial as:
> nBinomial(p1=0.75, p2=0.5, alpha=.05, beta=0.2, sided=2) [1] 115
which gives total sample size of 115. With equal sample size in both treat- ments, we would need to round 115/2=57.5 to 58 to have a total sample size of 116.
We now illustrate some calculations for sample size. Suppose we are de- signing a clinical trial whose objective is to demonstrate that a new drug is effective when compared to placebo in terms of the endpoint: proportion of patients showing marked improvement by the end of the treatment period, and we need to determine the number of patients needed to be randomized to the drug and placebo treated groups to have a power of 80% to detect a 15% difference (δ) between drug and placebo groups in terms of proportions of patients markedly improving given a false positive rate of 5%.
Suppose further that a search of the literature reveals that the proportion of patients randomized to placebo from reported trials of other drugs treating the same condition who showed marked improvement was 20%, and that for the trial we are designing, we wish to randomize twice as many patients to the drug group as to the placebo group.
Sample Size Determination and Power Calculation in Clinical Trials 171 proportion showing marked improvement in the placebo group is expected to be p2 = 0.20; p1 = p2 + δ = 0.35, α = 0.05 one-sided (the alternative hypothesis is the research objective which is to demonstrate that drug is better than placebo; i.e., is effective), β = 1 − 0.80 = 0.20, and that we want twice as many patients randomized to the drug group as the placebo group. Therefore the desired sample size would be calculated as
> nBinomial(p1=.35, p2=.2, beta=.2, ratio=0.5,outtype=2, alpha=.05, sided=1)
$n1 [1] 165 $n2 [1] 82.6
where outtype=2 to print the sample size for each treatment. We can see that the desired sample size is 165 and 83 (round 82.6 to 83) respectively with total of 165 + 83 = 248 subjects.
If we are to use 1-1 randomization, the total sample size is calculated as > nBinomial(p1=.35, p2=.2, beta=.2, alpha=.05, sided=1)
[1] 217
More calculations may be performed under various other scenarios (2- sided, power of 90% and 95%, etc.) and the reader is encouraged to pursue these.
We again take advantages of the R graphical capabilities to plot the sample size required under different control rates with four types of risk reduction for the new treatment. This is illustrated in Figure 7.5 with the R code chunk below. In this figure, all the sample size calculations are based on 80% power with Type-I error rate of 0.025 for one-sided binomial test.
> # sequence of control event rate > p1 = seq(.1, .3, .01)
> # reduce by 30% to calculate the sample size required > p2 <- p1 *.7
> y1 <- nBinomial(p1, p2, beta=.2, outtype=1, alpha=.025, sided=1) > # reduce by 40% to calculate the sample size required
> p2 <- p1 * .6
> y2 <- nBinomial(p1, p2, beta=.2, outtype=1, alpha=.025, sided=1) > # reduce by 50% to calculate the sample size required
> p2 <- p1 * .5
> y3 <- nBinomial(p1, p2, beta=.2, outtype=1, alpha=.025, sided=1) > # reduce by 60% to calculate the sample size required
172 Clinical Trial Data Analysis Using R
> y4 <- nBinomial(p1, p2, beta=.2, outtype=1, alpha=.025, sided=1) > # make the plot for 30% reduction
> plot(p1, y1, type="l", las=1,ylab="Sample Size",
xlab="Control Group Event Rate", ylim=c(0, 3000), lwd=2) > # add a line for 40% reduction
> lines(p1, y2, lty=2, lwd=2) > # add a line for 50% reduction > lines(p1, y3, lty=3, lwd=2) > # add a line for 60% reduction > lines(p1, y4, lty=4, lwd=2) > # add a legend
> legend("topright",lty=c(1,2, 3, 4), lwd=2, legend=c("30 pct reduction", "40 pct reduction",
"50 pct reduction", "60 pct reduction")) 0.10 0.15 0.20 0.25 0.30 0 500 1000 1500 2000 2500 3000
Control Group Event Rate
Sample Si ze 30 pct reduction 40 pct reduction 50 pct reduction 60 pct reduction
FIGURE 7.5: Sample Size Calculations for 80% Power.
It can be seen from Figure 7.5 that the required sample size decreases when the event probability in the control group increases in all four situa- tions. This is intuitively true since the absolute differences between p1 and p2
Sample Size Determination and Power Calculation in Clinical Trials 173 are increasing even though the values in the vector of p2 are all reduced by
the same amount. Theoretically it takes larger sample sizes to detect smaller differences which explains why the required sample size decreases along with the p1since the absolute difference between p1 and p2is increasing. This also
explains why a smaller sample size is required for a higher percent reduction as depicted in this figure.