Current issue

Vol.26 No.4

Vol.26 No.4

Volumes

© 1984-2017
British APL Association
All rights reserved.

Archive articles posted online on request: ask the archivist.

archive/10/2

Volume 10, No.2

An Improvement to LOGGAMMA

by Norman Thomson

(Step by Step Analysis of Variance, Education Vector, July 1993)

In the first place the name of the function is misleading since what LOGGAMMA delivers is log of gamma of half the argument. An excellent approximation for true log gamma can be obtained from Feller’s extension to Stirling’s formula for log factorial, namely

                                        1     1
ln n! = .5(ln 2n) + (n+.5)(ln n) - n + --- - ---n-3
                                       12n   360

(see An Introduction to Probability, William Feller). Here it is in APL:

[0]  Z←LOGFACT N
[1]  →0 IF 0=Z←N
[2]  Z←((0.5+0,N),÷¯1,12,¯360)+.×(⍟(○2),N),N,÷¨N,N*3

A final trivial adjustment must be made to allow for the fact that ⌈(n)=(n-1)!

For the purposes of FTAIL the above routine is an unnecessary refinement. However there are circumstances where it is invaluable, for example in calculating binomial probabilities with large parameter values, or in applying the Fisher Exact Test.


(webpage generated: 8 December 2005, 05:10)

script began 12:28:09
caching off
debug mode off
cache time 3600 sec
indmtime not found in cache
cached index is fresh
recompiling index.xml
index compiled in 0.302 secs
read index
read issues/index.xml
identified 26 volumes, 101 issues
array (
  'id' => '10012490',
)
regenerated static HTML
article source is 'HTML'
source file encoding is 'ASCII'
read as 'Windows-1252'
completed in 0.3289 secs