You can use an exact test based on a hypergeometric distribution: Fisher's Exact Test. R statistical software has such a test fisher.test
, which requires a $2 \times 2$ table of successes and failures.
Suppose you have $x_1 = 4$ successes from $n_1 = 16$ subjects for an estimate $\hat p_1 = .25$ from Group 1 and $n_2 = 12$ successes is $n_2 = 18$ for $\hat p_2 = 0.67.$ Are $\hat p_1$ and $\hat p_2$ significantly different at the 5% level? The table TBL
and test are as follows. The P-value $0.02 < 0.05 = 5\%$ indicates that
the two groups gave significantly different results.
TAB = rbind(c(4, 12), c(12, 6)); TAB
[,1] [,2]
[1,] 4 12
[2,] 12 6
fisher.test(TAB)
Fisher's Exact Test for Count Data
data: TAB
p-value = 0.02042
alternative hypothesis: true odds ratio is not equal to 1
95 percent confidence interval:
0.02802673 0.90758654
sample estimates:
odds ratio
0.1768846
For sample sizes below 20 or so, the difference in observed proportions has
to be quite large, as here, in order to get a significant result at the 5% level.
An alternative test is a chi-squared test using the same kind of table. This is
an approximate test, especially for small counts. There is controversy whether
to use Yates' continuity correction (which tends to give P-values that are somewhat
too large) or not (P-values may be too small). The implementation of chisq.test
in R can simulate a more reliable P-value (often nearly matching that of Fisher's Exact Test).
chisq.test(TAB, sim=T)
Pearson's Chi-squared test
with simulated p-value
(based on 2000 replicates)
data: TAB
X-squared = 5.9028, df = NA, p-value = 0.02249
Both tests will accept $2 \times k$ tables in case you want to begin by
looking for differences among $k$ groups. [If $k$ is too large, the simulations
involved may overwhelm available computer memory customarily allocated to R
or your patience waiting for the result. (Without sim=T
the chi-squared test
does not use simulation.)]