Tutorials › Introduction to Statistics › Deriving a Confidence Interval for an Odds Ratio

Two-Proportion Inference · Tutorial 717 of 996

Deriving a Confidence Interval for an Odds Ratio

Learn how the four cell counts determine uncertainty in an odds ratio and how to construct and interpret a confidence interval.

Intermediate 10 min read

What You'll Learn

  • Arrange two independent groups’ binary outcomes as four cell counts.
  • Calculate the sample odds ratio and its logarithm.
  • Derive the estimated standard error of the log odds ratio.
  • Construct a large-sample confidence interval on the log scale.
  • Exponentiate both endpoints and interpret the odds ratio interval.
  • Identify assumptions and common calculation pitfalls.

Why Build the Interval on the Log Scale?

An odds ratio compares the odds of an outcome in one group with the odds in another. Its estimate is positive and can range from nearly zero to arbitrarily large values, so an interval built directly by adding and subtracting a margin of error can be awkward: it might even have a negative lower endpoint. Taking the logarithm changes the ratio into a difference, gives a standard large-sample standard error, and makes a symmetric interval practical. The final step is to exponentiate the interval endpoints to return to the odds-ratio scale.

This tutorial considers two independent groups and a binary outcome, such as whether a hypothetical participant experiences an event. The groups could be assigned treatments or arise from a comparison of existing groups; the odds ratio describes their association with the outcome, not by itself a causal effect.

Four Counts and the Odds Ratio

Let \(a\) and \(b\) be the numbers with and without the outcome in group 1, and let \(c\) and \(d\) be the corresponding counts in group 2. Each group total is fixed by its two counts: \(n_1=a+b\) and \(n_2=c+d\). The odds of the outcome in group 1 are \(a/b\), and those in group 2 are \(c/d\).

Definition: The population odds ratio comparing group 1 with group 2 is \(\theta=\{p_1/(1-p_1)\}/\{p_2/(1-p_2)\}\), where \(p_1\) and \(p_2\) are the population outcome probabilities in the two groups. Its sample estimate from the four cell counts is \(\widehat{OR}=(a/b)/(c/d)=ad/(bc)\). The corresponding log odds ratio estimate is \(\log(\widehat{OR})=\log(a)+\log(d)-\log(b)-\log(c)\).

The comparison order matters: \(\widehat{OR}\) here is group 1 odds divided by group 2 odds. Reversing the groups gives the reciprocal, \(1/\widehat{OR}\). An odds ratio of 1 means equal odds; a value above 1 means greater estimated odds in group 1, and a value below 1 means lower estimated odds in group 1.

Worked Example: Calculating an Odds Ratio

Suppose a hypothetical comparison records the outcome for 300 people in group 1 and 300 in group 2. In group 1, 90 have the outcome and 210 do not; in group 2, 60 have it and 240 do not. Estimate the odds ratio, with group 1 in the numerator.

The estimated odds are \(90/210\) in group 1 and \(60/240\) in group 2. Therefore,

$$ \widehat{OR} =\frac{90/210}{60/240} =\frac{90\times240}{210\times60} =\frac{21600}{12600} =\frac{12}{7} \approx 1.714. $$

The estimated odds of the outcome in group 1 are about 1.714 times the estimated odds in group 2. The log estimate should be calculated from the unrounded ratio: \(\log(\widehat{OR})=\log(12/7)\approx0.5390\). Using an unrounded value avoids small discrepancies caused by taking a logarithm of an already rounded ratio.

Deriving the Standard Error

The standard error describes the sampling variability of the log odds ratio estimate. To derive it, assume each group is an independent sample and the outcome for each individual is binary. Within group \(i\), the number of outcomes has a binomial model with sample size \(n_i\) and population probability \(p_i\). Thus the sample proportion \(\hat p_i\) has approximate variance \(p_i(1-p_i)/n_i\).

The estimated log odds in a group can be written as the logit of its sample proportion, \(g(\hat p_i)=\log\{\hat p_i/(1-\hat p_i)\}\). The derivative of \(g(p)=\log\{p/(1-p)\}\) is \(g'(p)=1/\{p(1-p)\}\). The delta method says that, for a smooth function of an estimate, its approximate variance is the variance of the estimate multiplied by the square of the function’s derivative. Applying it here gives the following approximation:

$$ \operatorname{Var}\{g(\hat p_i)\} \approx \left(\frac{1}{p_i(1-p_i)}\right)^2 \frac{p_i(1-p_i)}{n_i} = \frac{1}{n_i p_i(1-p_i)}. $$

Replace the unknown probability \(p_i\) by the observed proportion \(x_i/n_i\), where \(x_i\) is the number with the outcome. Since \(n_i-x_i\) is the number without it, the estimated variance becomes

$$ \frac{1}{n_i(x_i/n_i)(1-x_i/n_i)} = \frac{n_i}{x_i(n_i-x_i)} = \frac{1}{x_i}+\frac{1}{n_i-x_i}. $$

The log odds ratio is the group 1 log odds minus the group 2 log odds. Because the groups are independent, the estimated variances of these two log odds add. Substituting the four cell counts gives the standard error formula.

Result: For independent groups with sufficiently large cell counts, the estimated standard error of the sample log odds ratio is \[ SE\{\log(\widehat{OR})\} = \sqrt{\frac{1}{a}+\frac{1}{b}+\frac{1}{c}+\frac{1}{d}}. \] This is a large-sample approximation. It requires all four counts to be positive, and it can be unreliable when counts are very small.

Constructing and Interpreting the Confidence Interval

Under the large-sample approximation, the estimate \(\log(\widehat{OR})\) is approximately normally distributed around the population log odds ratio \(\log(\theta)\), with estimated standard error given above. For a confidence level \(C\), let \(z^*\) be the standard normal critical value with central area \(C\). The confidence interval on the log scale is the estimate plus or minus \(z^*\) standard errors.

$$ \log(\widehat{OR})\ \pm\ z^* \sqrt{\frac{1}{a}+\frac{1}{b}+\frac{1}{c}+\frac{1}{d}}. $$

The exponential function is increasing, so exponentiating the lower and upper log-scale endpoints preserves their order and gives a confidence interval for \(\theta\). A 95% interval uses \(z^*\approx1.96\). The resulting interval is generally asymmetric around \(\widehat{OR}\), even though the interval on the log scale is symmetric around \(\log(\widehat{OR})\).

1
Set the group order.
Label the outcome and no-outcome counts \(a,b\) for group 1 and \(c,d\) for group 2. This fixes the direction of the odds ratio.
2
Calculate the estimate and its standard error.
Compute \(\widehat{OR}=ad/(bc)\), then calculate \(\log(\widehat{OR})\) and the four-count standard error.
3
Form the interval on the log scale.
Add and subtract \(z^*SE\) from \(\log(\widehat{OR})\) to obtain the lower and upper endpoints.
4
Exponentiate both endpoints.
The exponentiated values are the lower and upper confidence limits for the odds ratio. Interpret them in the stated group order.

Worked Example: A 95% Confidence Interval

Use the hypothetical counts from the first example: \(a=90\), \(b=210\), \(c=60\), and \(d=240\). Construct and interpret a 95% confidence interval for the population odds ratio comparing group 1 with group 2. Suppose the independent groups and binary outcomes described above are appropriate, and assume the counts are large enough for the large-sample approximation.

The estimated odds ratio is \(12/7\), so its unrounded log estimate is \(\log(12/7)\approx0.5390\). The estimated standard error is

$$ SE = \sqrt{\frac{1}{90}+\frac{1}{210}+\frac{1}{60}+\frac{1}{240}} = \sqrt{0.0367063} \approx0.1916. $$

For 95% confidence, use \(z^*=1.96\). The margin of error on the log scale is \(1.96(0.1916)\approx0.3755\), giving endpoints \(0.5390-0.3755=0.1635\) and \(0.5390+0.3755=0.9145\), to the displayed precision. Exponentiating both endpoints gives

$$ \left[\exp(0.1635),\ \exp(0.9145)\right] \approx[1.178,\ 2.496]. $$

The interval estimates that the population odds of the outcome in group 1 are between about 1.178 and 2.496 times the population odds in group 2. In repeated sampling under the stated conditions, this method produces intervals that contain the population odds ratio about 95% of the time. It does not mean that there is a 95% probability that this particular fixed population parameter lies in the calculated interval.

Worked Example: An Estimated Odds Ratio Below One

In a second hypothetical comparison, group 1 has 18 outcomes and 82 non-outcomes, while group 2 has 36 outcomes and 64 non-outcomes. Construct a 95% confidence interval for the odds ratio comparing group 1 with group 2. Assume the samples are independent, the outcome is binary, and the observed counts support the large-sample approximation.

The sample odds ratio and its logarithm, calculated without rounding the ratio first, are

$$ \widehat{OR} = \frac{18\times64}{82\times36} = \frac{1152}{2952} = \frac{16}{41} \approx0.3902, \qquad \log(\widehat{OR})=\log(16/41)\approx-0.9410. $$

The standard error is

$$ SE = \sqrt{\frac{1}{18}+\frac{1}{82}+\frac{1}{36}+\frac{1}{64}} = \sqrt{0.111154} \approx0.3334. $$

The 95% margin is \(1.96(0.3334)\approx0.6535\). Thus the log-scale endpoints are approximately \(-0.9410-0.6535=-1.5944\) and \(-0.9410+0.6535=-0.2875\). Exponentiating gives

$$ [\exp(-1.5944),\ \exp(-0.2875)] \approx[0.203,\ 0.750]. $$

The estimated odds in group 1 are lower than those in group 2, and the interval expresses the uncertainty around that comparison in the same group order. Reversing the comparison would invert the estimate and reverse the interval endpoints after taking reciprocals; it would not change the underlying data.

Worked Example: Using a 90% Confidence Level

A third hypothetical comparison has \(a=45\), \(b=155\), \(c=30\), and \(d=170\). Assume independent groups, binary outcomes, and counts adequate for the normal approximation. Construct a 90% confidence interval for the odds ratio for group 1 relative to group 2.

The estimate is \(\widehat{OR}=(45\times170)/(155\times30)=7650/4650\approx1.6452\), and \(\log(\widehat{OR})\approx0.4978\). The standard error is

$$ SE = \sqrt{\frac{1}{45}+\frac{1}{155}+\frac{1}{30}+\frac{1}{170}} = \sqrt{0.0678895} \approx0.2606. $$

For a central 90% interval, \(z^*\approx1.645\). The margin is \(1.645(0.2606)\approx0.4286\). The log-scale limits are approximately \(0.4978-0.4286=0.0692\) and \(0.4978+0.4286=0.9265\). Therefore,

$$ [\exp(0.0692),\ \exp(0.9265)] \approx[1.072,\ 2.526]. $$

This 90% interval estimates the population odds ratio for group 1 relative to group 2. Its confidence level is lower than that of a 95% interval constructed from the same data, so its margin on the log scale is smaller.

Assumptions and Common Pitfalls

Before relying on this interval, check that the data fit the comparison being described. Each individual contributes to one group and has one binary outcome; observations within a group should be independent under the sampling or study design, and the two groups should be independent of one another. The large-sample approximation also needs enough information in each of the four cells for the log odds ratio to behave approximately normally. There is no single count cutoff that guarantees good approximation in every setting. A zero cell makes the displayed estimate or standard error undefined, and a very small cell can make the interval unstable.

  • Using the wrong group order. Mixing the group 1 and group 2 cells changes the odds ratio to its reciprocal. Label the groups before calculating.
  • Using an unpooled proportion-difference standard error. The formula here is for the log odds ratio and uses the reciprocals of all four cell counts. It is not the standard error for a difference in proportions.
  • Exponentiating only the estimate. The confidence limits come from exponentiating both log-scale endpoints, not from adding and subtracting a margin directly on the odds-ratio scale.
  • Rounding too early. Keep the odds ratio unrounded when taking its logarithm, and round the reported endpoints only after exponentiation. For example, \(\log(16/41)\approx-0.9410\); computing from a rounded odds ratio can shift the last digits.
  • Treating a confidence level as a probability for this interval. The 95% statement concerns the long-run performance of the interval procedure under its assumptions, not a 95% probability that the fixed population odds ratio is inside the observed limits.
Key takeaway: For two independent groups with a binary outcome, estimate the odds ratio from the four cell counts, calculate uncertainty on the log scale using \(\sqrt{1/a+1/b+1/c+1/d}\), and exponentiate the log-scale interval endpoints to report a confidence interval for the odds ratio.

Check Your Understanding

Try these questions before moving on.

  1. For counts \(a=24\), \(b=76\), \(c=15\), and \(d=85\), write the sample odds ratio comparing group 1 with group 2 as a ratio of cell-count products.
  2. Why are the four reciprocal cell counts added in the estimated variance of the log odds ratio?
  3. What steps convert a log-scale confidence interval into an interval for the odds ratio?
  4. If the group order is reversed, how is the estimated odds ratio changed?
  5. Why is it incorrect to interpret a 95% confidence interval as giving a 95% probability that the fixed population odds ratio lies within the interval?