# Distributions Reference

Page Contents

## Distributions

MathymaStats provides a number of routines to support calculations depending on the common probability distributions, including both discrete and continuous distributions.

This page describes how to incorporate these routines into your own Web pages. If you are just interested in obtaining the results for given values in a particular distribution, see the Distribution Look-up Facility .

Remember to include the module containing the distribution routines in your Web page by putting the following line in yoursection:

Each distribution is provided with three routines, to work out the density function [ f( x ) ] for continuous, or probability [ P( x ) ] for discrete, the distribution function [ F( x ) = P( Xx ) ], and the inverse of the distribution function [ x such that F( x ) = prob. ]. The routines are consistently named XxxDens() [ or XxxProb() ], XxxDist(), XxxInv(), where Xxx represents the abbreviated name of the distribution, for example: NormDens(), NormDist(), NormInv() for the normal distribution, BinomProb(), BinomDist(), BinomInv() for the binomial distribution. The arguments for each routine is then as follows:

XxxDens ( value , parameters...)   - continuous
XxxProb ( value , parameters...)   - discrete
value
The value for which the density (or probability) is to be calculated.
parameters...
A list of the distribution parameters separated by commas (e.g. mean and standard deviation for normal, degrees of freedom for chi-squared - see below).
XxxDist ( value , parameters...)
value
The value for which the distribution [ P( Xvalue ) ] is to be calculated.
parameters...
A list of the distribution parameters as in XxxDens().
XxxInv ( probability , parameters... [, accuracy ])   - continuous
XxxInv ( probability , parameters...)   - discrete
probability
The number between zero and one for which you want to find the value such that P( Xvalue ) = probability .
parameters...
A list of the distribution parameters as in XxxDens().
accuracy [ optional ]
The number of decimal places to which the inverse should be calculated (default = 4). See Note on accuracy below

The main difference between the calls to different distributions is just the list of parameters. These are described below for each distribution in turn.

Note on accuracy

Density functions are usually given in terms of explicit formulae, and so can be calculated exactly (within the limits of the language (JavaScript) and the processor used).

The distribution function for discrete distributions can also be calculated exactly, but for continuous distributions there is often no explicit formula, the distribution being an integral of the density. All the algorithms used in MathymaStats have been developed independently and the results tested against standard statistical tables ( e.g. Neave ). There is usually full agreement to the tables, with only occasionally a difference of one in the least significant figure.

As for the inverse of continuous distribution functions, they require a large amount of computing to calculate, which is why there is an option of number of decimal places. The more decimal places you require, the more computing necessary. The result is accurate with regards to the corresponding MathymaStat distribution function, and is the value (with that number of decimal places) for which the distribution function will return a probability closest to that given in the call. This is best illustrated by an example:

To calculate the value which has a distribution of 0.7 in a standard normal distribution, correct to two decimal places, we use:

Compare this with:

Which confirms that 0.52 is the value (with 2 decimal places) which has the distribution value closest to 0.7.

## Continuous Distributions

### Gamma

The Gamma distribution with parameters &alpha. and &beta. has the density function:

f( ~y ) _ = _ fract{&beta.^{&alpha.} ~y^{&alpha. - 1} e^{-&beta.~y} , &Gamma.( &alpha. )}

where &Gamma.( &alpha. ) _ is the gamma function of &alpha..

Calls:

• GammaDens ( value , alpha, beta )
• GammaDist ( value , alpha, beta )
• GammaInv ( prob , alpha, beta [, accuracy ])

where alpha and beta must be a positive real numbers.

MathymaStats uses an algorithm that gives an exact value when alpha is a whole positive integer, and a very good approximation based on the error function (erf) when alpha is a half integer (1&hlf. , 2&hlf. etc.). In other cases a numerical integration using the Simpson method is used. For the theoretical details see Notes

### Chi-Squared

The Chi-Squared distribution with _ ~f _ ~{degrees of freedom} has the density function:

f( ~y ) _ = _ fract{~y ^{~f /2 - 1} e ^{-~y/2} , 2 ^{~f /2} &Gamma.( ~f /2 )}

Calls:

• ChiSqDens ( value , df )
• ChiSqDist ( value , df )
• ChiSqInv ( prob , df [, accuracy ])

where df represents the degrees of freedom of the distribution. This must be a positive whole number.

The Chi-squared distribution is a special case of the Gamma distribution (see Notes ), If _ ~Y ~ &chi.^2 (~k) , _ then ~Y ~ &Gamma. ( ~k/2 , 1/2 ).

Using the MathymaStats algorithm for Gamma distribution described above gives exact values for even ~k and extememly good approximation for odd ~k.

### Standard Normal

The Standard Normal distribution is the Normal distribution with mean zero, and standard deviation 1. It has the density function:

f( ~y ) _ = _ fract{1,&sqrt.\${2&pi.}} exp rndb{fract{- ~y^2,2 }}

Calls:

• StdNormDens ( value )
• StdNormDist ( value )
• StdNormInv ( prob [, accuracy ])

### Normal

The Normal distribution with mean &mu., and standard deviation &sigma. (variance: &sigma.&powtwo.) has the density function:

f( ~y ) _ = _ fract{1,&sqrt.\${2&pi.&sigma.&powtwo.}} exp rndb{fract{- (~y - &mu.)^2,2&sigma.&powtwo. }}

Calls:

• NormDens ( value , mean , std-dev )
• NormDist ( value , mean , std-dev )
• NormInv ( prob , mean , std-dev [, accuracy ])

where mean can be any number, std-dev must be a positive real number.

### Student's t

The Student's t-distribution with _ ~k _ ~{degrees of freedom} has the density function:

f( ~y ) _ = _ fract{&Gamma.( (~k+1)/2 ) (1 + ~y^2/~k)^{-(~k+1)/2},&Gamma.( ~k/2 ) &sqrt.\${~k&pi.}}

Calls:

• StudTDens ( value , df )
• StudTDist ( value , df )
• StudTInv ( prob , df [, accuracy ])

where df represents the degrees of freedom of the distribution. This must be a positive whole number.

### F-Distribution

The F-distribution with _ &nu._1 , &nu._2 _ ~{degrees of freedom} [ &nu._1 is the ~{numerator degrees of freedom} and &nu._2 is the ~{denominator degrees of freedom} ] has the density function:

f( ~y ) _ = _ fract{(&nu._1 ./ &nu._2) &Gamma.( (&nu._1 + &nu._2) ./ 2 ) (&nu._1 ~y ./ &nu._2)^{(&nu._1 ./ 2) - 1} , &Gamma.( &nu._1 ./ 2 ) &Gamma.( &nu._2 ./ 2 ) ( 1 + (&nu._1 ~y ./ &nu._2) )^{(&nu._1 + &nu._2) ./ 2} }

Calls:

• FDens ( value , nu_1 , nu_2 )
• FDist ( value , nu_1 , nu_2 )
• FInv ( prob , nu_1 , nu_2 [, accuracy ])

where nu_1 , nu_2 represent the numerator and denominator degrees of freedom respectively. These must be a positive whole numbers.

### Uniform Distribution

The Uniform distribution with bounds _ ~a _ and _ ~b _ ( ~a < ~b ) , _ has the density function:

f( ~y ) _ = _ array{{1 ./ ( ~b - ~a)}, _ , ~a =< ~y =< ~b / _ /0,,otherwise}

Calls:

• UniDens ( value , lb , ub )
• UniDist ( value , lb , ub )
• UniInv ( prob , lb , ub [, accuracy ])

where lb , ub represent the lower-bound and upper-bound respectively. These can be any number providing lb is strictly less than ub.

## Discrete Distributions

### Binomial

The binomial distribution with number _ ~n , _ and probability of single success _ ~p , _ has the probability function:

P( ~x ) _ = _ ( ^~n_~x ) ~p^~x ( 1 - ~p )^{~n - ~x}

Where _ ~x _ is the number of successes in _ ~n _ Bernoulli trials.

Calls:

• BinomProb ( value , n , p )
• BinomDist ( value , n , p )
• BinomInv ( prob , n , p)

where n represent the number of Bernoulli trials, and p represent the probability of success in a single trial.

### Negative Binomial

The negative binomial distribution with number of successes _ ~r , _ and probability of single success _ ~p , _ has the probability function:

P( ~x ) _ = _ fract{&alpha. (&alpha.+1) ... (&alpha.+~x+1) ,~x (~x-1) ... 1 } ~p^{&alpha.} ( 1 - ~p )^~x

where _ ~x _ represents the number of ~{failures}.

Calls:

• NegBinProb ( value , r , p )
• NegBinDist ( value , r , p )
• NegBinInv ( prob , r , p)

where r represent the number of successful trials, and p represent the probability of success in a single trial.

### Geometric

The geometric distribution with parameter _ ~p , _ has the probability function:

P( ~x ) _ = _ ~p ( 1 - ~p )^~x

Calls:

• GeomProb ( value , p )
• GeomDist ( value , p )
• GeomInv ( prob , p)

### Poisson

The poisson distribution with parameter _ &lamda. , _ has the probability function:

P( ~x ) _ = _ &lamda.^~x e^{-&lamda.} / ~x#!

Calls:

• PoissonProb ( value , lambda )
• PoissonDist ( value , lambda )
• PoissonInv ( prob , lambda)

### Hypergeometric

The hypergeometric distribution with parameters ~n, ~r and ~s has the probability function:

P( ~x ) _ = _ ( ^~r_~x ) ( ^~n_~s^{-}_{-}^~r_~x ){ ./ }( ^~n_~s )

~x is the number of objects with given property in a sample of size ~s from population of size ~n of which ~r objects have the property.

Calls:

• HyperProb ( value , n , r , s )
• HyperDist ( value , n , r , s )
• HyperInv ( prob , n , r , s)