# How can I calculate the probability that one random variable is bigger than a second one?

I have five random variables which are independent and each one of them has a continuous uniform distribution on the interval $$[0,2]:$$ $$X_i = \operatorname{Uniform}[0,2].$$

I want to calculate the probability $$\Pr(\min(X_1, X_2, X_3)\gt \max(X_4, X_5)).$$

I'm aware there is combinatorial solution, but I'm trying to solve this problem using coordinates with $$X$$ as the minimum and $$Y$$ as the maximum, but I don't know how to sketch the function and calculate the function space in order to know the probability.

To be brutally mindless about it, we may begin with the full five-dimensional integral and then proceed to evaluate it. Because this is carried out over a region in $$\mathbb{R}^5,$$ I will not attempt to sketch it :-).

As a simplification of the notation (and to reveal the ideas), let the joint density of $$(X_1,X_2,X_3)$$ be $$f_{123}$$ and the joint density of $$(X_4,X_5)$$ be $$f_{45}.$$ Then, with $$P = \Pr(\min(X_1,X_2,X_3) \gt \max(X_4,X_5)),$$

$$P = \iint f_{45}(x_4,x_5) \iiint_{\max(x_4,x_5)} f_{123}(x_1,x_2,x_3)\,\mathrm{d}x_1\mathrm{d}x_2\mathrm{d}x_3\ \mathrm{d}x_4\mathrm{d}x_5.$$

The first (double) integral extends over all $$\mathbb{R}^2$$ while the second (triple) integral extends only over those points $$(x_1,x_2,x_3)$$ in $$\mathbb{R}^3$$ where all three coordinates exceed both $$x_4$$ and $$x_5.$$

It is usually easiest to deal with a maximum in an integral's endpoint by breaking the integral into parts: almost surely either $$X_4$$ or $$X_5$$ will be the larger of those two and these two events (namely, $$\mathcal{E}_4:X_4=\max(X_4,X_5)$$ and $$\mathcal{E}_4:X_5=\max(X_4,X_5)$$) are mutually exclusive. Therefore we may compute the probabilities of these two events and add them.

Because $$X_4$$ and $$X_5$$ are iid, they are exchangeable, implying $$\mathcal{E}_4$$ and $$\mathcal{E}_5$$ have the same probability. Consequently, taking the case $$X_4\gt X_5$$ (event $$\mathcal{E}_4$$), we obtain

$$P = 2\int\int_{x_5} f_{45}(x_4,x_5) \iiint_{x_4} f_{123}(x_1,x_2,x_3)\,\mathrm{d}x_1\mathrm{d}x_2\mathrm{d}x_3\ \mathrm{d}x_4\mathrm{d}x_5.$$

Specializing now to iid uniform$$[0,1]$$ variables we may compute this integral using the most elementary techniques as

\begin{aligned} P &= 2\int_0^1\int_{x_5}^1\int_{x_4}^1\int_{x_4}^1\int_{x_4}^1\,\mathrm{d}x_1\mathrm{d}x_2\mathrm{d}x_3\mathrm{d}x_4\mathrm{d}x_5 \\ &= 2\int_0^1\int_{x_5}^1 \left(\int_{x_4}^1\mathrm{d}x_1\right)\left(\int_{x_4}^1\mathrm{d}x_2\right)\left(\int_{x_4}^1\mathrm{d}x_3\right)\,\mathrm{d}x_4\mathrm{d}x_5 \\ &= 2\int_0^1\int_{x_5}^1(1-x_4)^3\mathrm{d}x_4\mathrm{d}x_5 \\ &= 2\int_0^1 \frac{1}{4}(1-x_5)^4\,\mathrm{d}x_5 \\ &= 2\left(\frac{1}{4}\right)\left(\frac{1}{5}\right) = \frac{1}{10}. \end{aligned}

This gives the answer for any continuous iid variables with common density $$f$$ because the Probability Integral Transform

$$u(x) = \int^x f(t)\,\mathrm{d}t,$$

converts the variables $$(X_1,\ldots, X_5)$$ into variables $$U_i = u(X_i)$$ that are iid with a Uniform$$[0,1]$$ distribution without changing the order statistics, thereby leading to the calculation of $$P$$ that was just performed.

For all input values $$0 \leq t \leq 2$$ we have,

\begin{align*} \mathbb P (\min(X_1,X_2,X_3) > t ) &= \mathbb P(X_1>t)^3 \\[12pt] &= \Big (1 - \frac{t}{2} \Big )^3 \\[12pt] \mathbb P (\max(X_4,X_5) \leq t ) &= \mathbb P(X_4\leq t)^2 \\[12pt] &= \frac{t^2}{4}, \\[6pt] \end{align*}

which also gives the corresponding density,

\begin{align*} \quad f_{\max(X_4,X_5)}(t) &= \frac{t}{2}. \\[6pt] \end{align*}

Thus, using the substitution $$r = t/2$$, we have,

\begin{align*} \mathbb P (\min(X_1,X_2,X_3) > \max(X_4,X_5 )) &= \int \limits_0^2 \mathbb P (\min(X_1,X_2,X_3) > t ) \frac{t}{2} \ dt \\[6pt] &=\int \limits_0^2 \Big (1 - \frac{t}{2} \Big )^3 \frac{t}{2} \ dt \\[6pt] &= 2 \int \limits_0^1 (1-r)^3 r \ dr \\[6pt] &= 2 \int \limits_0^1 (r - 3r^2 + 3r^3 - r^4) \ dr \\[6pt] &= 2 \Bigg[ \frac{r^2}{2} - r^3 + \frac{3r^4}{4} - \frac{r^5}{5} \Bigg ]_{r=0}^{r=1} \\[12pt] &= 2 \Bigg[ \frac{1}{2} - 1 + \frac{3}{4} - \frac{1}{5} \Bigg ] \\[12pt] &= 0.1 \\[6pt] \end{align*}

• thank you but as i said i know the combinatorical solution. I'm trying to solve this using coordinates system
– Ben
Sep 16 at 13:45
• @Ben Ok sorry, I edited my answer Sep 16 at 14:16
• @periwinkle: Nice answer (+1). I have taken the liberty of editing to make your answer a bit prettier (lining up some equations, moving density into equations, adding more paragraph space between equations, etc.) and I have added a couple more steps in the final integral to assist readers. Please feel free to revert or edit if you do not like what I've changed.
– Ben
Oct 1 at 22:28

Solution using automated computer algebra systems:
Let $$(X_1, ..., X_5)$$ have joint pdf $$f(x_1,..., x_5)$$: Then: ... where I am using the Prob function from the mathStatica package for Mathematica.

Always nice to check work and existence of exact solutions.

• Because the question refers to the combinatorial argument (which is simple and clear, yielding the answer $1/\binom{5}{2}$), a good confirmation of the answer is already in place. Indeed, had your software obtained any other answer I would blame it on a bug rather than trusting the software!
– whuber
Sep 16 at 18:39
• Agreed - the attraction for me is how the parsing of the CAS solution can so closely and naturally match the question. Sep 17 at 17:07
• Yes, that is a really nice feature of the software.
– whuber
Sep 17 at 17:25

How can I calculate the probability that one random variable is bigger than a second one?

• You could integrate over the joint distribution in the area where the condition $$X>Y$$ is true.
• You could derive the distribution for the variable $$X-Y$$ and use it to compute $$P(X-Y>0)$$.

Below is an example of the first option

You variables $$X = min(X_1,X_2,X_3)$$ and $$Y = max(X_4,X_5)$$ are independent and follow the beta distribution with pdf's (without loss of generality I am scaling from [0,2] to [0,1]) $$\begin{array}{rcl} f_X(x) &=& 3(1-x)^2 \\ f_Y(y) &=& 2y \end{array}$$

I've plotted a randomly generated sample of this in the image below. What you want to know is the probability that $$X>Y$$ and this corresponds to a point being on the bottom of the diagonal line $$X=Y$$.

You can find this probability by integrating the probability density of the points below that diagonal line.

$$\begin{array}{rcl} P(X > Y) &=& \int_0^1 \int_0^x 6 (1-x)^2 y \, dy dx \\&=& \int_0^1 6(1-x)^2 \left[ \int_0^x y \, dy \right] \, dx \\ &=& \int_0^1 3 (1-x)^2 x^2 \, dx \\ &=& 3 \int_0^1 x^2 - 2x^3 + x^4 \, dx \\ &=& 3 (\frac{1}{3} - \frac{2}{4} + \frac{1}{5}) \\ & =& \frac{1}{10} \end{array}$$ I believe that its is slightly more intuitive and easy than doing the quintuple integral. However, when your question would have been like $$X = min(X_1,X_2,X_3)$$ and $$Y = max(X_3,X_4)$$ then the variables are not independent and it may not be so easy to write down the joint pdf.