Solved

# How do I calculate a t-distribution value (instead of just looking it up on a chart)?

Posted on 2007-08-01
2,963 Views
I need to write some code that, given a probability (eg 80%), and a number of degrees of freedom (eg 9) returns the t-distribution, as in the chart at the bottom of this page: http://en.wikipedia.org/wiki/T-distribution. (eg, for p=80%, df=9, the code would therefore return 0.883.)

I don't follow how they're getting that chart based on the derivation there. I tried finding some existing code and came up with the following links, but since I'm not familiar with OOP, I'm finding it hard to understand the code. Any help would be greatly appreciated.

Links to the t-distribution PHP code I found:

http://www.multistat.de/source.php?file=t.php

(this one is an archive of a bunch of different probability classes, including one for t-distribution)

All I really need is a function that will return a t-value given a probability and number of degrees of freedom.
0
Question by:bitt3n

LVL 84

Accepted Solution

0

Author Comment

ok, so I assume I need formula 6 from that page, with f(t) being the probability, r being the number of degrees of freedom, and t being the t value. Is that right? How does this 'beta function' thing work? There is a link to this:

http://mathworld.wolfram.com/RegularizedBetaFunction.html

but I do not know what this means. How would I express this in a normal way?
0

LVL 84

Expert Comment

0

Author Comment

ok great, so

B(r/2, 1/2) = (r/2-1)!(-1/2)!/(r/2-1/2)!

and I can just plug that into formula (6)

hm.. solving for t, I get

t = (r/((f(t)*B(r/2, 1/2)*r^(1/2))^(2/(1+r))) - r)^(1/2)

using f(t) = 90% and r = 1, I get

t = ( -0.646322349 )^(1/2)

when from the table, I am expecting t=3.07768. What am I doing wrong?
0

Author Comment

I figured it might be helpful if I showed exactly what I was doing, so I wrote out and scanned my calculations

I started with formula (6), then used the definition for the beta function that you provided, and arrived at the wrong result. I went through it several times so I don't think it is a math error. What am I misunderstanding? Thanks.

Here is my work:

http://godshalk.com/tdist.jpg
0

LVL 4

Expert Comment

I think that 90% is the integral of f(t) from -infinity to t. Not f(t) itself.
0

Author Comment

ok.. so is the integrated version formula 9? If so, how do I interpret that gamma and F sub 1 stuff? thanks for your help
0

Author Comment

ok, it looks like gamma(x) means (x-1)! but what does the F-sub-1 mean in formula 9?
0

## Featured Post

We are taking giant steps in technological advances in the field of wireless telephony. At just 10 years since the advent of smartphones, it is crucial to examine the benefits and disadvantages that have been report to us.
This is a research brief on the potential colonization of humans on Mars.
This video discusses moving either the default database or any database to a new volume.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.