Expected value of squared difference of two uniform distributions

1.1k Views Asked by At

I am trying to calculate the expected value of the following variable Z:

$$ Z = (X - Y)^2 $$

Where $X, Y$ are uniform distributions over the interval $[0, 1]$. To do this, I'm using python to evaluate a definite integral that I have computed to be:

$$ E[Z] = \int_0^1 \int_0^1 (x - y)^2 * (p(x) * p(y)) dxdy$$

This gives me the value $ 0.018561461590966083 $. In order to double check I also used the following formula:

$$ E[(X- Y)^2] = E[x^2] - 2E[x]E[y] + E[y^2] $$ After computing this, I get the value $ 0.14946790438658583 $

I'm less familiar with integration, so I would believe the double integral I'm doing is incorrect, but I'm not sure how so. I've done some searching as how to do this integral but all the examples I can find ask for $ E[|X - Y|]$, and the part that has me stuck largely is the exponentiation. How can I properly compute the integral for this?

2

There are 2 best solutions below

2
On BEST ANSWER

We have that:

$$E(X-Y)^2=EX^2-2E(XY)+EY^2.$$

(You have the signal wrong on the expresssion in your post.)

Since $X$ and $Y$ are independent and indentically distributed, $E(XY)=EXEY=1/4$, and

$$EX^2=\int_0^1 x^2 dx=\frac{1}{3}=EY^2.$$

Therefore: $$E(X-Y)^2=\frac{1}{3}-2\frac{1}{4}+\frac{1}{3}=\frac{1}{6}\approx 0.167.$$

0
On

The double integral you have written down is correct, although it is important to point out that the density is equal to $1$ (so the $p(x),p(y)$ go away) since that is the definition of a uniform random variable on $[0,1]$. Thus, $$ \mathbb E(X-Y)^2=\int_0^1\int_0^1 (x-y)^2\ dx\ dy=\int_0^1\left[\frac{(x-y)^3}{3}\right]_0^1\ dy=\int_0^1 \frac{(1-y)^3+y^3}{3}\ dy=\left[\frac{(1-y)^4+y^4}{3\cdot 4}\right]_0^1=\frac{1}{6}. $$