Inverse of the complemented F distribution CDF

You're viewing an older version of this page (#222). View the current version.

View versions (1)

Interface

#include <codecogs/statistics/distributions/continuous/f/cdf_inv.h>

using namespace Statistics::Distributions::Continuous::F;

Finds the F argument x such that the integral from x to infinity of the F distribution PDF (in other words the upper-tail CDF) is equal to the given cumulative probability p.

This is accomplished using:

z = I \left ( p; \frac{df2}{2}, \frac{df1}{2} \right )
(1)
x = \frac{n(1-z)}{mz}
(2)

where I(p;a,b) is the inverse beta integral function beta_reg_inv

Example:

#include <stdio.h>
#include <codecogs/statistics/distributions/continuous/f/cdf_inv.h>
#include <codecogs/statistics/distributions/continuous/f/cdf.h>
using namespace Stats::Dists::Continuous::F;
int main()
{
  printf( "    x              CDF              INV \n" );
  for( double x=1; x<10; x+=0.5 )
  {
    double y = CDF( 3, 5, x, true );
    double z = CDF_inv( 3, 5, y );
    printf( "%f \t %f \t %f \n", x, y, z );
  }
  return getchar();
}

Output:

x              CDF              INV
1.000000         0.464855        1.000000
1.500000         0.322165        1.500000
2.000000         0.232624        2.000000
2.500000         0.173928        2.500000
3.000000         0.133855        3.000000
3.500000         0.105520        3.500000
4.000000         0.084877        4.000000
4.500000         0.069451        4.500000
5.000000         0.057669        5.000000
5.500000         0.048498        5.500000
6.000000         0.041241        6.000000
6.500000         0.035415        6.500000
7.000000         0.030677        7.000000
7.500000         0.026780        7.500000
8.000000         0.023541        8.000000
8.500000         0.020825        8.500000
9.000000         0.018527        9.000000
9.500000         0.016569        9.500000

Accuracy:

Tested at random points (a,b,p).
  a,b domain   # trials     peak         rms
For p between .001 and 1:
  1,100         100000     8.3e-15     4.7e-16
  1,10000       100000     2.1e-11     1.4e-13
For p between 10^-6 and 10^-3:
  1,100         50000      1.3e-12     8.4e-15
  1,10000       50000      3.0e-12     4.8e-14

Parameters

m
the 1st degree of freedom, must be strictly positive
n
the 2nd degree of freedom, must be strictly positive
y
the probability to evaluate the function at, must be in range 0..1

the following holds for the inverse of the lower-tail CDF:

z = I \left ( p; \frac{m}{2}, \frac{n}{2} \right )
(3)
x = \frac{nz}{m(1-z)}
(4)

if m<1, n<1, y<0 or y>1 this function writes to the error stream and returns -1

GPL Licence — free for non commercial use. See Licence details.

Interactive Calculator

m
n
y
Result