# Comparing 2 continuous uniform distributions

#### economist1

##### New Member
I have what appears to be a very simple problem, but am having difficulties working out a solution. Any help would be much appreciated.

The problem can be specified as follows

Imagine there are two random variable, X and Y, both of which follow a continuous uniform distribution. Random variable X is defined fully in the interval [a,b] and random variable y is defined fully in the interval [c,d] where the parameters a, b, c and d are all non-negative.

A value of X is chosen at random and a value of Y is chosen at random. What is the probability that X>Y?

I am looking for a general expression to answer the above question.

I was thinking that perhaps the answer might involve having to integrate a joint probability distribution, but I'm not sure.

If it helps, one could think about a numerical example of the above where X lies in the interval [0,25] and Y lies in the interval [0,10]. If X and Y are selected at random, what is the probability that X>Y? If it might be possible to work through this example numerically, I was thinking it might help me understand how it would work in the general case where one does not know the numerical value of parameters a, b, c and d.

#### BGM

##### TS Contributor
The usual way is to integrate the joint pdf on the set $$\{(x, y): x > y\}$$.

Assuming $$X, Y$$ are independent, then the support of their joint pdf is just a rectangle, and the probability is the area intersect with the above set.

To express it as an integral: $$\Pr\{X > Y\} = \int_a^b \Pr\{Y < x\}\frac {1} {b - a}dx$$

Note that $$\Pr\{Y < x\} = \left\{\begin{matrix} 0 & \text{if} & x \leq c \\[1em] \displaystyle \frac {x - c} {d - c} & \text{if} & c < x < d \\[1em] 1 & \text{if} & x \geq d \end{matrix} \right.$$

So obviously the trivial cases are:

When $$d \leq a$$, $$\Pr\{Y < X\} = 1$$
When $$c \geq b$$, $$\Pr\{Y < X\} = 0$$

Now when $$a < d < b$$, we have

$$\Pr\{Y < X\} = \frac {1} {(b - a)(d - c)}\int_{\max\{a, c\}}^d (x - c)dx + \frac {1} {b - a} \int_d^b dx$$

$$= \frac {1} {(b - a)(d - c)}\left(\frac {d^2} {2} - cd - \frac {\max\{a, c\}^2} {2} + c\max\{a, c\} \right) + \frac {b - d} {b - a}$$

WHen $$c < b < d$$, we only have the first part

$$\frac {1} {(b - a)(d - c)}\left(\frac {d^2} {2} - cd - \frac {\max\{a, c\}^2} {2} + c\max\{a, c\} \right)$$

So for the non-trivial case, you may write more compactly as

$$\frac {1} {(b - a)(d - c)}\left(\frac {d^2} {2} - cd - \frac {\max\{a, c\}^2} {2} + c\max\{a, c\} \right) + \frac {\max\{b - d, 0\}} {b - a}$$

and that should sum up the cases.