Take the 2-minute tour ×
Cross Validated is a question and answer site for people interested in statistics, machine learning, data analysis, data mining, and data visualization. It's 100% free, no registration required.

I am trying to program out a couple of statistical formulas with python. I am not concerned with efficiency or the fact that there already are tools to calculate the values, but I am doing it to increase my understanding of statistics.

I tried setting up the Student T CDF, but I have no clue how to even start programming this.

On wikipedia it states the studentt cdf as follows: $$ \frac{1}{2}+x\Gamma\left(\frac{\nu+1}{2}\right)\cdot\frac{_2F_1\left(\frac{1}{2},\frac{\nu+1}{2},\frac{3}{2},-\frac{x^2}{\nu}\right)}{\sqrt{\pi\nu}\Gamma\left(\frac{\nu}{2}\right)} $$ It is noted that 2F1 is the Hypergeometric Function I have no idea what it does, how it works or what it looks like. I can't figure out how to program this function or even read it, since there must be something mysterious about the 2F1 notion that I don't understand. I tried reading up on the topic but I can only find very thick and old books that make me feel very stupid. The wikipedia link does not really help me, since I don't understand it. I don't have a good understanding of function theory and have never encountered gamma, beta and so on.

My desire might be too reductive and limited: I think of a function as something that calculates a value for a given input, so f(x) = 2x can pre easily programmed and will return 2 for f(1), 4 for f(2) and so on. So my question is:

How do I even read this formula?

Update I am sorry to admit it, but I am really dependent on your patience here. I have really big problems understanding the formula's "code" to begin with. I feel that until I do, I will have no use for your answers - so please help me on a lower level, as if you were explaining it to your grandma.

2F1 - what is the 2 for, what is the F for, what is the 1 for? Where does the (q)n come from? 2F1(a,b;c;z)? Why are a and b separated with a comma, not a semicolon? How is 2F1 different from 3F8, or is there even such a thing? This is all hieroglyphs to me. How do I read it? My question is more based on a reading issue than on a logical or a lack of understanding. I feel like translating chinese without a dictionary!

share|improve this question
1  
Why don't you just numerically integrate the PDF (which is a rational function, easily programmed)? For one degree of freedom ($\nu=1$) the CDF is an arctangent; for two or more DFs, even Simpson's Rule with a spacing of $0.1$ or so, starting around $-100$ (in place of $-\infty$), gives six-digit accuracy. Using the hypergeometric function formula does little or nothing to improve one's understanding of statistics, whereas integrating a PDF provides a direct connection to basic concepts. –  whuber Jan 2 '13 at 5:31
1  
This sounds like a different approach to my original problem and is in fact very helpful. I will look into it, thank you :) –  Johannes Hofmeister Jan 3 '13 at 16:07

2 Answers 2

up vote 2 down vote accepted

If I understand you correctly you basically would like to get what $$ _2F_1 $$ means. Basically, this is a so-called hypergeometric function. There are lots of them and they take the form: $$ _pF_q $$ Hence your example with p = 2 and q = 1 isn't the hypergeometric function, it's a hypergeometric one. This means that there may also be: $$ _3F_8 $$ which just means p = 3 and q = 8.

In general, hypergeometric functions are defined as

$$ _pF_q(a_1, ..., a_p; b_1, ..., b_q; z) = \sum_{k=0}^\infty\prod_{i=1}^p {\Gamma(k+a_i) \over \Gamma(a_i)}\prod_{j=1}^q {\Gamma(b_j) \over \Gamma(k + b_j)}{z^k \over k!} $$

so you get your formula for p = 2 and q = 1 by just inserting them into the appropriate places:

$$ _2F_1(a_1, a_2; b_1; z) = \sum_{k=0}^\infty\prod_{i=1}^2 {\Gamma(k+a_i) \over \Gamma(a_i)}\prod_{j=1}^1 {\Gamma(b_j) \over \Gamma(k + b_j)}{z^k \over k!} $$

Please note that you now have two times a, but only one time b (due to the choice of p and q). To visually group the a variables and separate them from the single b and the single z, you use semicolons instead of commas. It's just a visual clue.

The next step is to simplify the formula by removing unneccessary parts (such as the products). The result is the formula already mentioned by Julius in his answer.

The Gamma function, last but not least, is basically the same as the factorial function, but with its argument decreased by one. Hence

$$ \Gamma(n) = (n - 1)! $$

Does that answer your question, or at least helps with some understanding?

share|improve this answer
    
This is indeed exactly what I wanted, thank you very much. I am still missing a bridge here. In this document mhtlab.uwaterloo.ca/courses/me755/web_chap7.pdf I found that in 2F1, 2 − refers to number of parameters in numerator and 1 − refers to number of parameters in denominator, which emerges when you look at $$ \sum\limits_{n=0}^\infty \frac{(a)_n(b)_n}{(c)_n} \frac{x^n}{n!} $$ Why is it important to give a hint about the number of parameters in the denom/nom? –  Johannes Hofmeister Jan 4 '13 at 13:54

Getting the Student T CDF by numerical integration of the PDf works for me. But instead of using Simpson's Rule, I used a slice width of .0001 for t from -10 to +10. Also if you're looking for an algorithm for the CDF of the Normal curve, just make v a big number, like 1000. T now becomes z. I got 1.000000 for -6 to +6.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.