Statistical

GAMMALN Formula

Returns the natural logarithm of the gamma function evaluated at the given value. The gamma function extends the factorial to non-integer values, and its logarithm is used to avoid overflow in statistical calculations. It appears in the formulas for many probability distributions including the beta, chi-squared, and Student's t distributions.

Syntax

GAMMALN(x)
ParameterDescription
x Parameter of the GAMMALN function.
Try GAMMALN in Viztab — free, no signup

Examples

Log-gamma of 5 (related to 4!)

Formula
=GAMMALN(5)
Returns ~3.178. Since gamma(5) = 4! = 24, GAMMALN(5) = LN(24) = 3.178.

Computing binomial coefficient

Formula
=EXP(GAMMALN(21)-GAMMALN(6)-GAMMALN(16))
Returns 20349. This calculates C(20,5) = 20!/(5!*15!) using log-gamma to avoid factorial overflow.

Half-integer argument

Formula
=GAMMALN(0.5)
Returns ~0.5724. Gamma(0.5) = sqrt(pi) = 1.7725, so GAMMALN(0.5) = LN(1.7725) = 0.5724.

Common Errors

#NUM!

x must be positive. GAMMALN is undefined for zero and negative values.

#VALUE!

Occurs when the argument is non-numeric text.

Tips

Avoid overflow

Use GAMMALN instead of computing factorials directly. Factorials grow extremely fast — 170! overflows standard floating point, but GAMMALN(171) works fine.

Recover the gamma value

To get the actual gamma function value, use =EXP(GAMMALN(x)). But only do this when the result is small enough not to overflow.

Combinatorial calculations

For combinations C(n,k), use =EXP(GAMMALN(n+1) - GAMMALN(k+1) - GAMMALN(n-k+1)). This works for much larger values than direct factorial computation.

Try GAMMALN in Viztab

Import your data and use GAMMALN with 370+ other formulas. No signup required.

Open Viztab

Related Formulas