Why Use an Odds Ratio?
For a binary trial endpoint, each participant either experiences the event or does not. Comparing the event rates in the treatment and control arms is one way to describe the treatment contrast. The odds ratio compares the odds of the event in the two arms. It is useful in many clinical settings, but it is not the same quantity as a risk ratio: odds and probabilities have different scales, especially when events are common.
Let \(p_T\) be the treatment-arm event rate and \(p_C\) the control-arm event rate. The posterior risk-ratio material provides a related way to compare these rates. Here the focus is on transforming the two rate posteriors into a posterior distribution for their odds ratio, then summarizing that distribution. The odds ratio is dimensionless. Its interpretation still depends on which event is counted and which arm is in the numerator.
From Two Beta Posteriors to an Odds-Ratio Posterior
Suppose the treatment arm has \(x_T\) events among \(n_T\) participants and the control arm has \(x_C\) events among \(n_C\). Under the binomial sampling model, and independent beta priors for the two arm-specific event rates, the posterior distributions have the form
For example, if the prior for each event rate is \(\mathrm{Beta}(a_0,b_0)\), the corresponding posterior parameters are \(a_T=a_0+x_T\), \(b_T=b_0+n_T-x_T\), and likewise for the control arm. The beta-binomial posterior calculation is not the main task here; the essential input is the two posterior distributions and their dependence structure.
For the simple two-arm model in this tutorial, assume that outcomes are conditionally independent within each arm, each participant has the same event probability within their arm, and the event is measured consistently in both arms. Also assume the priors for \(p_T\) and \(p_C\) are independent. With separate binomial likelihoods and these independent priors, the two posteriors are independent. A shared or hierarchical prior could instead induce posterior dependence; in that case, the joint posterior should be used rather than treating the rates as independent.
The odds ratio is a transformation of the pair \((p_T,p_C)\). It has no single beta distribution in general. A direct and reliable approach is to draw paired values from the two independent posteriors, transform each pair, and summarize the resulting draws. The following change of variables explains the distribution being calculated.
A Distributional Derivation
For an event rate \(p\sim\mathrm{Beta}(a,b)\), define its odds \(U=p/(1-p)\), so that \(p=U/(1+U)\). The derivative of this inverse transformation is \(dp/dU=1/(1+U)^2\). Applying the change-of-variables formula to the beta density gives
where \(B(a,b)\) is the beta function. This is the beta-prime density. Write \(U_T=p_T/(1-p_T)\) and \(U_C=p_C/(1-p_C)\). Under the independence assumption, \(U_T\) and \(U_C\) are independent, and \(\mathrm{OR}=U_T/U_C\). To obtain the density of their ratio, set \(U_T=rU_C\) and integrate over the possible values of \(U_C\). The Jacobian for this transformation is \(U_C\), yielding
This integral provides a direct numerical route to the posterior density and its quantiles. In routine analyses, simulation is often simpler: draw \(p_T^{(m)}\) and \(p_C^{(m)}\) independently from their beta posteriors, then calculate \(\mathrm{OR}^{(m)}\) for each draw. The median of those transformed draws estimates the posterior median, and their empirical quantiles estimate posterior credible limits.
Record the beta parameters for \(p_T\) and \(p_C\), and confirm whether the posterior rates are independent.
For each draw index \(m\), draw \(p_T^{(m)}\) and \(p_C^{(m)}\) jointly from the specified joint posterior. For independent posteriors, draw independently.
Calculate \(\mathrm{OR}^{(m)}=[p_T^{(m)}/(1-p_T^{(m)})]/[p_C^{(m)}/(1-p_C^{(m)})]\).
Report a posterior median and credible interval, with the event definition and arm ordering. Check the draw count and computation for stability.
Worked Examples
Worked Example: A Lower Event Rate in the Treatment Arm
Suppose a hypothetical trial observes 12 events among 100 treatment participants and 20 among 100 control participants. Use independent \(\mathrm{Beta}(1,1)\) priors for the event rates. Calculate the posterior distributions and interpret a numerical posterior summary for the odds ratio, where the event is an undesirable outcome.
The treatment posterior is \(\mathrm{Beta}(1+12,1+100-12)=\mathrm{Beta}(13,89)\). The control posterior is \(\mathrm{Beta}(1+20,1+100-20)=\mathrm{Beta}(21,81)\). Under the independent-prior model, these posteriors are independent.
For any posterior pair \(p_T,p_C\), the transformation is
For illustration, a posterior draw with \(p_T=0.13\) and \(p_C=0.21\) gives treatment odds \(0.13/0.87=0.1494\), control odds \(0.21/0.79=0.2658\), and \(\mathrm{OR}=0.1494/0.2658=0.5621\). In an actual analysis, many such draws are transformed. Numerical posterior calculation for these beta distributions gives a median odds ratio of about 0.55 and an equal-tailed 95% credible interval of approximately 0.26 to 1.18.
Conditional on the model, prior, and observed data, the posterior probability that the treatment-to-control event odds ratio lies between 0.26 and 1.18 is approximately 95%. The interval includes 1, so it retains values corresponding to equal event odds as well as values on either side. The median points toward lower event odds with treatment, but the interval indicates substantial uncertainty about the direction.
Worked Example: Higher Event Odds With Treatment
In a second hypothetical trial, 30 of 80 treatment participants and 15 of 80 control participants experience the event. Take independent \(\mathrm{Beta}(1,1)\) priors. Calculate the posteriors and interpret a numerical odds-ratio summary.
The treatment posterior is \(\mathrm{Beta}(31,51)\), and the control posterior is \(\mathrm{Beta}(16,66)\). For one illustrative pair of posterior rates, \(p_T=0.38\) and \(p_C=0.19\), the treatment odds are \(0.38/0.62=0.6129\), and the control odds are \(0.19/0.81=0.2346\). Thus the draw-specific odds ratio is \(0.6129/0.2346=2.613\).
Transforming a large set of independent draws from the two beta posteriors gives, for example, a posterior median near 2.5 and an equal-tailed 95% credible interval of about 1.25 to 5.1. The numerical summaries are rounded. Under this model and these data, the treatment-arm event odds are estimated to be higher; the interval is above 1. If the event is harmful, this direction is unfavorable. It is not a statement that the treatment caused the events: the interpretation is conditional on the trial design, measurement, and statistical model.
Worked Example: Odds Ratio Is Not Risk Ratio
Consider a hypothetical trial with 40 events among 100 treatment participants and 20 among 100 control participants, with independent \(\mathrm{Beta}(1,1)\) priors. Compare the observed risk ratio with the scale of the posterior odds-ratio summary.
The observed event rates are \(40/100=0.40\) and \(20/100=0.20\). The observed risk ratio is \(0.40/0.20=2.00\). The observed odds are \(0.40/0.60=0.6667\) in treatment and \(0.20/0.80=0.2500\) in control, so the observed odds ratio is \(0.6667/0.2500=2.667\). The odds ratio is farther from 1 because the event is not rare.
The posterior distributions are \(\mathrm{Beta}(41,61)\) for treatment and \(\mathrm{Beta}(21,81)\) for control. Numerical transformation of independent draws gives a posterior odds-ratio median of roughly 2.6, a 95% credible interval of about 1.4 to 4.9, and a posterior probability \(P(\mathrm{OR}>1\mid\text{data})\) of approximately 0.998. These are odds-scale summaries; none should be reported as a risk ratio. In particular, a posterior median odds ratio need not equal the odds ratio formed from posterior mean event rates.
Interpreting Summaries and Checking the Calculation
A posterior median is the value that divides the posterior probability into two equal parts: half lies below it and half above it. An equal-tailed 95% credible interval has 2.5% posterior probability below its lower endpoint and 2.5% above its upper endpoint. Given the model, prior, and data, the posterior probability that the odds ratio lies in this interval is 95%. This is a probability statement about the parameter under the posterior, not a statement that the parameter has a 95% chance of being in a fixed interval under repeated sampling.
Since \(\mathrm{OR}=1\) corresponds to equal event odds, an interval that includes 1 does not exclude equal odds at the stated posterior probability level. An interval entirely below 1 supports lower event odds in treatment; an interval entirely above 1 supports higher event odds in treatment. These are directional descriptions, not automatic clinical judgments: the event's importance, the size of the effect, and the study context matter.
The log odds ratio, \(\log(\mathrm{OR})\), can be useful for computation because the ratio becomes a difference of log odds. Transforming every posterior draw to the log scale and then exponentiating its median and interval endpoints gives the same summaries as summarizing the odds-ratio draws directly, because the exponential function is strictly increasing. But posterior medians do not generally obey addition or subtraction: the median log odds ratio is not guaranteed to equal the difference between the separate posterior medians of the log odds.
- Check the arm order. Reversing treatment and control changes the odds ratio to its reciprocal. State explicitly which arm is in the numerator.
- Check the event definition. Reversing event and non-event also changes the odds ratio to its reciprocal. State whether the event is, for example, recovery or an adverse outcome.
- Check posterior dependence. Independent draws are appropriate only when the joint posterior factorizes. A shared prior or joint model may require paired draws that preserve dependence.
- Check Monte Carlo stability. With too few draws, estimated quantiles can vary noticeably. Increase the number of draws and compare summaries across runs; inspect the input rate draws and transformed values for coding or arm-label errors.
A common mistake is to calculate the odds ratio from two posterior means and label that value the posterior median odds ratio. For example, forming \([\mathbb{E}(p_T\mid\text{data})/(1-\mathbb{E}(p_T\mid\text{data}))]/[\mathbb{E}(p_C\mid\text{data})/(1-\mathbb{E}(p_C\mid\text{data}))]\) applies a nonlinear function to the means. In general, that is not the median—or the mean—of the transformed joint posterior. The correction is to transform each joint posterior draw and then calculate the desired summary from those transformed draws, or to calculate it from the ratio density.
The calculation also relies on the two-arm binomial model and the specified prior structure. If follow-up differs in a way that affects event opportunity, participants are not independent, or the endpoint definition differs across arms, the simple model may not describe the data adequately. The odds ratio alone also does not give absolute event rates: a similar odds ratio can correspond to different absolute differences in risk at different baseline event rates.
Check Your Understanding
Answer each item, then compare with the solutions below.
- A posterior draw has \(p_T=0.20\) and \(p_C=0.10\). Calculate the treatment-to-control odds ratio.
- With independent \(\mathrm{Beta}(1,1)\) priors, a hypothetical trial observes 8 events among 60 treatment participants and 12 among 60 control participants. Give each posterior distribution.
- For the data in question 2, calculate the odds ratio formed from the two posterior mean rates. Is this automatically the posterior median odds ratio?
- A 95% posterior credible interval for the treatment-to-control odds ratio is 0.72 to 1.34. What does its inclusion of 1 imply?
- If the outcome is a beneficial event, how should an odds ratio below 1 be described?
Solutions. (1) Treatment odds are \(0.20/0.80=0.25\); control odds are \(0.10/0.90=0.1111\). Thus \(\mathrm{OR}=0.25/0.1111=2.25\). (2) Treatment: \(\mathrm{Beta}(1+8,1+60-8)=\mathrm{Beta}(9,53)\). Control: \(\mathrm{Beta}(1+12,1+60-12)=\mathrm{Beta}(13,49)\). (3) The posterior means are \(9/62=0.1452\) and \(13/62=0.2097\). The odds ratio formed from these means is \((9/53)/(13/49)=441/689=0.6401\). This is a transformation of posterior means, not automatically the posterior median of the odds-ratio distribution; that median requires transforming the joint posterior and summarizing the result. (4) The interval includes 1, the value for equal odds, so it includes equal-odds values as well as values indicating either direction. (5) An odds ratio below 1 means lower odds of the beneficial event in treatment than in control, which points in an unfavorable direction for that outcome.