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( X ≤ x ) ], 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:
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.
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:
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
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:
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.
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:
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:
where mean can be any number, std-dev must be a positive real number.
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:
where df represents the degrees of freedom of the distribution. This must be a positive whole number.
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:
where nu_1 , nu_2 represent the numerator and denominator degrees of freedom respectively. These must be a positive whole numbers.
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:
where lb , ub represent the lower-bound and upper-bound respectively. These can be any number providing lb is strictly less than ub.
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:
where n represent the number of Bernoulli trials, and p represent the probability of success in a single trial.
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:
where r represent the number of successful trials, and p represent the probability of success in a single trial.
The geometric distribution with parameter _ ~p , _ has the probability function:
P( ~x ) _ = _ ~p ( 1 - ~p )^~x
Calls:
The poisson distribution with parameter _ &lamda. , _ has the probability function:
P( ~x ) _ = _ &lamda.^~x e^{-&lamda.} / ~x#!
Calls:
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: