home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / math / cephes / cprob / fdtr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-11-17  |  3.4 KB  |  206 lines

  1. /*                            fdtr.c
  2.  *
  3.  *    F distribution
  4.  *
  5.  *
  6.  *
  7.  * SYNOPSIS:
  8.  *
  9.  * int df1, df2;
  10.  * double x, y, fdtr();
  11.  *
  12.  * y = fdtr( df1, df2, x );
  13.  *
  14.  *
  15.  *
  16.  * DESCRIPTION:
  17.  *
  18.  * Returns the area from zero to x under the F density
  19.  * function (also known as Snedcor's density or the
  20.  * variance ratio density).  This is the density
  21.  * of x = (u1/df1)/(u2/df2), where u1 and u2 are random
  22.  * variables having Chi square distributions with df1
  23.  * and df2 degrees of freedom, respectively.
  24.  *
  25.  * The incomplete beta integral is used, according to the
  26.  * formula
  27.  *
  28.  *    P(x) = incbet( df1/2, df2/2, (df1*x/(df2 + df1*x) ).
  29.  *
  30.  *
  31.  * The arguments a and b are greater than zero, and x
  32.  * x is nonnegative.
  33.  * ACCURACY:
  34.  *
  35.  * See incbet.c.
  36.  *
  37.  * ERROR MESSAGES:
  38.  *
  39.  *   message         condition      value returned
  40.  * fdtr domain     a<0, b<0, x<0         0.0
  41.  *
  42.  */
  43. /*                            fdtrc()
  44.  *
  45.  *    Complemented F distribution
  46.  *
  47.  *
  48.  *
  49.  * SYNOPSIS:
  50.  *
  51.  * int df1, df2;
  52.  * double x, y, fdtrc();
  53.  *
  54.  * y = fdtrc( df1, df2, x );
  55.  *
  56.  *
  57.  *
  58.  * DESCRIPTION:
  59.  *
  60.  * Returns the area from x to infinity under the F density
  61.  * function (also known as Snedcor's density or the
  62.  * variance ratio density).
  63.  *
  64.  *
  65.  *                      inf.
  66.  *                       -
  67.  *              1       | |  a-1      b-1
  68.  * 1-P(x)  =  ------    |   t    (1-t)    dt
  69.  *            B(a,b)  | |
  70.  *                     -
  71.  *                      x
  72.  *
  73.  * (See fdtr.c.)
  74.  *
  75.  * The incomplete beta integral is used, according to the
  76.  * formula
  77.  *
  78.  *    P(x) = incbet( df2/2, df1/2, (df2/(df2 + df1*x) ).
  79.  *
  80.  *
  81.  * ACCURACY:
  82.  *
  83.  * See incbet.c.
  84.  *
  85.  * ERROR MESSAGES:
  86.  *
  87.  *   message         condition      value returned
  88.  * fdtrc domain    a<0, b<0, x<0         0.0
  89.  *
  90.  */
  91. /*                            fdtri()
  92.  *
  93.  *    Inverse of complemented F distribution
  94.  *
  95.  *
  96.  *
  97.  * SYNOPSIS:
  98.  *
  99.  * double df1, df2, x, y, fdtri();
  100.  *
  101.  * x = fdtri( df1, df2, y );
  102.  *
  103.  *
  104.  *
  105.  *
  106.  * DESCRIPTION:
  107.  *
  108.  * Finds the F density argument x such that the integral
  109.  * from x to infinity of the F density is equal to the
  110.  * given probability y.
  111.  *
  112.  * This is accomplished using the inverse beta integral
  113.  * function and the relations
  114.  *
  115.  *      z = incbi( df2/2, df1/2, y )
  116.  *      x = df2 (1-z) / (df1 z).
  117.  *
  118.  * Note: the following relations hold for the inverse of
  119.  * the uncomplemented F distribution:
  120.  *
  121.  *      z = incbi( df1/2, df2/2, y )
  122.  *      x = df2 z / (df1 (1-z)).
  123.  *
  124.  *
  125.  *
  126.  * ACCURACY:
  127.  *
  128.  * See incbi.c.
  129.  *
  130.  * ERROR MESSAGES:
  131.  *
  132.  *   message         condition      value returned
  133.  * fdtri domain   y <= 0 or y > 1       0.0
  134.  *                     v < 1
  135.  *
  136.  */
  137.  
  138.  
  139. /*
  140. Cephes Math Library Release 2.0:  April, 1987
  141. Copyright 1984, 1987 by Stephen L. Moshier
  142. Direct inquiries to 30 Frost Street, Cambridge, MA 02140
  143. */
  144.  
  145.  
  146. #include "mconf.h"
  147.  
  148. double fdtrc( ia, ib, x )
  149. int ia, ib;
  150. double x;
  151. {
  152. double a, b, w;
  153. double incbet();
  154.  
  155. if( (ia < 1) || (ib < 1) || (x < 0.0) )
  156.     {
  157.     mtherr( "fdtrc", DOMAIN );
  158.     return( 0.0 );
  159.     }
  160. a = ia;
  161. b = ib;
  162. w = b / (b + a * x);
  163. return( incbet( b/2.0, a/2.0, w ) );
  164. }
  165.  
  166.  
  167.  
  168. double fdtr( ia, ib, x )
  169. int ia, ib;
  170. double x;
  171. {
  172. double a, b, w;
  173. double incbet();
  174.  
  175. if( (ia < 1) || (ib < 1) || (x < 0.0) )
  176.     {
  177.     mtherr( "fdtr", DOMAIN );
  178.     return( 0.0 );
  179.     }
  180. a = ia;
  181. b = ib;
  182. w = a * x;
  183. w = w / (b + w);
  184. return( incbet(a/2.0, b/2.0, w) );
  185. }
  186.  
  187.  
  188. double fdtri( ia, ib, y )
  189. int ia, ib;
  190. double y;
  191. {
  192. double a, b, w, x;
  193. double incbi();
  194.  
  195. if( (ia < 1) || (ib < 1) || (y <= 0.0) || (y > 1.0) )
  196.     {
  197.     mtherr( "fdtri", DOMAIN );
  198.     return( 0.0 );
  199.     }
  200. a = ia;
  201. b = ib;
  202. w = incbi( 0.5*b, 0.5*a, y );
  203. x = (b - b*w)/(a*w);
  204. return(x);
  205. }
  206.