This project has moved and is read-only. For the latest updates, please go here.

Value for a t-distribution using the StudentDistribution class

Feb 18, 2013 at 12:30 PM
I'm trying to replicate the following R code using Meta Numerics:
t.val  = qt(0.9, 2)
Using the StudentDistribution class, I'm doing this...
var dist = new StudentDistribution(2);
... and then I want to get the value for a A-value of 0.9 (from here this should be 2.920). I'm not a stats guy, so I'm totally lost... HELP!
Feb 18, 2013 at 9:14 PM
The code you want is:
double A = dist.InverseLeftProbability(0.95);
which assigns the value 2.91998... to A.

Here's what's going on: R's qt function maps a probability value to a t-value. The probability value it expects as input is a central probability, the area under the probability distribution from -t to +t. You give it that central probability, which I'll call C, and it will give you back t. Meta.Numerics InverseLeftProbability metods expect a left probability, the area under the probability distribution from -Infinity to t. You give it that left probability, which I'll call L, and it will give you back t. If you sketch this on a piece of paper, you'll see that given a central area C, the left and right tails must each have area (1-C)/2, so the left area must be L=(1+C)/2. Plug C=0.90 into that equation and you will get L=0.95, which is where the 0.95 above came from.

If you want a complete re-implementation of R's qt function in Meta.Numerics, here it is:
        public static double qt (double C, double n) {
            StudentDistribution s = new StudentDistribution(n);
            double L = (1.0 + C) / 2.0;
            return (s.InverseLeftProbability(L));
Feb 19, 2013 at 7:41 AM
Many thanks ichbin, exactly what I needed!