5
$\begingroup$

I am trying to implement an algorithm for calculating $p$-values of $F$-tests and I need this method to be highly precise. It is easy to implement this with $z$- or $t$- tables, however I don't know how to do this with $F$-values. I have seen some online calculators that do this job, what method do they use? Interpolation of couple of $F$-tables would surely be unprecise.

Any help would be appreciated. Thanks in advance

$\endgroup$
3
  • 2
    $\begingroup$ What is your development environment? For many of them, code to compute the inverse CDF of F distributions is already available. $\endgroup$
    – whuber
    Dec 20, 2011 at 14:21
  • $\begingroup$ Scheme. I don't think there are readily available statistics codes for Scheme, but it might help if you could elaborate on the basic design if you can $\endgroup$
    – M. May
    Dec 20, 2011 at 14:40
  • 2
    $\begingroup$ There is Guile-numerics which provides bindings to GSL which includes functions for the $F$ distribution. $\endgroup$
    – cardinal
    Dec 20, 2011 at 17:22

3 Answers 3

5
$\begingroup$

More details than you probably want on the mathematics of the F distribution can be found here (and other places). The formula for the pdf is there and the p-value is just the integral from your F-statistic to infinity of that function. It also has the Cumulative distribution function for the F distribution and the p-value will just be one minus the cumulative up to your F statistic. The cumulative function is expressed in terms of the incomplete beta distribution (with link if you want the details). There may be implementations of the incomplete beta distribution already in Scheme that you could use (this would be fairly simple then), if not there are implementations in other languages (here is one location) that you could probably link to your Scheme program (I don't know Scheme enough to know about linking, but you should be able to find a way).

$\endgroup$
1
  • 2
    $\begingroup$ Possibly related reference: Barabesi L & Greco L. 2002. A note on the exact computation of the Student t, Snedecor F, and sample correlation coefficient distribution functions. Journal of the Royal Statistical Society, 51D, 105-110. For pdf-implementations in C / FORTRAN, also see DCDFLIB. $\endgroup$
    – caracal
    Dec 20, 2011 at 16:50
4
$\begingroup$

About Scheme libraries specifically, here are two GSL bindings that you might be interested in:

The second project is readily available on PLaneT if you use Racket.

Here is an example that returns the $p$-value for the quantile $x=4.2$ of an ${\cal F}(2, 10)$ distribution ($p=0.047$):

(require (planet williams/science/random-distributions/f-distribution))
(- 1 (f-distribution-cdf 4.2 2 10))

with the corresponding CDF

(require (planet williams/science/random-distributions/f-distribution-graphics))
(f-distribution-plot 2 10)

enter image description here

There are also some statistical functions available for Chicken Scheme (release branch 4). After having installed the required dependencies, e.g.

$ sudo chicken-install statistics

you will be able to do something like

(use statistics)
(f-significance 4.2 2 10 #:one-tailed? #t)

in the interactive Chicken shell (csi).

As pointed out by @cardinal, the Guile-numeric bindings look promising as it seems to provide a more integrated framework (with libfft and lapack support) for statistical computing. I have no time to test it presently but it is worth trying to.

$\endgroup$
5
  • $\begingroup$ Guile is another Scheme variant, so feel free to incorporate my comment to the OP into your answer, if applicable. $\endgroup$
    – cardinal
    Dec 22, 2011 at 15:40
  • $\begingroup$ @cardinal I've noticed your comment. I'd have to install guile on os x first. $\endgroup$
    – chl
    Dec 22, 2011 at 15:45
  • $\begingroup$ I have not tried this myself, but I figured with your veritably encyclopaedic knowledge of modern statistical software, that you might already be familiar with it and, maybe, even enough to have an opinion on it. (+1, by the way). $\endgroup$
    – cardinal
    Dec 22, 2011 at 18:03
  • 1
    $\begingroup$ @cardinal I have to give up for the moment because of external dependencies that I have no time to revolve. I added a pointer to your excellent comment. A lisp/scheme alternative to R has created some buzz some time ago (but see Ross Ihaka's paper for the JSM2010 conference), as you may know; hence my interest for it. But my interest is probably beyond my skills :) I wish I have as precious comments as yours... $\endgroup$
    – chl
    Dec 22, 2011 at 22:07
  • $\begingroup$ Wow. I did not mean to suggest that you should go through such effort to see if the Guile stuff would work! Thanks also for the links in your comment! Good stuff. $\endgroup$
    – cardinal
    Dec 22, 2011 at 22:50
2
$\begingroup$

Calculating the p-value for an F-Test is a quite straightforward job in every statistical programme. Consider for example r (r-project). Here's an example in R:

pf(F, df1=dfa, df2=dfb)

where F is the value from the statistic and dfa and dfb are the degrees of freedom.

Hope this helps you!

$\endgroup$
2
  • $\begingroup$ Thanks Seb, appreciated the input! However, my original code is written in Scheme, not really the best environment for developing statistics algoritms. Now I want to try using p-value for a task, but I need to write the code for it from the start. Could you elaborate the basic design of those algorithms maybe? $\endgroup$
    – M. May
    Dec 20, 2011 at 14:43
  • 1
    $\begingroup$ sorry, this is beyond my knowledge. couldn't you solve it analytically? probably this would be better placed at: http://programmers.stackexchange.com/ $\endgroup$
    – Seb
    Dec 20, 2011 at 15:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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