gsl_cdf__fdistinv.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /* cdf/fdistinv.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 "gsl_cdf.h"
  22. #include "gsl_math.h"
  23. #include "gsl_errno.h"
  24. #include "gsl_cdf__error.h"
  25. double
  26. gsl_cdf_fdist_Pinv (const double P, const double nu1, const double nu2)
  27. {
  28. double result;
  29. double y;
  30. if (P < 0.0)
  31. {
  32. CDF_ERROR ("P < 0.0", GSL_EDOM);
  33. }
  34. if (P > 1.0)
  35. {
  36. CDF_ERROR ("P > 1.0", GSL_EDOM);
  37. }
  38. if (nu1 < 1.0)
  39. {
  40. CDF_ERROR ("nu1 < 1", GSL_EDOM);
  41. }
  42. if (nu2 < 1.0)
  43. {
  44. CDF_ERROR ("nu2 < 1", GSL_EDOM);
  45. }
  46. if (P < 0.5)
  47. {
  48. y = gsl_cdf_beta_Pinv (P, nu1 / 2.0, nu2 / 2.0);
  49. result = nu2 * y / (nu1 * (1.0 - y));
  50. }
  51. else
  52. {
  53. y = gsl_cdf_beta_Qinv (P, nu2 / 2.0, nu1 / 2.0);
  54. result = nu2 * (1 - y) / (nu1 * y);
  55. }
  56. return result;
  57. }
  58. double
  59. gsl_cdf_fdist_Qinv (const double Q, const double nu1, const double nu2)
  60. {
  61. double result;
  62. double y;
  63. if (Q < 0.0)
  64. {
  65. CDF_ERROR ("Q < 0.0", GSL_EDOM);
  66. }
  67. if (Q > 1.0)
  68. {
  69. CDF_ERROR ("Q > 1.0", GSL_EDOM);
  70. }
  71. if (nu1 < 1.0)
  72. {
  73. CDF_ERROR ("nu1 < 1", GSL_EDOM);
  74. }
  75. if (nu2 < 1.0)
  76. {
  77. CDF_ERROR ("nu2 < 1", GSL_EDOM);
  78. }
  79. if (Q > 0.5)
  80. {
  81. y = gsl_cdf_beta_Qinv (Q, nu1 / 2.0, nu2 / 2.0);
  82. result = nu2 * y / (nu1 * (1.0 - y));
  83. }
  84. else
  85. {
  86. y = gsl_cdf_beta_Pinv (Q, nu2 / 2.0, nu1 / 2.0);
  87. result = nu2 * (1 - y) / (nu1 * y);
  88. }
  89. return result;
  90. }