# Distribution of difference of two random variables with chi-squared distribution

Supose that we have two random variables $$X \sim \chi_k^2$$ and $$Y \sim \chi_k^2$$, with the same degrees of freedom.

A chi-squared distribution cannot have zero degrees of freedom, so what would be the distribution of $$X - Y$$ ?

• From Maths stack exchange Dec 9 '18 at 14:49
• Even assuming $X$ and $Y$ to be independent, there is no result that states that difference of two independent chi-squared variables is also a chi-square variable. Dec 9 '18 at 14:54
• The technique at stats.stackexchange.com/questions/72479/… will work because chi-squared variables are scaled gamma variables.
– whuber
Dec 9 '18 at 18:41

This is not a chi-squared density, $$X-Y$$ will have support on $$(-\infty, +\infty)$$.

If the two variables are independent, it has mean 0 and variance $$4k$$.

If $$k$$ is large, its density is well approximated a normal variable with 0 mean and $$4k$$ variance. In the general case, its MGF has a closed form: $$E(\exp(t(X-Y))) = (1-4t^2)^{-k/2}$$

If the 2 variables have dependence, the nature of that dependence needs to be explicited.

• This MGF can be inverted (by sight if you have ever considered the MGF of the Student t distribution) to give the density function in terms of the Bessel $K$ function, $$f_{X-Y}(x)=\frac{2^{\frac{1}{2}-k } \left| x\right| ^{\frac{k -1}{2}} K_{\frac{k -1}{2}}\left(\frac{\left| x\right| }{2}\right)}{\Gamma \left(\frac{k }{2}\right)}.$$
– whuber
Dec 9 '18 at 18:50
• @whuber When $k=2m$ is even, a partial fraction expansion of $(1-4t^2)^{-m}$ into a sum of fractions with denominators $(1-2t)^{-j}, j = 1,2, \ldots, m$ and $(1+2t)^{-j}, j = 1, 2, \ldots, m$ is possible and so we can deduce that the pdf of $X-Y$ is proportional to a mixture of $\chi_j^2$ pdfs, $j = 1, 2, \ldots, m$ as stated in my answer here. No Bessel K functions need be invoked here. Dec 9 '18 at 21:04
• @Dilip Thank you for clarifying that point. I presented the Bessel function solution because it is (a) immediate and (b) completely general -- but it's nice to have the simplification in special cases.
– whuber
Dec 9 '18 at 21:34

Since $$X$$ and $$Y$$ can also be considered to be Gamma random variables with (order, rate) parameters $$\left(\frac k2, \frac 12\right)$$, then, as Sebapi points out, $$X-Y$$ has support $$(-\infty,\infty)$$. Furthermore, if $$X$$ and $$Y$$ are assumed to be independent, then the pdf of $$X-Y$$ is also symmetric about $$0$$ and has mean zero.

For independent $$X$$ and $$Y$$, the pdf of their difference $$X-Y$$ is the cross-correlation of the pdfs of $$X$$ and $$Y$$ (not the convolution of the pdfs as happens for the sum $$X+Y$$) and in this case, since the pdfs are identical, the cross-correlation is actually an autocorrelation and so the pdf of $$X-Y$$ is symmetric about $$0$$ as claimed. Furthermore, for the case here of $$X$$ and $$Y$$ being Gamma random variables, an explicit form can be deduced from this answer of mine here on stats.SE.

When $$k$$ is an odd number, then, as noted in my answer cited above, it is possible to write the pdf $$f_{X-Y}(z)$$ of $$X-Y$$ in terms of polynomial, exponential, and Bessel functions of $$z$$. However when $$k$$ is an even number, then for $$z \geq 0$$, $$f_{X-Y}(z)$$ is proportional to a mixture of Gamma pdfs with (order, rate) parameters $$\Gamma\left(1, \frac 12\right), \Gamma\left(2, \frac 12\right), \ldots, \Gamma\left(\frac k2, \frac 12\right)$$ pdfs (equivalently, $$\chi_2^2, \chi_4^2, \ldots, \chi_{k}^2$$ pdfs) and of course, since $$f_{X-Y}(z)$$ is an even function of $$z$$, the same curve "flipped over" is the pdf curve on the negative axis.

Those worried that Gamma pdfs have value $$0$$ at the origin whereas autocorrelation functions have a maximum at the origin and so something is awry in the above claims should relax. A $$\chi_2^2$$ pdf is an exponential pdf which has nonzero value (or a limiting value that is nonzero at the origin for those whose exponential random variables take on values only on the positive real line) and so that mixture pdf is indeed nonzero at the origin, and because of the weights in the mixture, indeed a maximum at the origin.