Brighton Webs Ltd.
Statistics for Energy and the Environment

Digamma Function

The digamma function appears in several statistical applications, for example the maximum likelihood equations for the shape and scale factors of the gamma distribution.  It is defined as:

This is the gradient of:

The the gamma and digamma functions are shown in the plot below:

the digamma function is not always present in maths libraries (e.g. math.net) and spreadsheets such as Excel and it is a complex calculation.  It is suggested that an approximation for real numbers greater than zero can be derived using numerical differentiation of the log(gamma) function.  In Excel the the ln(gamma) function is available as gammaln(x).

The basic numerical differentiation formula is:

The choice of value of delta x  will depend on the application, the precision of calculation (e.g. single, double etc.) and the nature of the gammaln function being called.  In the author's experience, a value of 0.0001 has provided acceptable results for the application to which it was being applied.

The value of psi(1) is -1 * Euler–Mascheroni constant, the values of this and the result of the approximation to six decimal places are shown below:

 Wikpedia Approximation psi(1) -0.577216 -0.577216

The results from the approximation follow th recurrence relationship:

Selected values to 3 d.p. are shown in the table below:

 x psi(x+1) psi(x)+1/x 0.1 -0.424 -0.424 1.0 0.423 0.423 2.0 0.923 0.923 3.0 1.256 1.256 4.0 1.506 1.506

It is not clear what the limitations or generality of this approach are, only that it has facilitated the use of the digamma functions within Excel and in-house software.

Related material

Digamma function
Euler-Mascheroni_constant
gammaln function
Page update: 02-Jun-2012