Functions | |
| double | dbeta (const double x, const double a, const double b, const bool give_log) |
| double | dbinom (const int k, const int n, double p, bool give_log) |
| double | dcauchy (const double x, const double l, const double s, const bool give_log) |
| double | dchisq (const double x, const double n, const bool give_log) |
| double | ddirch (const std::vector< double > &p, const std::vector< double > &a, const bool give_log, const bool include_const) |
| double | dexp (const double x, const double b, const bool give_log) |
| double | df (const double x, const double m, const double n, const bool give_log) |
| double | dgamma (const double x, const double shape, const double scale, const bool give_log) |
| double | dgeom (const unsigned x, const double p, const bool give_log) |
| double | dhyper (const unsigned x, const unsigned r, const unsigned b, const unsigned n, bool giveLog) |
| double | dinvgamma (const double y, const double shape, const double scale, const bool give_log) |
| double | dlnorm (const double x, const double mu, const double sigma, const bool give_log) |
| double | dlogis (const double x, const double m, const double s, const bool give_log) |
| double | dmulti (const std::vector< int > &n, const std::vector< double > &p, const bool give_log, const bool include_factorial) |
| double | dnbinom (const unsigned x, const double n, const double p, const bool give_log) |
| double | dnorm (const double x_in, const double mu, const double sigma, const bool give_log) |
| double | dpois (const unsigned x, const double lambda, const bool give_log) |
| double | dt (const double x, const double n, const bool give_log) |
| double | dweibull (const double x, const double a, const double b, const bool give_log) |
| double | gamln (const double x) |
| double | logChoose (const double n, const double k) |
| double | lbeta (const double a, const double b) |
| double | BetaEntropy (const double a, const double b) |
Variables | |
| const double | MinGammaPar |
| const double | MaxGammaPar |
Provides a variety of numerical density routines. All of them are derived from R. Details are provided in the comments accompanying each one.
| double Density::BetaEntropy | ( | const double | a, | |
| const double | b | |||
| ) |
Entropy of a beta distribution with parameters a and b.
Formula:
| a | first parameter of the beta distribution | |
| b | second parameter of the beta distribution |
is Euler's psi function (also known as the digamma function).
Definition at line 1999 of file Density.cpp.
References lbeta().
| double Density::dbeta | ( | const double | x, | |
| const double | a, | |||
| const double | b, | |||
| const bool | give_log = false | |||
| ) |
Density of the beta distribution
Returns the probability density associated with a beta variate:
| x | ||
| a | ||
| b | ||
| give_log | Return log density? |
This implementation is derived from R. It assumes that the caller has ensured that a and b are positive.
Definition at line 841 of file Density.cpp.
Referenced by logQBeta().
| double Density::dbinom | ( | const int | k, | |
| const int | n, | |||
| double | p, | |||
| bool | give_log | |||
| ) |
Density of the binomial distribution.
Returns probability of getting k successes in n binomial trials with a probability p of success on each trial, if give_log == false. If give_log == true, returns the natural logarithm of the probability.
| k | Number of successes | |
| n | Number of trials | |
| p | Probability of success on each trial | |
| give_log | Return log probability? |
The implementation uses dbinom_raw from R
Definition at line 890 of file Density.cpp.
| double Density::dcauchy | ( | const double | x, | |
| const double | l, | |||
| const double | s, | |||
| const bool | give_log | |||
| ) |
Density of the Cauchy distribution
| x | the x value at which the density is to be calculated | |
| l | the location parameter | |
| s | the scale parameter | |
| give_log | return natural log of density if true |
This implementation is adapted from R v2.0. The sanity checks for s > 0 and ISNAN(x) have been removed.
Definition at line 932 of file Density.cpp.
| double Density::dchisq | ( | const double | x, | |
| const double | n, | |||
| const bool | give_log | |||
| ) |
Density of the chi-squared distribution
| x | the chi-squared variate whose density is desired | |
| n | degrees of freedom for the chi-squared density | |
| give_log | true if natural logarithm of density is desired |
From R v2.0. The implementation simply calls dgamma with shape = n/2 and scale = 2.
Definition at line 978 of file Density.cpp.
References dgamma().
| double Density::ddirch | ( | const std::vector< double > & | p, | |
| const std::vector< double > & | a, | |||
| const bool | give_log = false, |
|||
| const bool | include_const = true | |||
| ) |
Density of the Dirichlet distribution
A brute-force implementation of the Dirichlet density:
| p | Vector of probabilities | |
| a | Vector of Dirichlet parameters | |
| give_log | Return log density? | |
| include_const | Include normalizing constant |
Definition at line 995 of file Density.cpp.
References gamln(), and Util::log_dbl_min.
Referenced by logQDirch().
| double Density::dexp | ( | const double | x, | |
| const double | b, | |||
| const bool | give_log | |||
| ) |
Exponential density
| x | the exponential variate | |
| b | the parameter of the exponential density | |
| give_log | return log density if true |
Derived from R v2.0. Does not propagate NaNs. Does not check to ensure b > 0.
Definition at line 1053 of file Density.cpp.
| double Density::df | ( | const double | x, | |
| const double | m, | |||
| const double | n, | |||
| const bool | give_log | |||
| ) |
Density of the F distribution
| x | the F variate | |
| m | ``numerator'' degrees of freedom | |
| n | ``denominator'' degrees of freedom | |
| give_log | return log density if true |
Derived from R v2.0. Does not do isnan() check on arguments. Does not check m > 0 and n > 0. Callers must ensure that these conditions are met.
Definition at line 1109 of file Density.cpp.
| double Density::dgamma | ( | const double | x, | |
| const double | shape, | |||
| const double | scale, | |||
| const bool | give_log | |||
| ) |
Density of the gamma distribution.
Returns the probability density associated with a gamma variate:
| x | A gamma variate (x) | |
| shape | Shape of the distribution (a) | |
| scale | Scale of the distribution (s) | |
| give_log | Return log density? |
The implementation is derived from R.
Definition at line 1146 of file Density.cpp.
References Util::dbl_max.
Referenced by dchisq().
| double Density::dgeom | ( | const unsigned | x, | |
| const double | p, | |||
| const bool | give_log | |||
| ) |
Density of the geometric distribution
| x | the (integer) geometric variate | |
| p | the parameter of the geometric distribution | |
| give_log | return log density if true |
Derived from R v2.0. Does not check isnan() on x and p. Does not check for 0 < p < 1. Changed x to unsigned int, so check on it is no longer required.
Definition at line 1215 of file Density.cpp.
| double Density::dhyper | ( | const unsigned | x, | |
| const unsigned | r, | |||
| const unsigned | b, | |||
| const unsigned | n, | |||
| bool | giveLog | |||
| ) |
Density of the hypergeometric distribution.
Returns the probability of choosing x white balls in a sample of size n from an urn with r white balls and b black balls (sampling without replacement.
| x | The number of white balls in the sample | |
| r | The number of white balls in the urn | |
| b | The number of black balls in the urn | |
| n | The sample size | |
| giveLog | Return log probability? |
The code is modified from R v1.8.1 to take unsigned integer arguments rather than doubles.
Definition at line 1278 of file Density.cpp.
| double Density::dinvgamma | ( | const double | y, | |
| const double | shape, | |||
| const double | scale, | |||
| const bool | give_log | |||
| ) |
Density of the inverse gamma distribution.
Returns the probability density associated with an inverse gamma variate:
| y | An inverse gamma variate (y) | |
| shape | Shape of the distribution (a) | |
| scale | Scale of the distribution (s) | |
| give_log | Return log density? |
The implementation is based on the R implementation of dgamma(). It first calculates
is then given by
Definition at line 1323 of file Density.cpp.
References gamln().
| double Density::dlnorm | ( | const double | x, | |
| const double | mu, | |||
| const double | sigma, | |||
| const bool | give_log | |||
| ) |
Density of the lognormal distribution
| x | the lognormal variate | |
| mu | logarithm of the mean of the corresponding normal ( ) | |
| sigma | logarithm of the sd of the corresponding normal ( ) | |
| give_log | return log density if true |
Derived from R v2.0. Does not do isnan() checks on arguments. Does not check for sigma > 0.
Definition at line 1380 of file Density.cpp.
| double Density::dlogis | ( | const double | x, | |
| const double | m, | |||
| const double | s, | |||
| const bool | give_log | |||
| ) |
Density of the logistic distribution
or equivalently (dividing numerator and denominator by
)
| x | the logistic variate | |
| m | the location parameter | |
| s | the scale parameter | |
| give_log | return log density if true |
Derived from R v2.0. Does not do isnan() checks on parameters. Does not check for scale > 0.
Definition at line 1429 of file Density.cpp.
| double Density::dmulti | ( | const std::vector< int > & | n, | |
| const std::vector< double > & | p, | |||
| const bool | give_log = false, |
|||
| const bool | include_factorial = false | |||
| ) |
Density of the multinomial distribution
A brute-force implementation of the multinomial density
| n | Vector of observations | |
| p | Vector of probabilities | |
| give_log | Return log probability | |
| include_factorial | Leave out combinatorial coefficient? |
Definition at line 1452 of file Density.cpp.
References Util::dbl_min, gamln(), and Util::log_dbl_min.
| double Density::dnbinom | ( | const unsigned | x, | |
| const double | n, | |||
| const double | p, | |||
| const bool | give_log | |||
| ) |
Density of the negative binomial distribution
| x | the negative binomial variate | |
| n | the ``size'' parameter | |
| p | the ``probability'' parameter | |
| give_log | return log density if true |
Derived from R v2.0. Does not check isnan() on arguments. Does not check 0 < p < 1 or n > 0. Allows non-integer n (as in R). Integer checks for x not needed, since it is passed as unsigned.
Definition at line 1524 of file Density.cpp.
| double Density::dnorm | ( | const double | x_in, | |
| const double | mu, | |||
| const double | sigma, | |||
| const bool | give_log | |||
| ) |
Density of the normal distribution.
Returns the probability density associated with a normal variate:
| x_in | A normal variate (x) | |
| mu | Mean ( ) | |
| sigma | Standard deviation ( ) | |
| give_log | Return log density? |
This implementation is derived from Mathlib via R.
Definition at line 1577 of file Density.cpp.
Referenced by logQNorm().
| double Density::dpois | ( | const unsigned | x, | |
| const double | lambda, | |||
| const bool | give_log | |||
| ) |
Density of the Poisson distribution
| x | the Poisson variate | |
| lambda | the Poisson parameter ( ) | |
| give_log | return log density if true |
Derived from R v2.0. No isnan() checks. Integer check on x discarded since it is unsigned.
Definition at line 1628 of file Density.cpp.
| double Density::dt | ( | const double | x, | |
| const double | n, | |||
| const bool | give_log | |||
| ) |
Density of Student's t distribution
| x | the t deviate | |
| n | the degrees of freedom ( ) | |
| give_log | return log density if true |
Derived from R v2.0. Does not check isnan() or isfinite() on arguments. Does not verify n >= 0.
Definition at line 1680 of file Density.cpp.
Referenced by lot::hypergeom().
| double Density::dweibull | ( | const double | x, | |
| const double | a, | |||
| const double | b, | |||
| const bool | give_log | |||
| ) |
Density of the Weibull distribution
| x | the Weibull variate | |
| a | the ``shape'' parameter | |
| b | the ``scale'' parameter | |
| give_log | return log density if true |
Derived from R v2.0. Does not check isnan() on arguments. Does not check for finite x.
Definition at line 1730 of file Density.cpp.
| double Density::gamln | ( | const double | x | ) |
Natural log of the gamma function
| x |
NIST Guide to Available Math Software. Source for module GAMLN from package CMLIB. Retrieved from TIBER on Wed Apr 29 17:30:20 1998.
Definition at line 1785 of file Density.cpp.
Referenced by ddirch(), dinvgamma(), dmulti(), lbeta(), and logChoose().
| double Density::lbeta | ( | const double | a, | |
| const double | b | |||
| ) |
Logarithm of
.
Formula:
| a | ||
| b |
Definition at line 1981 of file Density.cpp.
References gamln().
Referenced by BetaEntropy().
| double Density::logChoose | ( | const double | n, | |
| const double | k | |||
| ) |
Logarithm of n choose k.
Formula:
| n | Sample size | |
| k | Number of successes |
Definition at line 1967 of file Density.cpp.
References gamln().
| const double Density::MaxGammaPar |
Maximum value of parameters to be used in gamln()
Definition at line 45 of file Density.cpp.
| const double Density::MinGammaPar |
Minimum value of parameters to be used in gamln()
Definition at line 44 of file Density.cpp.
1.5.1