4

I have written a Perl script that performs many one-sample t-tests. I get thousands of t-statistics with their degrees of freedom (df). I need to upgrade the script to also return their p-values (there are too many to look them up manually in a table). Is there some kind of formula I can use for this with the t-statistic and d.f as input? I hope someone can help me with this, many thanks in advance!

A.A.

brian d foy
  • 129,424
  • 31
  • 207
  • 592
Abdel
  • 5,826
  • 12
  • 56
  • 77
  • 1). not enough info (2). show us your coding attempt... – Mitch Wheat May 05 '09 at 03:27
  • 1
    It's a pretty huge script. And it works fine. All I need is a formula or a piece of script that uses a t-statistic and it's d.f. (which I both already calculated and stored into memory) to calculate a p-value.. :-) But if there is something specific you would like to know about the script, I would gladly supply you with the information. – Abdel May 05 '09 at 03:39
  • There is no way to tell what you want/need without more information. – Brad Gilbert May 05 '09 at 04:02
  • 3
    @Mitch, Brad: What additional info is needed? As elbenshira says, Abdel needs a subroutine to integrate the area under the probability distribution function for the t distribution, from the value of the statistic to infinity. I think the problem is well-specified. – j_random_hacker May 05 '09 at 12:52

3 Answers3

7

Using Statistics::Distributions seems pretty straightforward:

print Statistics::Distributions::tprob($dof,$tstat);
titanofold
  • 2,852
  • 1
  • 15
  • 21
bubaker
  • 2,279
  • 1
  • 18
  • 13
  • Thanks a lot u guys! I really appreciate all your help. I think bubaker's answer is the one I needed! – Abdel May 05 '09 at 23:06
6

A search of MetaCPAN reveals the following:

https://metacpan.org/pod/Statistics::Distributions

Sinan Ünür
  • 116,958
  • 15
  • 196
  • 339
3

If you are doing a two-tailed test, then your p-value = 2*P(T > t), where t is your calculated test statistic. So essentially, you need a way to model the T-dist in order to integrate(T-dist from t to INFINITY). Here is a demo: http://www.stat.tamu.edu/~west/applets/tdemo.html

I'm not familiar with Perl and its libraries, but hopefully this gets you started. You can write a rudimentary integrator and check some values to make sure that it is accurate enough.

Elben Shira
  • 2,086
  • 3
  • 14
  • 13