Source

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

Description

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.

Running the Program

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.

Input Items

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

Output Items

Statistical Code

The program is written in R.

View Power Code


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))
}


View Power Code for Continuity Correction


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))
}


View Sample Size Code


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))
}


View Sample Size Code for Continuity Correction


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))
}