My previous post introduced random inequalities and their application to Bayesian clinical trials. This post will discuss how to evaluate random inequalities analytically. The next post in the series will discuss numerical evaluation when analytical evaluation is not possible.

For independent random variables *X* and *Y*, how would you compute *P*(*X*>*Y*), the probability that a sample from *X* will be larger than a sample from *Y*? Let* f _{X}* be the probability density function (PDF) of

*X*and let

*F*be the cumulative distribution function (CDF) of

_{X}*X*. Define

*f*and

_{Y}*F*similarly. Then the probability

_{Y}*P*(

*X*>

*Y*) is the integral of

*f*(

_{X}*x*)

*f*(

_{Y}*y*) over the part of the

*x*–

*y*plane below the diagonal line

*x*=

*y*.

This result makes intuitive sense: *f*_{X(x)} is the density for *x* and *F _{Y}*(

*x*) is the probability that

*Y*is less than

*x*. Sometimes this integral can be evaluated analytically, though in general it must be evaluated numerically. The technical report Numerical computation of stochastic inequality probabilities explains how

*P*(

*X*>

*Y*) can be computed in closed form for several common distribution families as well as how to evaluate inequalities involving other distributions numerically.

**Exponential:** If *X* and *Y* are exponential random variables with mean μ* _{X}* and μ

*respectively, then*

_{Y}*P*(

*X*>

*Y*) = μ

*/(μ*

_{X}*+ μ*

_{X}*).*

_{Y}**Normal:** If *X* and *Y* are normal random variables with mean and standard deviation (μ* _{X}*, σ

*) and (μ*

_{X}*, σ*

_{Y}*) respectively, then*

_{Y}*P*(

*X*>

*Y*) = Φ((μ

*– μ*

_{X}*)/√(σ*

_{Y}

_{X}^{2}+ σ

_{Y}^{2})) where Φ is the CDF of a standard normal distribution.

**Gamma**: If *X* and *Y* are gamma random variables with shape and scale (α* _{X}*, β

*) and (α*

_{X}*, β*

_{Y}*) respectively, then*

_{Y}*P*(

*X*>

*Y*) =

*I*(β

_{x}*/(β*

_{X}*+ β*

_{X}*)) where*

_{Y}*I*is the incomplete beta function with parameters α

_{x}*and α*

_{Y}*, i.e. the CDF of a beta distribution with parameters α*

_{X}*and α*

_{Y}*.*

_{X}The inequality *P*(*X* > *Y*) where *X* and *Y* are **beta **random variables comes up very often in applications. This inequality cannot be computed in closed form in general, though there are closed-form solutions for special values of the beta parameters. If *X* ~ beta(*a*, *b*) and *Y* ~ beta(*c*, *d*), the probability *P*(*X* > *Y*) can be evaluated in closed form if

- one of the parameters
*a*,*b*,*c*, or*d*is an integer, *a*+*b*+*c*+*d*= 1, or*a*+*b*=*c*+*d*= 1.

These last two cases can be combined with a recurrence relation to compute other probabilities. See Exact calculation of beta inequalities for more details.

Sometimes you need to calculate *P*(*X* > max(*Y*, *Z*)) for three independent random variables. This comes up, for example, when computing adaptive randomization probabilities for a three-arm clinical trial. For a time-to-event trial as implemented here, the random variables have a gamma distribution. See Numerical evaluation of gamma inequalities for analytical as well as numerical results for computing *P*(*X* > max(*Y*, *Z*)) in that case.

The next post in this series will discuss how to evaluate random inequalities numerically when closed-form integration is not possible.

**Update**: See Part IV of this series for results with the Cauchy distribution.

## 8 thoughts on “Random inequalities II: analytical results”