Fleiss JL, Tytun A, Ury HK (1980). *A simple approximation for calculating sample sizes for comparing independent proportions.* Biometrics 36, 343-346.

The Two Arm Binomial calculator computes an estimate of either sample size or power for tests for differences between two proportions. The program allows for unequal sample sizes between the two groups.

The formulas are based on the classic critical ratio test, with the user able to specify whether or not to apply the continuity correction. Do not use this program for conditions under which normal approximations do not hold. In the case of equal sample sizes, sample sizes will be identical to the tables in Fleiss: *Statistical Methods for Rates and Proportions.* For estimates of power, an additional approximation is used. For the case of equal sample sizes, this approximation is accurate for values of *N* (the number of cases in each group), and *D* (the absolute value of the difference in proportions to be detected), such that \[ D(N-\frac{2}{D})\ge 4 \] For the case of unequal sample sizes, please consult the paper for conditions under which this approximation is accurate.

Enter the type of calculation to be performed: either estimate sample size or estimate power. Enter the input items listed below. Some items have initial default values.

The user is prompted for values to the following items. For items that have initial default values set, the values are given in parentheses.

- Type of calculation- sample size or power
- One-sided or two-sided test
- Continuity correction or no continuity correction
*\(\alpha\)*, the significance level (.05)*\(p_{1}\)*, the proportion of successes in Group 1*\(p_{2}\)*, the proportion of successes in Group 2, where*\(p_{2}\)*>*\(p_{1}\)**\(\frac{n2}{n1}\)*, the sample size ratio of Group 2 to Group 1 (1)*\(1-\beta\)*, the desired power for sample size estimation (.90), or*n*, the total sample size for power estimation

- Approximate power (if power calculation was requested)
- N (if sample size calculation was requested)

The program is written in *R*.

```
function(alpha, N, p1, p2, sides, sampszratio) {
method = "UTJCuneqpower"
zalpha = qnorm(1 - alpha / sides)
prop2 = 1 - (1 / (sampszratio + 1))
prop1 = 1 - prop2
pbar = prop1 * p1 + prop2 * p2
qbar = 1 - pbar
q1 = 1 - p1
q2 = 1 - p2
delta = p2 - p1
Zvalue = (zalpha * sqrt(pbar * qbar / (prop1 * prop2)) - (delta * sqrt(N))) / sqrt((p1 * q1 / prop1) + (p2 * q2 / prop2))
power = 1 - pnorm(Zvalue)
result = list(method = method,
power = power)
return(jsonlite::toJSON(result, pretty = TRUE))
}
```

```
function(alpha, N, p1, p2, sides, sampszratio) {
method = "utFleissCC"
zalpha = qnorm(1 - alpha / sides)
r = sampszratio
pbar = (p1 + r * p2) / (r + 1)
qbar = 1 - pbar
q1 = 1 - p1
q2 = 1 - p2
delta = p2 - p1
mstar = N / (r + 1)
Zpctile = (sqrt(r * delta^2 * mstar - (r + 1) * delta) - zalpha * sqrt((r + 1) * pbar * qbar)) / sqrt(r * p1 * q1 + p2 * q2)
power = pnorm(Zpctile)
result = list(method = method,
power = power)
return(jsonlite::toJSON(result, pretty = TRUE))
}
```

```
function(alpha, power, p1, p2, sides, sampszratio) {
method = "UTJCuneq"
zalpha = qnorm(1 - alpha / sides)
zbeta = qnorm(power)
prop2 = 1 - (1 / (sampszratio + 1))
prop1 = 1 - prop2
pbar = prop1 * p1 + prop2 * p2
qbar = 1 - pbar
q1 = 1 - p1
q2 = 1 - p2
delta = p2 - p1
N = ((zalpha * sqrt(pbar * qbar / (prop1 * prop2)) + zbeta * sqrt((p1 * q1 / prop1) + (p2 * q2 / prop2)))^2) /((delta)^2)
Ntot = 2 * round(N / 2)
N2 = round(prop2 * Ntot)
N1 = Ntot - N2
result = list(method = method,
Ntot = Ntot,
N1 = N1,
N2 = N2)
return(jsonlite::toJSON(result, pretty = TRUE))
}
```

```
function(alpha, power, p1, p2, sides, sampszratio) {
method = "utFleissCC"
zalpha = qnorm(1 - alpha / sides)
zbeta = qnorm(power)
r = sampszratio
pbar = (p1 + r * p2) / (r + 1)
qbar = 1 - pbar
q1 = 1 - p1
q2 = 1 - p2
delta = p2 - p1
mprime = (zalpha * sqrt((r + 1) * pbar * qbar) + zbeta * sqrt(r * p1 * q1 + p2 * q2))^2 / (r * (delta^2))
a = sqrt((1 + (2 * r + 2) / (r * mprime * delta)))
b = (1 + a)^2
m = (mprime / 4) * b
N1 = ceiling(m)
N2 = ceiling(r * N1)
Ntot = N1 + N2
result = list(method = method,
Ntot = Ntot,
N1 = N1,
N2 = N2)
return(jsonlite::toJSON(result, pretty = TRUE))
}
```