# Calculating critical value for Student's t-distribution through numerical approximation, for arbitrary values of degrees of freedom

I'm trying to make a plot in LaTeX/tikz which is supposed to show the progressive critical value for a t distribution of arbitrary amount of degrees of freedom, in an animated plot, progressing over time.

For those with LaTeX that feel they need a little more insight on what I currently have, the code I have so far is included at the bottom of the question.

For this I wish to use a numerical approximation to actually calculate this critical value on the fly for each degree of freedom my plot is going through. I figured a good start would be to check out the student's t cumulative distribution function.

ct(x,nu)=nu<0||!isint(nu)?1/0:0.5+0.5*sgn(x)*(1-ibeta(0.5*nu,0.5,nu/(nu+x*x)));


The above approximation (in GNUplot) works using the signum of x and the incomplete beta function. Sgn(x) is not too much of an issue to code, but I can't find anything on numerical approximations on the incomplete beta function.

So my first question is: is there any easier way to calculate the critical value progressing over time? Circumventing the need for complex numerical calculations will surely inhibit computation times.

I've read something on wolfram and on wikipedia, both pointing towards the hypergeometrical function. Approximating this is substantially more tedious, from what I understand. Unless there's a good way to approximate this instead?

Alternatively: how can approximate the ibeta function? The complete beta function, gamma function, etc. are all no problem.

Note: (1) I wish to avoid integrals because tikz cannot parse these numerically in a timely fashion (I wish to also display the critical value.) (2) preferrably I want an expression comprising of a taylor series, some expression with for instance gamma, etc. So preferrably something that won't involve making a huge table of calculations which I would retro-actively insert into tikz after the computations; this would contradict the versatility that I'm originally making this plot in TeX for.

PS: I'm not sure about the tags. I've just put some general direction of the right tags but I'm not too sure about the tags here in Mathematics.SX. Bear with me. :-)

\documentclass[border=2pt]{standalone}
\usepackage{tikz,pgfplots}
\usetikzlibrary{calc}
\usepackage{animate}
\usepackage{fp}
\begin{document}
\begin{animateinline}[controls,loop,palindrome]{36}
\multiframe{216}{ik=1+4}{
\begin{tikzpicture}
\begin{axis}[%
xlabel =$q$,
ylabel =$d$,
xtick={-6,-4,...,6},ytick={.05,.1,...,.45},
height=7cm, width=7cm,
axis lines*=left,
xmin = -6, xmax = 6,
ymin = 0, ymax = .41,
every y tick label/.append style  =
{ /pgf/number format/.cd,
precision = 2,
fixed zerofill,
fixed
}]
\pgfmathsetmacro{\result}{((\ik/100+.6)^2+(ln(\ik/100+.6)^2+1.5))/5};
\addplot+[mark={},very thick, draw=cyan!80] gnuplot[raw gnuplot] {%
plot [-6:6][-6:6] gamma(.5*(\result+1))/(sqrt(\result*pi)*gamma(.5*\result))*((1+x^2/\result)^(-.5*(\result+1)))};
\addlegendentry{df = $\pgfmathprintnumber[fixed,fixed zerofill, precision=0]{\result}$};
\end{axis}
\end{tikzpicture}
}
\end{animateinline}
\end{document}