Tutorials › Bayesian Clinical Trials › Deriving a Posterior Risk Difference

Posterior Inference for Trial Endpoints · Tutorial 5 of 696

Deriving a Posterior Risk Difference

Learn how independent beta-binomial models for two trial arms induce a posterior distribution for their risk difference and how to summarize it in context.

Beginner 10 min read

What You'll Learn

  • Define the risk difference as the treatment-arm event probability minus the control-arm event probability.
  • Derive each arm’s beta posterior from its binomial likelihood and beta prior.
  • Obtain the posterior density, mean, and variance of the difference under independent arm posteriors.
  • Calculate a posterior probability that the treatment-arm event risk is higher.
  • Construct and interpret an equal-tailed credible interval, including when numerical integration is needed.
  • Identify how dependence, endpoint coding, and prior choices affect the analysis.

Why Compare Risks by Their Difference?

For a binary trial endpoint, the event risk in each arm is a probability. A risk difference expresses the absolute contrast between the two risks on the probability scale. It is often directly useful for clinical interpretation: a difference of \(-0.05\) means five fewer events per 100 participants in the treatment arm than in the control arm, when the endpoint is coded as an undesirable event. The sign depends on which arm is subtracted from which, so that convention must be explicit.

This tutorial derives the posterior distribution of that contrast from two binomial arm models. The posterior distribution of a difference is generally not itself a beta distribution. Instead, it is induced by the two arm-specific posterior distributions, and its summaries can be calculated from those distributions.

Definition: Let \(p_T\) be the probability of the endpoint event in the treatment arm and \(p_C\) the probability of the same event in the control arm. The risk difference is \(D=p_T-p_C\). Thus, \(D<0\) means lower event risk under treatment, and \(D>0\) means higher event risk under treatment. The parameter satisfies \(-1\leq D\leq 1\).

Model and Posterior Distribution

Suppose the trial has \(n_T\) participants in the treatment arm and \(n_C\) in the control arm. Let \(X_T\) and \(X_C\) be the numbers with the event, with observed counts \(x_T\) and \(x_C\). The arm-specific sampling model is

$$ X_T\mid p_T\sim\operatorname{Binomial}(n_T,p_T), \qquad X_C\mid p_C\sim\operatorname{Binomial}(n_C,p_C). $$

The likelihood assumes that, within each arm, participants’ endpoint indicators are conditionally independent Bernoulli observations with a common event probability for that arm. The binomial model also treats the denominators and endpoint definitions as fixed for this analysis. A beta prior is specified for each arm:

$$ p_T\sim\operatorname{Beta}(a_T,b_T), \qquad p_C\sim\operatorname{Beta}(a_C,b_C). $$

For the standard two-independent-arm analysis, the prior distributions for \(p_T\) and \(p_C\) are independent. Together with the factorized arm likelihood, this gives independent posterior distributions. Independence is a modeling assumption about the unknown risks, not a claim that the observed treatment and control outcomes are identical or that the trial was unrandomized.

Theorem: Under the binomial sampling models and independent beta priors above, the posterior distributions are independent and $$ p_T\mid x_T\sim\operatorname{Beta}(A_T,B_T), \qquad p_C\mid x_C\sim\operatorname{Beta}(A_C,B_C), $$ where \(A_T=a_T+x_T\), \(B_T=b_T+n_T-x_T\), \(A_C=a_C+x_C\), and \(B_C=b_C+n_C-x_C\). The posterior distribution of \(D=p_T-p_C\) is the distribution of the difference of independent random variables with these two beta distributions.

The beta-binomial update follows directly from Bayes’ rule. For one arm, the likelihood as a function of its event probability is proportional to \(p^x(1-p)^{n-x}\), while the beta prior density is proportional to \(p^{a-1}(1-p)^{b-1}\). Multiplying them gives

$$ p^x(1-p)^{n-x}p^{a-1}(1-p)^{b-1} \propto p^{a+x-1}(1-p)^{b+n-x-1}. $$

This is the kernel of a \(\operatorname{Beta}(a+x,b+n-x)\) density. Since the two likelihoods and the two prior densities factor across arms, their posterior also factors, establishing posterior independence under the stated assumptions.

How to Describe the Distribution of the Difference

There is usually no standard named distribution for \(D\). Its density can nevertheless be written using the arm-specific posterior densities \(f_T\) and \(f_C\). For \(-1<d<1\), convolution gives

$$ f_D(d)= \int_{\max(0,d)}^{\min(1,1+d)} f_T(t)f_C(t-d)\,dt. $$

The limits ensure that both \(t=p_T\) and \(t-d=p_C\) lie between 0 and 1. An equivalent expression for its cumulative distribution function is

$$ F_D(d)=P(D\leq d\mid x_T,x_C) =\int_0^1 f_T(t)F_C(t-d)\,dt, $$

where \(F_C(u)=0\) for \(u<0\), \(F_C(u)=1\) for \(u>1\), and \(F_C\) is the control-arm posterior cumulative distribution function on \([0,1]\). This expression makes it possible to calculate posterior probabilities and quantiles by integration or numerical methods.

The posterior mean and variance of the difference have simpler formulas. For a beta distribution with parameters \(A,B\), the mean is \(A/(A+B)\) and the variance is \(AB/[(A+B)^2(A+B+1)]\). Independence means the covariance between the two arm risks is zero, so the variance of their difference is the sum of their variances.

$$ E(D\mid x_T,x_C) = \frac{A_T}{A_T+B_T}-\frac{A_C}{A_C+B_C}, $$
$$ \operatorname{Var}(D\mid x_T,x_C) = \frac{A_TB_T}{(A_T+B_T)^2(A_T+B_T+1)} + \frac{A_CB_C}{(A_C+B_C)^2(A_C+B_C+1)}. $$

The posterior standard deviation is the square root of this variance. It describes posterior spread in probability units; multiplying a risk difference or its standard deviation by 100 expresses it in percentage points.

Worked Example: Updating Both Arms and Summarizing the Difference

Consider a hypothetical trial with 8 events among 40 participants in the treatment arm and 10 among 40 in the control arm. Use independent \(\operatorname{Beta}(1,1)\) priors for the two event risks. Calculate the posterior mean and standard deviation of \(D=p_T-p_C\).

The treatment posterior is \(\operatorname{Beta}(1+8,1+40-8)=\operatorname{Beta}(9,33)\). The control posterior is \(\operatorname{Beta}(1+10,1+40-10)=\operatorname{Beta}(11,31)\). Both posteriors have total parameter 42, so their means are \(9/42=0.2143\) and \(11/42=0.2619\), respectively. Therefore,

$$ E(D\mid x_T,x_C)=\frac{9}{42}-\frac{11}{42} =-\frac{2}{42}=-0.04762. $$

The posterior mean risk difference is \(-4.762\) percentage points: averaged over the posterior distribution, treatment has a lower event risk. This is a posterior estimate, not a statement that every plausible value of \(D\) is negative.

For the treatment risk, the posterior variance is \(9(33)/[42^2(43)]=297/75852=0.003916\). For the control risk, it is \(11(31)/[42^2(43)]=341/75852=0.004495\). By posterior independence,

$$ \operatorname{Var}(D\mid x_T,x_C) =\frac{297+341}{75852} =0.008412, \qquad SD(D\mid x_T,x_C)=\sqrt{0.008412}=0.09172. $$

Thus the posterior standard deviation is 9.172 percentage points. It is not a credible interval: the standard deviation alone does not give the posterior probability that the risk difference lies in a particular range.

Posterior Probabilities and Credible Intervals

A probability about the risk difference is calculated under its posterior distribution. For example, the posterior probability that the treatment risk is higher than the control risk is \(P(D>0\mid x_T,x_C)\). Using the control posterior cumulative distribution function, this probability is

$$ P(D>0\mid x_T,x_C)=\int_0^1 f_T(t)F_C(t)\,dt. $$

The expression follows by conditioning on \(p_T=t\): the event \(p_T>p_C\) has conditional posterior probability \(F_C(t)\). A \(100(1-\alpha)\%\) equal-tailed credible interval for \(D\) has endpoints \(q_{\alpha/2}\) and \(q_{1-\alpha/2}\), where \(q_r\) is the posterior \(r\)-quantile satisfying \(F_D(q_r)=r\). Because the difference distribution is generally not a beta distribution, these endpoints are commonly obtained by numerical integration or by sampling independently from the two beta posteriors and taking their differences.

Worked Example: Calculating a Posterior Probability of Higher Treatment Risk

For a small hypothetical illustration, suppose one event is observed among one treatment participant and no events among one control participant. Give both arms independent \(\operatorname{Beta}(1,1)\) priors. Find \(P(p_T>p_C\mid x_T,x_C)\).

The updated treatment distribution is \(\operatorname{Beta}(2,1)\), with density \(f_T(t)=2t\) for \(0<t<1\). The updated control distribution is \(\operatorname{Beta}(1,2)\), whose cumulative distribution function on this range is \(F_C(t)=1-(1-t)^2=2t-t^2\). Therefore,

$$ P(p_T>p_C\mid x_T,x_C) =\int_0^1 2t(2t-t^2)\,dt =\left[\frac{4t^3}{3}-\frac{t^4}{2}\right]_0^1 =\frac{5}{6}=0.8333. $$

Under this model and these data, the posterior probability that the treatment-arm event risk exceeds the control-arm risk is 83.33%. It is not the probability that a null hypothesis is true, nor does it by itself establish a clinically important difference. The example is deliberately small; its probability is strongly affected by the prior and sparse observations.

Worked Example: A Difference with a Positive Posterior Mean

In another hypothetical trial, suppose there are 3 events among 10 treatment participants and 1 event among 10 control participants. Again use independent \(\operatorname{Beta}(1,1)\) priors. Calculate the posterior mean and standard deviation of the risk difference.

The posteriors are \(\operatorname{Beta}(4,8)\) for treatment and \(\operatorname{Beta}(2,10)\) for control. The respective posterior means are \(4/12=0.3333\) and \(2/12=0.1667\), giving

$$ E(D\mid x_T,x_C)=\frac{4}{12}-\frac{2}{12} =\frac{1}{6}=0.1667. $$

The posterior mean difference is 16.67 percentage points, in the direction of higher event risk in the treatment arm. The posterior variances are \(4(8)/[12^2(13)]=32/1872\) and \(2(10)/[12^2(13)]=20/1872\). Hence

$$ \operatorname{Var}(D\mid x_T,x_C)=\frac{52}{1872} =\frac{1}{36}=0.02778, \qquad SD(D\mid x_T,x_C)=\frac{1}{6}=0.1667. $$

The positive mean does not imply that the entire posterior distribution is positive. A posterior probability such as \(P(D>0\mid x_T,x_C)\), or a credible interval, is needed to describe how much posterior mass lies on each side of zero.

Worked Example: An Equal-Tailed Interval Before Observing Events

As a calculation check, take independent \(\operatorname{Beta}(1,1)\) distributions for both risks and suppose no endpoint observations have yet been made. The posterior then equals the prior. Find the 95% equal-tailed interval for \(D\).

The two risks are independent uniform random variables on \([0,1]\). For \(-1\leq d\leq0\), the event \(p_T-p_C\leq d\) occupies a right triangle of area \((1+d)^2/2\) in the unit square of possible risk pairs. Thus \(F_D(d)=(1+d)^2/2\) on that range. Symmetry gives \(F_D(d)=1-(1-d)^2/2\) for \(0\leq d\leq1\). Setting the lower endpoint’s cumulative probability to 0.025 gives

$$ \frac{(1+d)^2}{2}=0.025 \quad\Longrightarrow\quad d=\sqrt{0.05}-1=-0.7764. $$

By symmetry, the upper endpoint is \(0.7764\). The equal-tailed 95% interval is therefore \([-0.7764,0.7764]\), an intentionally broad prior interval. It means that, under this prior model before observing events, 95% of the posterior probability lies between those endpoints; it is not a frequentist coverage statement.

Diagnostics, Alternatives, and Limitations

Before interpreting a result, check the model inputs and the numerical calculation. Confirm that each numerator counts the same event over its stated arm denominator, that the event is coded consistently, and that treatment-minus-control is the intended subtraction order. Verify the prior parameters and posterior updates separately for each arm. The computed posterior for \(D\) must lie within \([-1,1]\), and its probability density must integrate to one. A simulated calculation should use independent draws from the two arm posteriors and calculate treatment draw minus control draw on every iteration; reversing this subtraction reverses the sign of all summaries.

Independent beta priors are a transparent default, but they are not the only possible model. If prior information links the arm risks, the posterior covariance need not be zero. In that case the variance identity is

$$ \operatorname{Var}(p_T-p_C\mid\text{data}) =\operatorname{Var}(p_T\mid\text{data}) +\operatorname{Var}(p_C\mid\text{data}) -2\operatorname{Cov}(p_T,p_C\mid\text{data}), $$

and the independent-arm formulas cannot be used without justification. Other approaches may model the two risks jointly or report arm-specific posterior summaries. Separate arm summaries are useful, but they do not replace a direct posterior summary of their difference: the contrast’s uncertainty and probability statements concern the joint posterior for both risks.

The risk difference is an absolute effect measure. Its value and clinical interpretation depend on the event definition, follow-up period, and population being analyzed. The binomial model does not automatically address loss to follow-up, varying follow-up time, clustering, or departures from a common event probability within an arm. Those features may require a different likelihood or additional model structure. Finally, a posterior calculation is conditional on the specified likelihood and priors; a precise numerical answer does not remove sensitivity to those assumptions.

Common pitfall: A reader may subtract the observed proportions, obtain a negative value, and conclude that treatment has a high posterior probability of reducing risk. The observed difference is not itself a posterior probability and does not describe uncertainty. Update each arm’s risk distribution, form \(D=p_T-p_C\), and calculate the desired posterior probability or interval from that difference distribution.

Check Your Understanding

Answer each question using the treatment-minus-control convention. Solutions follow each question.

  1. A hypothetical treatment arm has 6 events among 30 participants, and a control arm has 9 among 30. With independent \(\operatorname{Beta}(1,1)\) priors, what are the two posterior distributions?

    Solution: Treatment is \(\operatorname{Beta}(1+6,1+30-6)=\operatorname{Beta}(7,25)\). Control is \(\operatorname{Beta}(1+9,1+30-9)=\operatorname{Beta}(10,22)\).

  2. If the endpoint is an undesirable event and the posterior mean of \(D\) is \(-0.03\), interpret it.

    Solution: The posterior mean treatment risk is 3 percentage points lower than the posterior mean control risk. This does not show that the probability \(D<0\) is 1; that probability requires the posterior distribution of \(D\).

  3. Under independent arm posteriors, how is the variance of \(D\) obtained?

    Solution: Add the posterior variances of \(p_T\) and \(p_C\): \(\operatorname{Var}(D\mid\text{data})=\operatorname{Var}(p_T\mid\text{data})+\operatorname{Var}(p_C\mid\text{data})\). Independence makes their posterior covariance zero.

  4. What does a 95% equal-tailed credible interval for \(D\) mean?

    Solution: Conditional on the model, priors, and observed data, the interval contains 95% of the posterior probability for \(D\), with 2.5% in each tail. It is not a statement that there is a 95% repeated-sampling chance that a fixed parameter lies in this particular interval.

  5. A calculation reports \(P(p_C>p_T\mid\text{data})=0.82\). What is the corresponding probability for the treatment-minus-control risk difference to be positive?

    Solution: Since the posterior is continuous, \(P(D=0\mid\text{data})=0\). Therefore \(P(D>0\mid\text{data})=1-P(p_C>p_T\mid\text{data})=1-0.82=0.18\).

Clinical Biostats