gsl_cdf__fdist.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /* cdf/fdist.c
  2. *
  3. * Copyright (C) 2002 Przemyslaw Sliwa and Jason H. Stover.
  4. * Copyright (C) 2006, 2007 Brian Gough
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
  19. */
  20. #include "gsl__config.h"
  21. #include <math.h>
  22. #include "gsl_cdf.h"
  23. #include "gsl_sf_gamma.h"
  24. #include "gsl_math.h"
  25. #include "gsl_errno.h"
  26. #include "gsl_cdf__error.h"
  27. #include "gsl_cdf__beta_inc.c"
  28. /*
  29. * Lower tail.
  30. */
  31. double
  32. gsl_cdf_fdist_P (const double x, const double nu1, const double nu2)
  33. {
  34. double P;
  35. double r = nu2 / nu1;
  36. if (x < r)
  37. {
  38. double u = x / (r + x);
  39. P = beta_inc_AXPY (1.0, 0.0, nu1 / 2.0, nu2 / 2.0, u);
  40. }
  41. else
  42. {
  43. double u = r / (r + x);
  44. P = beta_inc_AXPY (-1.0, 1.0, nu2 / 2.0, nu1 / 2.0, u);
  45. }
  46. return P;
  47. }
  48. /*
  49. * Upper tail.
  50. */
  51. double
  52. gsl_cdf_fdist_Q (const double x, const double nu1, const double nu2)
  53. {
  54. double Q;
  55. double r = nu2 / nu1;
  56. if (x < r)
  57. {
  58. double u = x / (r + x);
  59. Q = beta_inc_AXPY (-1.0, 1.0, nu1 / 2.0, nu2 / 2.0, u);
  60. }
  61. else
  62. {
  63. double u = r / (r + x);
  64. Q = beta_inc_AXPY (1.0, 0.0, nu2 / 2.0, nu1 / 2.0, u);
  65. }
  66. return Q;
  67. }