Blame cdf/poisson.c

Packit 67cb25
/* cdf/poisson.c
Packit 67cb25
 *
Packit 67cb25
 * Copyright (C) 2004 Jason H. Stover.
Packit 67cb25
 *
Packit 67cb25
 * This program is free software; you can redistribute it and/or modify
Packit 67cb25
 * it under the terms of the GNU General Public License as published by
Packit 67cb25
 * the Free Software Foundation; either version 3 of the License, or (at
Packit 67cb25
 * your option) any later version.
Packit 67cb25
 *
Packit 67cb25
 * This program is distributed in the hope that it will be useful, but
Packit 67cb25
 * WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 67cb25
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 67cb25
 * General Public License for more details.
Packit 67cb25
 *
Packit 67cb25
 * You should have received a copy of the GNU General Public License
Packit 67cb25
 * along with this program; if not, write to the Free Software Foundation,
Packit 67cb25
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Packit 67cb25
 */
Packit 67cb25
Packit 67cb25
/*
Packit 67cb25
 * Computes the cumulative distribution function for a Poisson
Packit 67cb25
 * random variable. For a Poisson random variable X with parameter
Packit 67cb25
 * mu,
Packit 67cb25
 *
Packit 67cb25
 *          Pr( X <= k ) = Pr( Y >= p )
Packit 67cb25
 *
Packit 67cb25
 * where Y is a gamma random variable with parameters k+1 and 1.
Packit 67cb25
 *
Packit 67cb25
 * Reference: 
Packit 67cb25
 * 
Packit 67cb25
 * W. Feller, "An Introduction to Probability and Its
Packit 67cb25
 * Applications," volume 1. Wiley, 1968. Exercise 46, page 173,
Packit 67cb25
 * chapter 6.
Packit 67cb25
 */
Packit 67cb25
Packit 67cb25
#include <config.h>
Packit 67cb25
#include <math.h>
Packit 67cb25
#include <gsl/gsl_math.h>
Packit 67cb25
#include <gsl/gsl_errno.h>
Packit 67cb25
#include <gsl/gsl_cdf.h>
Packit 67cb25
Packit 67cb25
#include "error.h"
Packit 67cb25
Packit 67cb25
/*
Packit 67cb25
 * Pr (X <= k) for a Poisson random variable X.
Packit 67cb25
 */
Packit 67cb25
Packit 67cb25
double
Packit 67cb25
gsl_cdf_poisson_P (const unsigned int k, const double mu)
Packit 67cb25
{
Packit 67cb25
  double P;
Packit 67cb25
  double a;
Packit 67cb25
Packit 67cb25
  if (mu <= 0.0)
Packit 67cb25
    {
Packit 67cb25
      CDF_ERROR ("mu <= 0", GSL_EDOM);
Packit 67cb25
    }
Packit 67cb25
Packit 67cb25
  a = (double) k + 1.0;
Packit 67cb25
  P = gsl_cdf_gamma_Q (mu, a, 1.0);
Packit 67cb25
Packit 67cb25
  return P;
Packit 67cb25
}
Packit 67cb25
Packit 67cb25
/*
Packit 67cb25
 * Pr ( X > k ) for a Possion random variable X.
Packit 67cb25
 */
Packit 67cb25
Packit 67cb25
double
Packit 67cb25
gsl_cdf_poisson_Q (const unsigned int k, const double mu)
Packit 67cb25
{
Packit 67cb25
  double Q;
Packit 67cb25
  double a;
Packit 67cb25
Packit 67cb25
  if (mu <= 0.0)
Packit 67cb25
    {
Packit 67cb25
      CDF_ERROR ("mu <= 0", GSL_EDOM);
Packit 67cb25
    }
Packit 67cb25
Packit 67cb25
  a = (double) k + 1.0;
Packit 67cb25
  Q = gsl_cdf_gamma_P (mu, a, 1.0);
Packit 67cb25
Packit 67cb25
  return Q;
Packit 67cb25
}