Paired Proportions
Menu location: Analysis_Proportions_Paired.
This function examines the difference between a pair of binomial proportions.
Two proportions are paired (as opposed to independent) if they share a common feature that affects the outcome. For example, when comparing two laboratory methods (culture media) to detect bacteria in samples of blood, if blood from the same sample is put into both methods, this is the "pairing". Pairs of results from multiple samples can then be compared as a pair of proportions:
| Group/Category A: | |||
| outcome present | outcome absent | ||
| Group/Category B: | outcome present: | a | b |
| outcome absent: | c | d | |
total n = a+b+c+d
responding in both categories = r = a
responding in first category only = s = b
responding in second category only = t = c
proportion 1 = (r + s) / n
proportion 2 = (r + t) / n
proportion difference (delta) = (s - t) / n
Another way of looking at these data is to examine how the grouping into category A depends upon the grouping into category B (see exact test for matched pairs of counts).
StatsDirect gives you exact and exact mid-P hypothesis tests for the equality of the two proportions (i.e. delta = 0) and gives you a confidence interval for the difference between them.
Assumptions:
- two mutually exclusive outcomes
- random sample from one population
Consider using mid-P values and intervals when you have several similar studies to consider within an overall investigation (Armitage and Berry, 1994).
Technical Validation
Exact methods are used throughout (Armitage and Berry, 1994; Liddell, 1983). The two sided exact P value equates with the exact test for a paired fourfold table (Liddell, 1983). The exact test is calculated for any number of pairs.
The confidence interval is constructed using Newcombe's refinement of Wilson's score based method, this is close to a mid-P interval (Newcombe, 1998a).
Example
From Armitage and Berry (1994, p. 138).
The data below represent a comparison of two media for culturing Mycobacterium tuberculosis. Fifty suspect sputum specimens were plated up on both media and the following results were obtained:
| Medium B: | ||||
| Growth | No Growth | |||
| Medium A: | Growth: | 20 | 12 | |
| No Growth: | 2 | 16 | N = 50 | |
To analyse these data in StatsDirect you must select paired proportions from the proportions section of the analysis menu. Select a 95% confidence interval by pressing enter when you are presented with the confidence interval menu. Enter TOTAL (n) as 50, BOTH (r) as 20, FIRST (s) as 12 and SECOND (t) as 2.
For this example:
Total = 50, both = 20, first only = 12, second only = 2
Proportion 1 = 0.64
Proportion 2 = 0.44
Proportion difference = 0.2
Exact two sided P = 0.0129
Exact one sided P = 0.0065
Exact two sided mid P = 0.0074
Exact one sided mid P = 0.0037
Score based (Newcombe) 95% confidence interval for the proportion difference:
0.056156 to 0.329207
Here we can conclude that the proportion difference is statistically significantly different from zero. With 95% confidence we can say that the true population value for the proportion difference lies somewhere between 0.06 and 0.33. This leaves us with little doubt that medium A is more effective than medium B for the culture of tubercle bacilli.
Compare these results with the exact test for matched pairs.
R code
This R code reproduces the example above. It needs no packages and was checked with R 4.6.1. Paste it into R, or save it as a script and run it.
# Paired proportions: the StatsDirect help example (Armitage and Berry 1994, p. 138,
# growth of tubercle bacilli from 50 sputum specimens on two culture media) in R
n <- 50 # total pairs
r <- 20 # growth on both media
s <- 12 # growth on medium A only
t <- 2 # growth on medium B only
p1 <- (r + s) / n
p2 <- (r + t) / n
cat("Total = ", n, ", both = ", r, ", first only = ", s, ", second only = ", t,
"\n", sep = "")
six <- function(x) formatC(x, digits = 6, format = "f", drop0trailing = TRUE)
pv <- function(p) {
if (p < 0.0001) "P < 0.0001" else
paste("P =", formatC(p, digits = 4, format = "f", drop0trailing = TRUE))
}
cat("Proportion 1 =", six(p1), "\n")
cat("Proportion 2 =", six(p2), "\n")
cat("Proportion difference =", six((s - t) / n), "\n")
# The exact test is a binomial test on the discordant pairs: under the null
# hypothesis each of the s + t pairs that differ is equally likely to favour
# either medium, so s ~ Binomial(s + t, 1/2). With probability 1/2 the binomial is
# symmetric, so the outcomes at least as far from 7 as s = 12 are 0 to 2 and 12 to 14,
# and binom.test's two sided P (0.0129) is twice the one sided P. mcnemar.test() on the
# 2 by 2 table gives the continuity corrected chi-square approximation instead.
print(binom.test(s, s + t, p = 0.5))
# One sided and mid P values. The one sided P is the lower tail of the smaller of
# s and t; mid P counts the observed value with half weight. Two sided P is twice
# the one sided value, capped at 1.
m <- min(s, t)
p_one <- pbinom(m, s + t, 0.5)
p_mid <- p_one - dbinom(m, s + t, 0.5) / 2
cat("Exact two sided", pv(min(1, 2 * p_one)), "\n")
cat("Exact one sided", pv(p_one), "\n")
cat("Exact two sided mid", pv(min(1, 2 * p_mid)), "\n")
cat("Exact one sided mid", pv(p_mid), "\n")
# Confidence interval for the difference: Newcombe's (1998) method 10. The Wilson
# score interval of each proportion is found first, then the two are combined using
# an estimate of the correlation (phi) between the paired outcomes, with Newcombe's
# continuity correction of the numerator of phi when it is positive.
z <- qnorm(0.975)
a <- r
b <- s
c <- t
d <- n - r - s - t
wilson <- function(x) {
den <- n + z^2
half <- 0.5 * z * sqrt(z^2 + 4 * x * (n - x) / n)
c((x + 0.5 * z^2 - half) / den, (x + 0.5 * z^2 + half) / den)
}
w1 <- wilson(a + b) # limits for proportion 1
w2 <- wilson(a + c) # limits for proportion 2
if ((a + b) * (c + d) * (a + c) * (b + d) == 0) {
phi <- 0
} else {
num <- a * d - b * c
if (num > 0) num <- max(num - n / 2, 0)
phi <- num / sqrt((a + b) * (c + d) * (a + c) * (b + d))
}
dl1 <- p1 - w1[1]
du1 <- w1[2] - p1
dl2 <- p2 - w2[1]
du2 <- w2[2] - p2
lower <- (p1 - p2) - sqrt(dl1^2 - 2 * phi * dl1 * du2 + du2^2)
upper <- (p1 - p2) + sqrt(du1^2 - 2 * phi * du1 * dl2 + dl2^2)
cat("Score based (Newcombe) 95% confidence interval for the proportion difference:\n")
cat(six(lower), "to", six(upper), "\n")