| 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 | /* |
| 21 | * Computes the cumulative distribution function for a Poisson |
| 22 | * random variable. For a Poisson random variable X with parameter |
| 23 | * mu, |
| 24 | * |
| 25 | * Pr( X <= k ) = Pr( Y >= p ) |
| 26 | * |
| 27 | * where Y is a gamma random variable with parameters k+1 and 1. |
| 28 | * |
| 29 | * Reference: |
| 30 | * |
| 31 | * W. Feller, "An Introduction to Probability and Its |
| 32 | * Applications," volume 1. Wiley, 1968. Exercise 46, page 173, |
| 33 | * chapter 6. |
| 34 | */ |
| 35 | |
| 36 | #include "gsl__config.h" |
| 37 | #include <math.h> |
| 38 | #include "gsl_math.h" |
| 39 | #include "gsl_errno.h" |
| 40 | #include "gsl_cdf.h" |
| 41 | |
| 42 | #include "gsl_cdf__error.h" |
| 43 | |
| 44 | /* |
| 45 | * Pr (X <= k) for a Poisson random variable X. |
| 46 | */ |
| 47 | |
| 48 | double |
| 49 | gsl_cdf_poisson_P (const unsigned int k, const double mu) |
| 50 | { |
| 51 | double P; |
| 52 | double a; |
| 53 | |
| 54 | if (mu <= 0.0) |
| 55 | { |
| 56 | CDF_ERROR ("mu <= 0", GSL_EDOM); |
| 57 | } |
| 58 | |
| 59 | a = (double) k + 1.0; |
| 60 | P = gsl_cdf_gamma_Q (mu, a, 1.0); |
| 61 | |
| 62 | return P; |
| 63 | } |
| 64 | |
| 65 | /* |
| 66 | * Pr ( X > k ) for a Possion random variable X. |
| 67 | */ |
| 68 | |
| 69 | double |
| 70 | gsl_cdf_poisson_Q (const unsigned int k, const double mu) |
| 71 | { |
| 72 | double Q; |
| 73 | double a; |
| 74 | |
| 75 | if (mu <= 0.0) |
| 76 | { |
| 77 | CDF_ERROR ("mu <= 0", GSL_EDOM); |
| 78 | } |
| 79 | |
| 80 | a = (double) k + 1.0; |
| 81 | Q = gsl_cdf_gamma_P (mu, a, 1.0); |
| 82 | |
| 83 | return Q; |
| 84 | } |