3

Consider two independent and identically distributed random variables $X$ and $Y$ such that

$$X, Y \sim \Gamma\left(\frac{1}{2}, 2^{-n+1}\right), $$ where $n$ is a constant.

I am trying to calculate \begin{equation} \text{E}[|X - Y|], ~~\text{and}~~ \text{Var}[|X - Y|]. \end{equation}

Is there any simple way of doing this without having to compute the double integrals? Or, is there at least any way to simplify the double integrals? The double integrals are too complicated to solve on Mathematica.

BlackHat18
  • 237
  • 1
  • 8
  • You can ignore the scale factor and just introduce it in the end. With this simplification, Wolfram Alpha gives the answer directly by [inverting the characteristic function](https://www.wolframalpha.com/input/?i=Fourier+transform+sqrt%282%2Fpi%29+%281+%2B+t%5E2%29%5E%28-1%2F2%29). The distribution is proportional to the Bessel $K_0$ function. Of course, if all you need are these two moments, you don't even need the Fourier transform: just expand the series. – whuber Dec 01 '20 at 20:22
  • Might you elaborate a bit more on what the final values of those moments are and how the Fourier transform or the inversion of the characteristic function is related to finding out these moments, perhaps in an answer? – BlackHat18 Dec 02 '20 at 04:45
  • Also, might you elaborate on how you got that specific characteristic function for this problem? A random variable $X$ distributed as $\Gamma(\frac{1}{2}, 1)$ has the characteristic function $\frac{1}{\sqrt{1 - it}}$. I could not figure out how to get the factor of $2/pi$ or tackle the modulus of the difference. – BlackHat18 Dec 02 '20 at 13:36
  • Finally, upon expanding the series, the first two terms are $\sqrt{2/\pi} - t^{2}/\sqrt{2 \pi}$. Does this mean the mean is $0$? But then, how can the variance be negative? – BlackHat18 Dec 02 '20 at 13:43
  • I have written about characteristic functions before at https://stats.stackexchange.com/a/43075/919. Relevant information about the Gamma function can be found in my answer at https://stats.stackexchange.com/a/72486/919. A simple way to obtain the normalizing constant is to [integrate $K_0.$](https://www.wolframalpha.com/input/?i=integrate+besselK%280%2C+t%29+for+t+%3D+0+to+t+%3D+infinity). – whuber Dec 02 '20 at 14:22
  • Thanks! It's a lot clear now. What's not clear is how to get that specific characteristic function. You mention in this (stats.stackexchange.com/a/43075/919) answer how to get the characteristic function for a sum $X + Y$ of independent random variables $X$ and $Y$, but what if there is a modulus and we ought to calculate $|X - Y|$? Also, how ought we do get the normalizing factor in the characteristic function itself? – BlackHat18 Dec 02 '20 at 14:41
  • And, how does the series expansion of the characteristic function correspond to the mean and variance? If the $t^{2}$ term is proportional to the variance, why is it negative for our case? – BlackHat18 Dec 02 '20 at 14:42
  • Finally, just for a sanity check and to make sure I understand at least some of the steps, the mean is 0 for this case, right? – BlackHat18 Dec 02 '20 at 14:49
  • The mean cannot possibly be zero, because $|X-Y|$ is almost surely positive. However, because $X$ and $Y$ are iid and have finite absolute first moments, the mean of $X-Y$ is indeed zero. BTW, the $t^2$ term in the characteristic function is $-1/2$ times the variance, so it had better be *negative.* – whuber Dec 02 '20 at 14:50
  • But the series expansion of the characteristic function has no $t$ term. How do we compute the mean and the variance from the series expansion of the characteristic function? – BlackHat18 Dec 02 '20 at 14:51
  • The variance you can derive from the expectation of $(X-Y)^2$ because $|X-Y|^2=(X-Y)^2.$ To obtain the mean, [perform the integration directly](https://www.wolframalpha.com/input/?i=%28integrate+t+besselK%280%2C+t%29+for+t+%3D+0+to+t+%3D+infinity%29+%2F+%28integrate+besselK%280%2C+t%29+for+t+%3D+0+to+t+%3D+infinity%29) – whuber Dec 02 '20 at 14:54

1 Answers1

5

Here's a sketch of a solution.

First, ignore the scale factor of $\sigma = 2^{-n+1}$ because it can be restored at the end. Because the characteristic function of a Gamma$(1/2)$ variable like $X$ or $Y$ is

$$\psi_X(t) = \psi_Y(t) = (1 - it)^{-1/2},$$

the characteristic function of $X-Y$ (a version of the Fourier Transform of its density) is

$$\psi_{X-Y}(t) = \psi_X(t)\psi_Y(-t) = (1+t^2)^{-1/2}.$$

The density function of $X - Y$ therefore is recovered by applying the inverse Fourier transform, giving

$$f_{X-Y}(x) = \widehat{\psi_{X-Y}}(t) = \frac{1}{\pi}K_0(|x|),$$

a multiple of the Bessel $K_0$ function.

Because all events of the form $|X-Y|\le t$ for $t\ge 0$ correspond to events $-t \le X-Y \le t$ and the symmetry (and continuity) of $f_{X-Y}$ show the events $-t \le X-Y\le 0$ and $0 \le X-Y \le t$ must have equal probabilities, the density of $|X-Y|$ is twice the density of $X-Y$ for all positive values (and otherwise is zero, of course). Thus

$$f_{|X-Y|}(x) = \frac{2}{\pi}K_0(|x|).$$

The mean therefore is

$$E\left[\,|X-Y|\,\right] = \int_0^\infty x f_{|X-Y|}(x)\,\mathrm{d}x = \int_0^\infty x \frac{2}{\pi}K_0(|x|)\,\mathrm{d}x = \frac{2}{\pi}.$$

The raw second moment similarly is

$$E\left[\,|X-Y|^2\,\right] = \int_0^\infty x^2 \frac{2}{\pi}K_0(|x|)\,\mathrm{d}x = 1.$$

(We could have obtained this earlier from $\psi_{X-Y}$ because the second moment of $X-Y$ is that of $|X-Y|$ and

$$\psi_{X-Y}(t) = (1+t^2)^{-1/2} = 1 + \binom{-1/2}{1}(t^2)^1 + \cdots = 1 - \frac{t^2}{2} + \cdots$$

and the second moment is, as always, $2!$ times the coefficient of $(it)^2.$)

Therefore $$\operatorname{Var}(|X-Y|) = 1 - \left(\frac{2}{\pi}\right)^2 \approx 0.5947153.$$

Finally, when $X$ and $Y$ are multiplied by the same constant $\sigma,$ $|X-Y|$ is also multiplied by $\sigma,$ whence its mean is $(2/\pi)\sigma$ and its variance is $\left(1-(2/\pi)^2\right)\sigma^2.$

Results of a simulation of $|X-Y|$ compared to the theoretical density (shown in red):

Figure

This R code conducted the simulation and produced the graphic.

n <- 1e6
z <- abs(rgamma(n, 1/2) - rgamma(n, 1/2))

hist(z, xlim=c(0,5), breaks=200, freq=FALSE, col="Gray", main="Realizations of |X-Y|",
     xlab=expression(abs(X-Y)))
curve(besselK(x, 0) * 2/pi, add=TRUE, col="Red", lwd=2, n=1501)

(cbind(Mean=c(Simulated=mean(z), Theoretical=2/pi),
       Variance=c(var(z), 1 - (2/pi)^2)))
whuber
  • 281,159
  • 54
  • 637
  • 1,101