Class Probability
Implementation: Some code taken and adapted from the Java 2D Graph Package 2.4, which in turn is a port from the Cephes 2.2 Math Library (C). Most Cephes code (missing from the 2D Graph Package) directly ported.
- Version:
- 0.91, 08-Dec-99
- Author:
- peter.gedeck@pharma.Novartis.com, wolfgang.hoschek@cern.ch
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final double[]COEFFICIENTS FOR METHOD normalInverse() *protected static final double[]protected static final double[]protected static final double[]protected static final double[]protected static final double[] -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedMakes this class non instantiable, but still let's others inherit from it. -
Method Summary
Modifier and TypeMethodDescriptionstatic doublebeta(double a, double b, double x) Returns the area from zero toxunder the beta density function.static doublebetaComplemented(double a, double b, double x) Returns the area under the right hand tail (fromxto infinity) of the beta density function.static doublebinomial(int k, int n, double p) Returns the sum of the terms0throughkof the Binomial probability density.static doublebinomialComplemented(int k, int n, double p) Returns the sum of the termsk+1throughnof the Binomial probability density.static doublechiSquare(double v, double x) Returns the area under the left hand tail (from 0 tox) of the Chi square probability density function withvdegrees of freedom.static doublechiSquareComplemented(double v, double x) Returns the area under the right hand tail (fromxto infinity) of the Chi square probability density function withvdegrees of freedom.static doubleerrorFunction(double x) Returns the error function of the normal distribution; formerly namederf.static doubleerrorFunctionComplemented(double a) Returns the complementary Error function of the normal distribution; formerly namederfc.static doublegamma(double a, double b, double x) Returns the integral from zero toxof the gamma probability density function.static doublegammaComplemented(double a, double b, double x) Returns the integral fromxto infinity of the gamma probability density function:static doublenegativeBinomial(int k, int n, double p) Returns the sum of the terms0throughkof the Negative Binomial Distribution.static doublenegativeBinomialComplemented(int k, int n, double p) Returns the sum of the termsk+1to infinity of the Negative Binomial distribution.static doublenormal(double a) Returns the area under the Normal (Gaussian) probability density function, integrated from minus infinity tox(assumes mean is zero, variance is one).static doublenormal(double mean, double variance, double x) Returns the area under the Normal (Gaussian) probability density function, integrated from minus infinity tox.static doublenormalInverse(double y0) Returns the value,x, for which the area under the Normal (Gaussian) probability density function (integrated from minus infinity tox) is equal to the argumenty(assumes mean is zero, variance is one); formerly namedndtri.static doublepoisson(int k, double mean) Returns the sum of the firstkterms of the Poisson distribution.static doublepoissonComplemented(int k, double mean) Returns the sum of the termsk+1toInfinityof the Poisson distribution.static doublestudentT(double k, double t) Returns the integral from minus infinity totof the Student-t distribution withk > 0degrees of freedom.static doublestudentTInverse(double alpha, int size) Returns the value,t, for which the area under the Student-t probability density function (integrated from minus infinity tot) is equal to1-alpha/2.
-
Field Details
-
P0
protected static final double[] P0COEFFICIENTS FOR METHOD normalInverse() * -
Q0
protected static final double[] Q0 -
P1
protected static final double[] P1 -
Q1
protected static final double[] Q1 -
P2
protected static final double[] P2 -
Q2
protected static final double[] Q2
-
-
Constructor Details
-
Probability
protected Probability()Makes this class non instantiable, but still let's others inherit from it.
-
-
Method Details
-
beta
public static double beta(double a, double b, double x) Returns the area from zero toxunder the beta density function.x - - | (a+b) | | a-1 b-1 P(x) = ---------- | t (1-t) dt - - | | | (a) | (b) - 0This function is identical to the incomplete beta integral functionGamma.incompleteBeta(a, b, x). The complemented function is1 - P(1-x) = Gamma.incompleteBeta( b, a, x ); -
betaComplemented
public static double betaComplemented(double a, double b, double x) Returns the area under the right hand tail (fromxto infinity) of the beta density function. This function is identical to the incomplete beta integral functionGamma.incompleteBeta(b, a, x). -
binomial
public static double binomial(int k, int n, double p) Returns the sum of the terms0throughkof the Binomial probability density.k -- ( n ) j n-j > ( ) p (1-p) -- ( j ) j=0
The terms are not summed directly; instead the incomplete beta integral is employed, according to the formulay = binomial( k, n, p ) = Gamma.incompleteBeta( n-k, k+1, 1-p ).All arguments must be positive,
- Parameters:
k- end term.n- the number of trials.p- the probability of success (must be in(0.0,1.0)).
-
binomialComplemented
public static double binomialComplemented(int k, int n, double p) Returns the sum of the termsk+1throughnof the Binomial probability density.n -- ( n ) j n-j > ( ) p (1-p) -- ( j ) j=k+1
The terms are not summed directly; instead the incomplete beta integral is employed, according to the formulay = binomialComplemented( k, n, p ) = Gamma.incompleteBeta( k+1, n-k, p ).All arguments must be positive,
- Parameters:
k- end term.n- the number of trials.p- the probability of success (must be in(0.0,1.0)).
-
chiSquare
Returns the area under the left hand tail (from 0 tox) of the Chi square probability density function withvdegrees of freedom.inf. - 1 | | v/2-1 -t/2 P( x | v ) = ----------- | t e dt v/2 - | | 2 | (v/2) - xwherexis the Chi-square variable.The incomplete gamma integral is used, according to the formula
y = chiSquare( v, x ) = incompleteGamma( v/2.0, x/2.0 ).The arguments must both be positive.
- Parameters:
v- degrees of freedom.x- integration end point.- Throws:
ArithmeticException
-
chiSquareComplemented
Returns the area under the right hand tail (fromxto infinity) of the Chi square probability density function withvdegrees of freedom.inf. - 1 | | v/2-1 -t/2 P( x | v ) = ----------- | t e dt v/2 - | | 2 | (v/2) - xwherexis the Chi-square variable. The incomplete gamma integral is used, according to the formulay = chiSquareComplemented( v, x ) = incompleteGammaComplement( v/2.0, x/2.0 ). The arguments must both be positive.- Parameters:
v- degrees of freedom.- Throws:
ArithmeticException
-
errorFunction
Returns the error function of the normal distribution; formerly namederf. The integral isx - 2 | | 2 erf(x) = -------- | exp( - t ) dt. sqrt(pi) | | - 0Implementation: For0 <= |x| < 1, erf(x) = x * P4(x**2)/Q5(x**2); otherwiseerf(x) = 1 - erfc(x).Code adapted from the Java 2D Graph Package 2.4, which in turn is a port from the Cephes 2.2 Math Library (C).
- Parameters:
x- the argument to the function.- Throws:
ArithmeticException
-
errorFunctionComplemented
Returns the complementary Error function of the normal distribution; formerly namederfc.1 - erf(x) = inf. - 2 | | 2 erfc(x) = -------- | exp( - t ) dt sqrt(pi) | | - xImplementation: For small x,erfc(x) = 1 - erf(x); otherwise rational approximations are computed.Code adapted from the Java 2D Graph Package 2.4, which in turn is a port from the Cephes 2.2 Math Library (C).
- Parameters:
a- the argument to the function.- Throws:
ArithmeticException
-
gamma
public static double gamma(double a, double b, double x) Returns the integral from zero toxof the gamma probability density function.x b - a | | b-1 -at y = ----- | t e dt - | | | (b) - 0The incomplete gamma integral is used, according to the relationy = Gamma.incompleteGamma( b, a*x ).- Parameters:
a- the paramater a (alpha) of the gamma distribution.b- the paramater b (beta, lambda) of the gamma distribution.x- integration end point.
-
gammaComplemented
public static double gammaComplemented(double a, double b, double x) Returns the integral fromxto infinity of the gamma probability density function:inf. b - a | | b-1 -at y = ----- | t e dt - | | | (b) - xThe incomplete gamma integral is used, according to the relationy = Gamma.incompleteGammaComplement( b, a*x ).
- Parameters:
a- the paramater a (alpha) of the gamma distribution.b- the paramater b (beta, lambda) of the gamma distribution.x- integration end point.
-
negativeBinomial
public static double negativeBinomial(int k, int n, double p) Returns the sum of the terms0throughkof the Negative Binomial Distribution.k -- ( n+j-1 ) n j > ( ) p (1-p) -- ( j ) j=0
In a sequence of Bernoulli trials, this is the probability thatkor fewer failures precede then-th success.The terms are not computed individually; instead the incomplete beta integral is employed, according to the formula
y = negativeBinomial( k, n, p ) = Gamma.incompleteBeta( n, k+1, p ). All arguments must be positive,- Parameters:
k- end term.n- the number of trials.p- the probability of success (must be in(0.0,1.0)).
-
negativeBinomialComplemented
public static double negativeBinomialComplemented(int k, int n, double p) Returns the sum of the termsk+1to infinity of the Negative Binomial distribution.inf -- ( n+j-1 ) n j > ( ) p (1-p) -- ( j ) j=k+1
The terms are not computed individually; instead the incomplete beta integral is employed, according to the formulay = negativeBinomialComplemented( k, n, p ) = Gamma.incompleteBeta( k+1, n, 1-p ). All arguments must be positive,
- Parameters:
k- end term.n- the number of trials.p- the probability of success (must be in(0.0,1.0)).
-
normal
Returns the area under the Normal (Gaussian) probability density function, integrated from minus infinity tox(assumes mean is zero, variance is one).x - 1 | | 2 normal(x) = --------- | exp( - t /2 ) dt sqrt(2pi) | | - -inf. = ( 1 + erf(z) ) / 2 = erfc(z) / 2wherez = x/sqrt(2). Computation is via the functionserrorFunctionanderrorFunctionComplement.- Throws:
ArithmeticException
-
normal
Returns the area under the Normal (Gaussian) probability density function, integrated from minus infinity tox.x - 1 | | 2 normal(x) = --------- | exp( - (t-mean) / 2v ) dt sqrt(2pi*v)| | - -inf.wherev = variance. Computation is via the functionserrorFunction.- Parameters:
mean- the mean of the normal distribution.variance- the variance of the normal distribution.x- the integration limit.- Throws:
ArithmeticException
-
normalInverse
Returns the value,x, for which the area under the Normal (Gaussian) probability density function (integrated from minus infinity tox) is equal to the argumenty(assumes mean is zero, variance is one); formerly namedndtri.For small arguments
0 < y < exp(-2), the program computesz = sqrt( -2.0 * getLog(y) ); then the approximation isx = z - getLog(z)/z - (1/z) P(1/z) / Q(1/z). There are two rational functions P/Q, one for0 < y < exp(-32)and the other foryup toexp(-2). For larger arguments,w = y - 0.5, andx/sqrt(2pi) = w + w**3 R(w**2)/S(w**2)).- Throws:
ArithmeticException
-
poisson
Returns the sum of the firstkterms of the Poisson distribution.k j -- -m m > e -- -- j! j=0
The terms are not summed directly; instead the incomplete gamma integral is employed, according to the relationy = poisson( k, m ) = Gamma.incompleteGammaComplement( k+1, m ). The arguments must both be positive.- Parameters:
k- number of terms.mean- the mean of the poisson distribution.- Throws:
ArithmeticException
-
poissonComplemented
Returns the sum of the termsk+1toInfinityof the Poisson distribution.inf. j -- -m m > e -- -- j! j=k+1
The terms are not summed directly; instead the incomplete gamma integral is employed, according to the formulay = poissonComplemented( k, m ) = Gamma.incompleteGamma( k+1, m ). The arguments must both be positive.- Parameters:
k- start term.mean- the mean of the poisson distribution.- Throws:
ArithmeticException
-
studentT
Returns the integral from minus infinity totof the Student-t distribution withk > 0degrees of freedom.t - | | - | 2 -(k+1)/2 | ( (k+1)/2 ) | ( x ) ---------------------- | ( 1 + --- ) dx - | ( k ) sqrt( k pi ) | ( k/2 ) | | | - -inf.Relation to incomplete beta integral:1 - studentT(k,t) = 0.5 * Gamma.incompleteBeta( k/2, 1/2, z )wherez = k/(k + t**2).Since the function is symmetric about
t=0, the area under the right tail of the density is found by calling the function with-tinstead oft.- Parameters:
k- degrees of freedom.t- integration end point.- Throws:
ArithmeticException
-
studentTInverse
public static double studentTInverse(double alpha, int size) Returns the value,t, for which the area under the Student-t probability density function (integrated from minus infinity tot) is equal to1-alpha/2. The value returned corresponds to usual Student t-distribution lookup table fortalpha[size].The function uses the studentT function to determine the return value iteratively.
- Parameters:
alpha- probabilitysize- size of data set
-