gsl_cdf__poisson.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /* cdf/poisson.c
  2. *
  3. * Copyright (C) 2004 Jason H. Stover.
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
  18. */
  19. /*
  20. * Computes the cumulative distribution function for a Poisson
  21. * random variable. For a Poisson random variable X with parameter
  22. * mu,
  23. *
  24. * Pr( X <= k ) = Pr( Y >= p )
  25. *
  26. * where Y is a gamma random variable with parameters k+1 and 1.
  27. *
  28. * Reference:
  29. *
  30. * W. Feller, "An Introduction to Probability and Its
  31. * Applications," volume 1. Wiley, 1968. Exercise 46, page 173,
  32. * chapter 6.
  33. */
  34. #include "gsl__config.h"
  35. #include <math.h>
  36. #include "gsl_math.h"
  37. #include "gsl_errno.h"
  38. #include "gsl_cdf.h"
  39. #include "gsl_cdf__error.h"
  40. /*
  41. * Pr (X <= k) for a Poisson random variable X.
  42. */
  43. double
  44. gsl_cdf_poisson_P (const unsigned int k, const double mu)
  45. {
  46. double P;
  47. double a;
  48. if (mu <= 0.0)
  49. {
  50. CDF_ERROR ("mu <= 0", GSL_EDOM);
  51. }
  52. a = (double) k + 1.0;
  53. P = gsl_cdf_gamma_Q (mu, a, 1.0);
  54. return P;
  55. }
  56. /*
  57. * Pr ( X > k ) for a Possion random variable X.
  58. */
  59. double
  60. gsl_cdf_poisson_Q (const unsigned int k, const double mu)
  61. {
  62. double Q;
  63. double a;
  64. if (mu <= 0.0)
  65. {
  66. CDF_ERROR ("mu <= 0", GSL_EDOM);
  67. }
  68. a = (double) k + 1.0;
  69. Q = gsl_cdf_gamma_P (mu, a, 1.0);
  70. return Q;
  71. }