Student's T distribution CDF

View versions (1)

Interface

#include <codecogs/statistics/distributions/continuous/t/cdf.h>

using namespace Statistics::Distributions::Continuous::T;

Computes the integral from minus infinity to t of the Student T distribution with integer k > 0 degrees of freedom:

\frac { \Gamma((k+1)/2) } { \sqrt{k\pi} \Gamma(k/2) }
    \int_{-\infty}^t  \left ( 1 + x^2/k \right )^{ -(k+1)/2 }  dx
(1)

The T distribution has PDF and CDF as shown below, denoted P(x) and D(x) respectively

\graph t=-2.5:2.5 k=1:25:5

For t < -2, this is the method of computation. For higher t, a direct method is derived from integration by parts. Since the function is symmetric about t=0, the area under the right tail of the density is found by calling the function with -t instead of t.

Example:

#include <stdio.h>
#include <codecogs/statistics/distributions/continuous/t/cdf.h>
using namespace Stats::Dists::Continuous::T;
int main()
{
  for( double t=-2.5; t<2.5; t+=0.5 )
    printf(  "CDF( %1.1f ) = %f \n", t, CDF(t, 20)  );
  return getchar();
}

Output:

CDF( -2.5 ) = 0.010617
CDF( -2.0 ) = 0.029633
CDF( -1.5 ) = 0.074618
CDF( -1.0 ) = 0.164628
CDF( -0.5 ) = 0.311266
CDF( 0.0 ) = 0.500000
CDF( 0.5 ) = 0.688734
CDF( 1.0 ) = 0.835372
CDF( 1.5 ) = 0.925382
CDF( 2.0 ) = 0.970367

Accuracy:

Tested at random 1 <= k <= 25.
 t domain     # trials      peak         rms
-100 -> -2      50000      5.9e-15     1.4e-15
-2 -> 100      500000      2.7e-15     4.9e-17

Parameters

t
the point at which to evaluate the distribution
k
the number of degrees of freedom of the T distribution

Returns

the integral from minus infinity to t of the distribution
GPL Licence — free for non commercial use. See Licence details.

Interactive Calculator

t
k
Result