The density of Student's t distribution is given by $$f_n(x) = \frac{1}{\sqrt{n\pi}}\frac{\Gamma\left(\frac{n+1}{2}\right)}{\Gamma\left(\frac n2\right)}\left(1+\frac{x^2}n\right)^{-\frac{n+1}{2}},$$ where $n$ is a positive real (the degrees of freedom) and $\Gamma$ denotes the usual Gamma function. I want to evaluate this density numerically. I already have an implementation for $\Gamma$. For numerical evaluations, the following form $$f_n(x) = \sqrt{\frac n2} \,\,\,\left(\frac{n+1}2\right)^{-1}\,\frac{\Gamma\left(\frac{n+3}2\right)}{\Gamma\left(\frac{n+2}{2}\right)}\left(1+\frac{x^2}n\right)^{-\frac n2}\left(2\pi\left(1+\frac {x^2}n\right)\right)^{-\frac 12} $$ is recommended. Both forms are equivalent (it's easy to show using the property $\Gamma(z + 1) = z\Gamma(z)$ of the $\Gamma$ function), but the latter form is, apparently, numerically more stable. How? I don't see why it's numerically more stable. The fact that more operations are involved make it hard for me to believe... If it is in fact true, is this the best (with regard to precision) form for numerical evaluation?
Asked
Active
Viewed 52 times
1
-
1I am by no means an expert on these matters, but perhaps the reason it is better is because it avoids the inverse square root – K.defaoite May 06 '22 at 09:25
1 Answers
1
I do not see either how it could be more stable.
In my former research group, $40^+$ years ago, we faced this problem and a PhD student worked to find the cheapest way of computing it.
His result was $$f_n(x) = \frac{\Gamma\left(\frac{n+1}{2}\right)}{\Gamma\left(\frac n2\right)}\frac 1 {\sqrt{n\pi \left(1+\frac{x^2}{n}\right)^{n+1} } }$$
Just to give you an idea of the power of computers at that time, just have a look here (I started with the $\text{IBM-704}$ which was (supposed to be) able to perform $12,000$ floating-point additions per second)
Edit
Going back through his thesis, I found interesting approximations for large values of $n$ (this was our case in statistical thermodynamics). If this is of any interest for you, let me know.
Claude Leibovici
- 260,315
-
I think it could be interesting to see a large sample approximation. I (and I think many other people) usually use the Gaussian density as approximation of $f_n$ for large $n$ – Syd Amerikaner May 25 '22 at 10:15