Scythe-1.0.3
Namespaces | Defines | Functions
distributions.h File Reference

Definitions for probability density functions (PDFs), cumulative distribution functions (CDFs), and some common functions (gamma, beta, etc). More...

#include <iostream>
#include <cmath>
#include <cfloat>
#include <climits>
#include <algorithm>
#include <limits>
#include "scythestat/matrix.h"
#include "scythestat/ide.h"
#include "scythestat/error.h"
Include dependency graph for distributions.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

namespace  scythe
 

The Scythe library namespace.


Defines

#define M_PI   3.141592653589793238462643383280
#define M_LN_SQRT_2PI   0.918938533204672741780329736406
#define M_LN_SQRT_PId2   0.225791352644727432363097614947
#define M_1_SQRT_2PI   0.39894228040143267793994605993
#define M_2PI   6.28318530717958647692528676655
#define M_SQRT_32   5.656854249492380195206754896838
#define S0   0.083333333333333333333 /* 1/12 */
#define S1   0.00277777777777777777778 /* 1/360 */
#define S2   0.00079365079365079365079365 /* 1/1260 */
#define S3   0.000595238095238095238095238 /* 1/1680 */
#define S4   0.0008417508417508417508417508/* 1/1188 */
#define SIXTEN   16
#define do_del(X)
#define swap_tail
#define SCYTHE_ARGSET(...)   __VA_ARGS__
#define SCYTHE_DISTFUN_MATRIX(NAME, XTYPE, ARGNAMES,...)

Functions

double scythe::gammafn (double x)
 The gamma function.
double scythe::lngammafn (double x)
 The natural log of the absolute value of the gamma function.
double scythe::betafn (double a, double b)
 The beta function.
double scythe::lnbetafn (double a, double b)
 The natural log of the beta function.
int scythe::factorial (unsigned int n)
 The factorial function.
double scythe::lnfactorial (unsigned int n)
 The log of the factorial function.
double scythe::pbeta (double x, double a, double b)
 The beta distribution function.
template<matrix_order RO, matrix_style RS, matrix_order PO, matrix_style PS>
Matrix< double, RO, RS > scythe::pbeta (const Matrix< double, PO, PS > &X, double a, double b)
template<matrix_order O, matrix_style S>
Matrix< double, O, Concrete > scythe::pbeta (const Matrix< double, O, S > &X, double a, double b)
double scythe::dbeta (double x, double a, double b)
 The beta density function.
template<matrix_order RO, matrix_style RS, matrix_order PO, matrix_style PS>
Matrix< double, RO, RS > scythe::dbeta (const Matrix< double, PO, PS > &X, double a, double b)
template<matrix_order O, matrix_style S>
Matrix< double, O, Concrete > scythe::dbeta (const Matrix< double, O, S > &X, double a, double b)
double scythe::lndbeta1 (double x, double a, double b)
 The natural log of the ordinate of the beta density function.
template<matrix_order RO, matrix_style RS, matrix_order PO, matrix_style PS>
Matrix< double, RO, RS > scythe::lndbeta1 (const Matrix< double, PO, PS > &X, double a, double b)
template<matrix_order O, matrix_style S>
Matrix< double, O, Concrete > scythe::lndbeta1 (const Matrix< double, O, S > &X, double a, double b)
double scythe::pbinom (double x, unsigned int n, double p)
 The binomial distribution function.
template<matrix_order RO, matrix_style RS, matrix_order PO, matrix_style PS>
Matrix< double, RO, RS > scythe::pbinom (const Matrix< double, PO, PS > &X, unsigned int n, double p)
template<matrix_order O, matrix_style S>
Matrix< double, O, Concrete > scythe::pbinom (const Matrix< double, O, S > &X, unsigned int n, double p)
double scythe::dbinom (double x, unsigned int n, double p)
 The binomial density function.
template<matrix_order RO, matrix_style RS, matrix_order PO, matrix_style PS>
Matrix< double, RO, RS > scythe::dbinom (const Matrix< double, PO, PS > &X, unsigned int n, double p)
template<matrix_order O, matrix_style S>
Matrix< double, O, Concrete > scythe::dbinom (const Matrix< double, O, S > &X, unsigned int n, double p)
double scythe::pchisq (double x, double df)
 The $\chi^2$ distribution function.
template<matrix_order RO, matrix_style RS, matrix_order PO, matrix_style PS>
Matrix< double, RO, RS > scythe::pchisq (const Matrix< double, PO, PS > &X, double df)
template<matrix_order O, matrix_style S>
Matrix< double, O, Concrete > scythe::pchisq (const Matrix< double, O, S > &X, double df)
double scythe::dchisq (double x, double df)
 The $\chi^2$ density function.
template<matrix_order RO, matrix_style RS, matrix_order PO, matrix_style PS>
Matrix< double, RO, RS > scythe::dchisq (const Matrix< double, PO, PS > &X, double df)
template<matrix_order O, matrix_style S>
Matrix< double, O, Concrete > scythe::dchisq (const Matrix< double, O, S > &X, double df)
double scythe::pexp (double x, double scale)
 The exponential distribution function.
template<matrix_order RO, matrix_style RS, matrix_order PO, matrix_style PS>
Matrix< double, RO, RS > scythe::pexp (const Matrix< double, PO, PS > &X, double scale)
template<matrix_order O, matrix_style S>
Matrix< double, O, Concrete > scythe::pexp (const Matrix< double, O, S > &X, double scale)
double scythe::dexp (double x, double scale)
 The exponential density function.
template<matrix_order RO, matrix_style RS, matrix_order PO, matrix_style PS>
Matrix< double, RO, RS > scythe::dexp (const Matrix< double, PO, PS > &X, double scale)
template<matrix_order O, matrix_style S>
Matrix< double, O, Concrete > scythe::dexp (const Matrix< double, O, S > &X, double scale)
double scythe::pf (double x, double df1, double df2)
 The F distribution function.
template<matrix_order RO, matrix_style RS, matrix_order PO, matrix_style PS>
Matrix< double, RO, RS > scythe::pf (const Matrix< double, PO, PS > &X, double df1, double df2)
template<matrix_order O, matrix_style S>
Matrix< double, O, Concrete > scythe::pf (const Matrix< double, O, S > &X, double df1, double df2)
double scythe::df (double x, double df1, double df2)
 The F density function.
template<matrix_order RO, matrix_style RS, matrix_order PO, matrix_style PS>
Matrix< double, RO, RS > scythe::df (const Matrix< double, PO, PS > &X, double df1, double df2)
template<matrix_order O, matrix_style S>
Matrix< double, O, Concrete > scythe::df (const Matrix< double, O, S > &X, double df1, double df2)
double scythe::pgamma (double x, double shape, double scale)
 The gamma distribution function.
template<matrix_order RO, matrix_style RS, matrix_order PO, matrix_style PS>
Matrix< double, RO, RS > scythe::pgamma (const Matrix< double, PO, PS > &X, double shape, double scale)
template<matrix_order O, matrix_style S>
Matrix< double, O, Concrete > scythe::pgamma (const Matrix< double, O, S > &X, double shape, double scale)
double scythe::dgamma (double x, double shape, double scale)
 The gamma density function.
template<matrix_order RO, matrix_style RS, matrix_order PO, matrix_style PS>
Matrix< double, RO, RS > scythe::dgamma (const Matrix< double, PO, PS > &X, double shape, double scale)
template<matrix_order O, matrix_style S>
Matrix< double, O, Concrete > scythe::dgamma (const Matrix< double, O, S > &X, double shape, double scale)
double scythe::plogis (double x, double location, double scale)
 The logistic distribution function.
template<matrix_order RO, matrix_style RS, matrix_order PO, matrix_style PS>
Matrix< double, RO, RS > scythe::plogis (const Matrix< double, PO, PS > &X, double location, double scale)
template<matrix_order O, matrix_style S>
Matrix< double, O, Concrete > scythe::plogis (const Matrix< double, O, S > &X, double location, double scale)
double scythe::dlogis (double x, double location, double scale)
 The logistic density function.
template<matrix_order RO, matrix_style RS, matrix_order PO, matrix_style PS>
Matrix< double, RO, RS > scythe::dlogis (const Matrix< double, PO, PS > &X, double location, double scale)
template<matrix_order O, matrix_style S>
Matrix< double, O, Concrete > scythe::dlogis (const Matrix< double, O, S > &X, double location, double scale)
double scythe::plnorm (double x, double logmean, double logsd)
 The log-normal distribution function.
template<matrix_order RO, matrix_style RS, matrix_order PO, matrix_style PS>
Matrix< double, RO, RS > scythe::plnorm (const Matrix< double, PO, PS > &X, double logmean, double logsd)
template<matrix_order O, matrix_style S>
Matrix< double, O, Concrete > scythe::plnorm (const Matrix< double, O, S > &X, double logmean, double logsd)
double scythe::dlnorm (double x, double logmean, double logsd)
 The log-normal density function.
template<matrix_order RO, matrix_style RS, matrix_order PO, matrix_style PS>
Matrix< double, RO, RS > scythe::dlnorm (const Matrix< double, PO, PS > &X, double logmean, double logsd)
template<matrix_order O, matrix_style S>
Matrix< double, O, Concrete > scythe::dlnorm (const Matrix< double, O, S > &X, double logmean, double logsd)
double scythe::pnbinom (unsigned int x, double n, double p)
 The negative binomial distribution function.
template<matrix_order RO, matrix_style RS, matrix_order PO, matrix_style PS>
Matrix< double, RO, RS > scythe::pnbinom (const Matrix< unsigned int, PO, PS > &X, double n, double p)
template<matrix_order O, matrix_style S>
Matrix< double, O, Concrete > scythe::pnbinom (const Matrix< unsigned int, O, S > &X, double n, double p)
double scythe::dnbinom (unsigned int x, double n, double p)
 The negative binomial density function.
template<matrix_order RO, matrix_style RS, matrix_order PO, matrix_style PS>
Matrix< double, RO, RS > scythe::dnbinom (const Matrix< unsigned int, PO, PS > &X, double n, double p)
template<matrix_order O, matrix_style S>
Matrix< double, O, Concrete > scythe::dnbinom (const Matrix< unsigned int, O, S > &X, double n, double p)
double scythe::pnorm (double x, double mean, double sd)
 The normal distribution function.
template<matrix_order RO, matrix_style RS, matrix_order PO, matrix_style PS>
Matrix< double, RO, RS > scythe::pnorm (const Matrix< double, PO, PS > &X, double mean, double sd)
template<matrix_order O, matrix_style S>
Matrix< double, O, Concrete > scythe::pnorm (const Matrix< double, O, S > &X, double mean, double sd)
double scythe::dnorm (double x, double mean, double sd)
 The normal density function.
template<matrix_order RO, matrix_style RS, matrix_order PO, matrix_style PS>
Matrix< double, RO, RS > scythe::dnorm (const Matrix< double, PO, PS > &X, double mean, double sd)
template<matrix_order O, matrix_style S>
Matrix< double, O, Concrete > scythe::dnorm (const Matrix< double, O, S > &X, double mean, double sd)
double scythe::lndnorm (double x, double mean, double sd)
 The natural log of normal density function.
template<matrix_order RO, matrix_style RS, matrix_order PO, matrix_style PS>
Matrix< double, RO, RS > scythe::lndnorm (const Matrix< double, PO, PS > &X, double mean, double sd)
template<matrix_order O, matrix_style S>
Matrix< double, O, Concrete > scythe::lndnorm (const Matrix< double, O, S > &X, double mean, double sd)
double scythe::qnorm1 (double in_p)
 The standard normal quantile function.
template<matrix_order RO, matrix_style RS, matrix_order PO, matrix_style PS>
Matrix< double, RO, RS > scythe::qnorm1 (const Matrix< double, PO, PS > &X, double in_p)
template<matrix_order O, matrix_style S>
Matrix< double, O, Concrete > scythe::qnorm1 (const Matrix< double, O, S > &X, double in_p)
double scythe::ppois (unsigned int x, double lambda)
 The Poisson distribution function.
template<matrix_order RO, matrix_style RS, matrix_order PO, matrix_style PS>
Matrix< double, RO, RS > scythe::ppois (const Matrix< unsigned int, PO, PS > &X, double lambda)
template<matrix_order O, matrix_style S>
Matrix< double, O, Concrete > scythe::ppois (const Matrix< unsigned int, O, S > &X, double lambda)
double scythe::dpois (unsigned int x, double lambda)
 The Poisson density function.
template<matrix_order RO, matrix_style RS, matrix_order PO, matrix_style PS>
Matrix< double, RO, RS > scythe::dpois (const Matrix< unsigned int, PO, PS > &X, double lambda)
template<matrix_order O, matrix_style S>
Matrix< double, O, Concrete > scythe::dpois (const Matrix< unsigned int, O, S > &X, double lambda)
double scythe::pt (double x, double n)
 The Student t distribution function.
template<matrix_order RO, matrix_style RS, matrix_order PO, matrix_style PS>
Matrix< double, RO, RS > scythe::pt (const Matrix< double, PO, PS > &X, double n)
template<matrix_order O, matrix_style S>
Matrix< double, O, Concrete > scythe::pt (const Matrix< double, O, S > &X, double n)
double scythe::dt (double x, double n)
 The Student t distribution function.
template<matrix_order RO, matrix_style RS, matrix_order PO, matrix_style PS>
Matrix< double, RO, RS > scythe::dt (const Matrix< double, PO, PS > &X, double n)
template<matrix_order O, matrix_style S>
Matrix< double, O, Concrete > scythe::dt (const Matrix< double, O, S > &X, double n)
double scythe::dt1 (double x, double mu, double sigma2, double nu)
 The univariate Student t density function.
template<matrix_order RO, matrix_style RS, matrix_order PO, matrix_style PS>
Matrix< double, RO, RS > scythe::dt1 (const Matrix< double, PO, PS > &X, double mu, double sigma2, double nu)
template<matrix_order O, matrix_style S>
Matrix< double, O, Concrete > scythe::dt1 (const Matrix< double, O, S > &X, double mu, double sigma2, double nu)
double scythe::lndt1 (double x, double mu, double sigma2, double nu)
 The natural log of the univariate Student t density function.
template<matrix_order RO, matrix_style RS, matrix_order PO, matrix_style PS>
Matrix< double, RO, RS > scythe::lndt1 (const Matrix< double, PO, PS > &X, double mu, double sigma2, double nu)
template<matrix_order O, matrix_style S>
Matrix< double, O, Concrete > scythe::lndt1 (const Matrix< double, O, S > &X, double mu, double sigma2, double nu)
double scythe::punif (double x, double a, double b)
 The uniform distribution function.
template<matrix_order RO, matrix_style RS, matrix_order PO, matrix_style PS>
Matrix< double, RO, RS > scythe::punif (const Matrix< double, PO, PS > &X, double a, double b)
template<matrix_order O, matrix_style S>
Matrix< double, O, Concrete > scythe::punif (const Matrix< double, O, S > &X, double a, double b)
double scythe::dunif (double x, double a, double b)
 The uniform density function.
template<matrix_order RO, matrix_style RS, matrix_order PO, matrix_style PS>
Matrix< double, RO, RS > scythe::dunif (const Matrix< double, PO, PS > &X, double a, double b)
template<matrix_order O, matrix_style S>
Matrix< double, O, Concrete > scythe::dunif (const Matrix< double, O, S > &X, double a, double b)
double scythe::pweibull (double x, double shape, double scale)
 The Weibull distribution function.
template<matrix_order RO, matrix_style RS, matrix_order PO, matrix_style PS>
Matrix< double, RO, RS > scythe::pweibull (const Matrix< double, PO, PS > &X, double shape, double scale)
template<matrix_order O, matrix_style S>
Matrix< double, O, Concrete > scythe::pweibull (const Matrix< double, O, S > &X, double shape, double scale)
double scythe::dweibull (double x, double shape, double scale)
 The Weibull density function.
template<matrix_order RO, matrix_style RS, matrix_order PO, matrix_style PS>
Matrix< double, RO, RS > scythe::dweibull (const Matrix< double, PO, PS > &X, double shape, double scale)
template<matrix_order O, matrix_style S>
Matrix< double, O, Concrete > scythe::dweibull (const Matrix< double, O, S > &X, double shape, double scale)
template<matrix_order O1, matrix_style 0. 00277777777777777777778, matrix_order O2, matrix_style 0. 00079365079365079365079365, matrix_order O3, matrix_style 0. 000595238095238095238095238>
double scythe::lndmvn (const Matrix< double, O1, 0.00277777777777777777778 > &x, const Matrix< double, O2, 0.00079365079365079365079365 > &mu, const Matrix< double, O3, 0.000595238095238095238095238 > &Sigma)
 The natural log of the multivariate normal density function.

Detailed Description

Definitions for probability density functions (PDFs), cumulative distribution functions (CDFs), and some common functions (gamma, beta, etc).

This file provides functions that evaluate the PDFs and CDFs of a number of probability distributions. In addition, it includes definitions for another of related functions, such as the gamma and beta functions.

The various distribution functions in this file operate on both scalar quantiles and matrices of quantiles and the definitions of both forms of these functions appear below. We provide explicit documentation only for the scalar versions of the these functions and describe the Matrix versions in the scalar calls' documents. Much like the operators in matrix.h, we implement these overloaded versions of the distribution functions in terms of both generalized and default templates to allow for explicit control over the template type of the returned Matrix.

Note:
Doxygen does not correctly expand the macro definitions we use to generate the Matrix versions of the various distribution functions. Therefore, it incorrectly substitutes the macro variable __VA_ARGS__ for the actual parameter values in the parameter lists of each of these functions. For example, the definitions of the Matrix versions of pbeta are listed as
 template<matrix_order RO, matrix_style RS, matrix_order PO, matrix_style PS>
 Matrix<double, RO, RS> scythe::pbeta (const Matrix<double, PO, PS> &X, __VA_ARGS__)

 template<matrix_order O, matrix_style S>
 Matrix<double, O, Concrete> scythe::pbeta (const Matrix<double, O, S> &X, __VA_ARGS__)
when they should be
 template<matrix_order RO, matrix_style RS, matrix_order PO, matrix_style PS>
 Matrix<double, RO, RS> scythe::pbeta (const Matrix<double, PO, PS> &X, double a, double b)

 template<matrix_order O, matrix_style S>
 Matrix<double, O, Concrete> scythe::pbeta (const Matrix<double, O, S> &X, double a, double b)
Furthermore, Doxygen erroneously lists a number of variables at the end of this document that are not, in fact, declared in distributions.h. Again, this error is a result of Doxygen's macro parsing capabilities.