From Gene Lists to a 2-by-2 Table
A pathway-enrichment calculation compares two binary attributes for each gene: whether it belongs to a pathway and whether it was selected by an analysis, such as a differential-expression procedure. The comparison is only meaningful relative to a defined tested-gene universe: genes eligible to be selected and included in the analysis. Using the correct universe is essential; counting genes that could never have been selected changes the margins and therefore changes the result.
Let \(N\) be the number of genes in the universe, \(M\) the number in the pathway, and \(K\) the number selected. Write \(a\) for the number both in the pathway and selected. The other three cells follow from these margins.
| Selected | Unselected | Total | |
|---|---|---|---|
| In pathway | \(a\) | \(M-a\) | \(M\) |
| Outside pathway | \(K-a\) | \(N-M-K+a\) | \(N-M\) |
| Total | \(K\) | \(N-K\) | \(N\) |
An odds ratio of 1 indicates equal observed selection odds in the two groups. An odds ratio above 1 indicates higher observed selection odds among pathway genes; a value below 1 indicates lower observed odds. The odds ratio describes association in this selected list and universe; it does not establish that pathway membership causes selection.
Fisher’s Exact Test: Conditioning on the Margins
Fisher’s exact test evaluates whether the observed overlap is unusual under a null model of no association between pathway membership and selection. Conditional on the margins \(N\), \(M\), and \(K\), the null model treats the \(K\) selected genes as a uniformly chosen subset of size \(K\) from the \(N\) genes. Equivalently, each possible value of the overlap has a hypergeometric probability. The feasible range is \(\max(0,M+K-N)\leq x\leq\min(M,K)\).
The conditional distribution is the same hypergeometric distribution used to derive over-representation from the hypergeometric distribution. Fisher’s exact test is not a different probability model in this setting: it is the test obtained by evaluating that distribution at the observed table. The word “exact” means that the tail probability is calculated from the discrete conditional distribution, rather than from a large-sample approximation.
The two-sided definition above is a widely used convention, but two-sided exact p-values are not uniquely defined for discrete distributions. Some software uses a different ordering of tables or a doubled one-sided tail. State which convention is used when results need to be reproducible. A one-sided upper-tail p-value directly answers whether the observed overlap is unusually large under the specified null model.
Worked Example: Building the Table and Calculating an Upper-Tail p-Value
Suppose a hypothetical tested-gene universe contains \(N=20\) genes. A pathway contains \(M=6\) of them, and an analysis selected \(K=8\) genes. Five genes are both selected and in the pathway, so \(a=5\). Construct the table and calculate the upper-tail Fisher p-value.
The remaining cells are \(b=M-a=6-5=1\), \(c=K-a=8-5=3\), and \(d=N-M-K+a=20-6-8+5=11\). The table is therefore \((a,b,c,d)=(5,1,3,11)\); its row and column totals agree with the stated margins.
Under the fixed-margin null, \(X\) can range from \(\max(0,6+8-20)=0\) to \(\min(6,8)=6\). The upper-tail probability includes overlaps of five and six: $$ P(X\geq 5)=\frac{\binom{6}{5}\binom{14}{3}+\binom{6}{6}\binom{14}{2}}{\binom{20}{8}} =\frac{6(364)+1(91)}{125970} =\frac{2275}{125970} \approx 0.01806. $$
Thus, under the fixed-margin null model, the probability of an overlap at least this large is about 0.0181. This is a p-value, not the probability that the null model is true. The observed overlap is large relative to this conditional reference distribution, but the result alone does not address confounding, gene dependence, or the consequences of testing many pathways.
Odds Ratios and Confidence Intervals
The cross-product odds ratio summarizes the magnitude and direction of the association in the table. For \((a,b,c,d)=(5,1,3,11)\), the estimated odds of selection among pathway genes are \(5/1=5\), while those outside the pathway are \(3/11\). Their ratio is \(5/(3/11)=18.33\), equivalently \(ad/(bc)=5(11)/(1(3))=18.33\). This is an estimated odds ratio, not a ratio of selection probabilities.
When all four cells are positive, a familiar approximate interval is the log-Wald confidence interval. Its standard error is based on the large-sample approximation for the log cross-product odds ratio. For a 95% interval, the formula is:
This interval is an approximation, not an exact interval. Its interpretation is about the odds ratio parameter: under repeated sampling and the assumptions of the model, a procedure constructed this way would cover the parameter about 95% of the time. A particular calculated interval is not a 95% probability statement about where the fixed parameter lies.
Worked Example: A Log-Wald Confidence Interval
Use the table \((5,1,3,11)\) from the previous example. All four cells are positive, so the log-Wald formula can be calculated, though the small cell count makes its approximation worth treating cautiously.
The estimated odds ratio is \(\widehat{OR}=5(11)/(1(3))=18.33\), and $$ SE\{\log(\widehat{OR})\} =\sqrt{\frac15+\frac11+\frac13+\frac1{11}} =\sqrt{1.6242} \approx 1.274. $$
Since \(\log(18.33)\approx2.909\), the log-scale endpoints are \(2.909\pm1.96(1.274)\), or approximately \(0.412\) and \(5.406\). Exponentiating gives $$ \left(\exp(0.412),\exp(5.406)\right)\approx(1.510,\ 223.1). $$
The approximate 95% interval is therefore about 1.51 to 223 for the odds ratio. It is very wide, reflecting substantial uncertainty. Although the interval lies above 1, the small cell \(b=1\) warns that the large-sample approximation may not provide reliable coverage; an exact conditional interval is a useful alternative to report.
A conditional exact confidence interval for the odds ratio can be defined by inverting tests based on the noncentral hypergeometric distribution. With fixed margins and odds ratio parameter \(\theta\), the probability of overlap \(x\) is proportional to \(\binom{M}{x}\binom{N-M}{K-x}\theta^x\), normalized by summing over the feasible values of \(x\). An equal-tailed 95% interval chooses a lower endpoint for which the conditional upper-tail probability at the observed overlap is 0.025 and an upper endpoint for which the conditional lower-tail probability is 0.025. These endpoints are generally found numerically. Unlike the log-Wald interval, this construction respects the discrete conditional model, but it may be conservative and can be wide with sparse data.
Worked Example: A Two-Sided Exact p-Value
Consider a second hypothetical universe with \(N=12\) genes, a pathway of \(M=4\) genes, and \(K=5\) selected genes. Suppose \(a=3\) selected genes are in the pathway. The other cells are \(b=1\), \(c=2\), and \(d=6\), so the table margins match \(M=4\) and \(K=5\).
The feasible overlaps are \(x=0,1,2,3,4\). Their unnormalized hypergeometric numerators, \(\binom{4}{x}\binom{8}{5-x}\), are respectively 56, 280, 336, 112, and 8. The common denominator is \(\binom{12}{5}=792\). The observed-table probability is \(112/792\). Under the probability-ordering convention, include every table with probability no greater than \(112/792\): these are \(x=0,3,4\).
Thus the two-sided Fisher p-value is $$ \frac{56+112+8}{792}=\frac{176}{792}\approx0.2222. $$
For comparison, the upper-tail p-value is \((112+8)/792\approx0.1515\). These differ because the two-sided convention also counts the sufficiently low-probability table at \(x=0\). The odds ratio is \(3(6)/(1(2))=9\). Neither p-value says that there is a 22.2% chance the null hypothesis is true.
Assumptions, Diagnostics, and Alternatives
The table calculation is straightforward, but its interpretation depends on how the table was made and on the conditional null model. Check that each gene appears once, pathway membership and selection status are assigned consistently, and the universe contains exactly the genes eligible for selection. The selected total \(K\), pathway total \(M\), and universe size \(N\) must reproduce the table margins. If the table does not add up, do not proceed to the p-value.
The fixed-margin null treats the selected set as if every subset of size \(K\) were equally plausible with respect to pathway membership. In a real analysis, genes may have different probabilities of being selected, and related genes may have correlated expression or test statistics. Such features can undermine the uniform-subset model and make a Fisher p-value poorly calibrated. The test also does not incorporate uncertainty from the selection procedure, correct for pathway overlap, or by itself account for testing many pathways.
A chi-square test of independence is a common large-sample alternative for a 2-by-2 table. It uses an asymptotic reference distribution and may be convenient when expected counts are sufficiently large, but its approximation can be inaccurate for sparse tables. Fisher’s test conditions on the margins and calculates a discrete probability exactly under its null model. Neither choice repairs an inappropriate universe or dependence that violates the null model; the choice of test does not replace study-design checks.
A zero cell is a particularly important diagnostic. In the table \((a,b,c,d)=(3,0,0,7)\), the cross-product estimate divides by zero and is infinite; the log-Wald formula cannot be evaluated. Adding 0.5 to every cell is sometimes used as a correction, but it changes the estimate and is not the unmodified Fisher test or an exact confidence interval. If a cell is zero, report the table, use a suitable exact interval or method, and explain the boundary estimate rather than silently applying a correction.
Worked Example: Interpreting a Zero Cell
In a hypothetical universe of \(N=10\) genes, suppose a pathway contains \(M=3\) genes and all \(K=3\) selected genes are in that pathway. The table is \((a,b,c,d)=(3,0,0,7)\), and its margins are consistent with the stated totals.
The only possible overlap at least as large as the observed one is \(X=3\). Consequently, $$ P(X\geq3)=\frac{\binom{3}{3}\binom{7}{0}}{\binom{10}{3}} =\frac{1}{120}\approx0.008333. $$
The sample odds ratio is infinite because both the pathway and outside selection odds have boundary counts; the cross-product denominator \(bc\) is zero. This does not mean the underlying odds ratio is known to be infinite. The data are sparse, and uncertainty should be represented with an exact conditional interval or another method appropriate to the design.
Common Pitfalls
- Using all annotated genes as the universe. If some genes were not eligible for selection, including them changes the conditional reference distribution. Use the tested-gene universe.
- Reversing the cells. Write down which row is pathway membership and which column is selection before interpreting the odds ratio. Changing the layout can invert the reported ratio.
- Calling an odds ratio a risk ratio. An odds ratio of 2 means twice the odds, not necessarily twice the probability of selection.
- Treating the exact p-value as assumption-free. “Exact” refers to the conditional calculation; it does not guarantee that selection was uniform or genes were independent in the actual analysis.
- Reporting a narrow-looking approximate interval without checking counts. Sparse cells and zeros can make the log-Wald approximation unreliable or undefined.
Check Your Understanding
Try each problem, then compare your work with the solutions below.
- A hypothetical universe has \(N=30\), a pathway has \(M=10\) genes, \(K=6\) genes are selected, and \(a=4\) are in both groups. Give the other three cells.
- For the table in Question 1, write the upper-tail Fisher p-value as a sum of hypergeometric probabilities. You do not need to evaluate it numerically.
- For a table \((a,b,c,d)=(4,2,2,8)\), calculate the cross-product odds ratio.
- Explain why an odds ratio of 4 does not necessarily mean that pathway genes are four times as likely to be selected.
Solutions. (1) \(b=M-a=6\), \(c=K-a=2\), and \(d=N-M-K+a=30-10-6+4=18\); the table is \((4,6,2,18)\). (2) Here \(X\) has \(N=30\), \(M=10\), and \(K=6\), so the upper tail is \(\sum_{x=4}^{6}\binom{10}{x}\binom{20}{6-x}/\binom{30}{6}\). (3) \(\widehat{OR}=4(8)/(2(2))=8\). (4) An odds ratio compares \(p/(1-p)\) between groups, not the probabilities \(p\) themselves; the probability ratio depends on the baseline probability.