gamma
Gamma Function (and Its Derivatives and Logarithm)
Description
Describes the special mathematics function gamma and
its derivatives and logarithma.
Usage
gamma(x)
lgamma(x)
digamma(x)
trigamma(x)
psigamma(x, deriv = 0)
Arguments
x |
- for gamma and lgamma, a numeric or complex object.
- for digamma, a numeric or
complex value, or a vector.
- For trigamma, a numeric or
complex value, or a vector. It can be real or
complex, but it must have a positive real part.
Missing values (NA) are allowed.
|
Details
gamma and
lgamma:
- For positive integral values, gamma(x) is (x-1)!.
- For negative integral values, gamma(x) is undefined.
- gamma(x) increases very rapidly with x. Use
lgamma to avoid overflow.
For more details about the gamma function, see
http://en.wikipedia.org/wiki/Gamma_function.
digamma,
trigamma and
psigamma:
- The digamma function is the derivative of the log gamma
function. (Abramowitz and Stegun (1965, p. 258.) digamma(x)
is equal to psigamma(x, 0).
- trigamma uses an asymptotic expansion where Re(x) > 5
and a recurrence formula to such a case where Re(x) <= 5.
Accuracy is good. This function is based upon the function trigamma
in Venables and Ripley (1997).
- The trigamma function is the second derivative of
the log gamma function. trigamma(x) is equal to psigamma(x, 1)
- The psigamma function (also called polygamma function)
is the higher derivative of the log gamma function. The level is defined
by the fs"deriv" argument.
gamma,
lgamma,
digamma and
trigamma
are members of the
Math group of generic functions.
NAs are returned when evaluation would cause numerical problems,
except that when an overflow occurs, an infinity is returned.
Value
gamma | returns the gamma function evaluated for
each value in x. |
lgamma | returns natural log of the gamma function
evaluated for each value in x. |
digamma | returns the derivative of the log gamma
function evaluated for each value in x. |
trigamma | returns the second derivative of the log
gamma function evaluated for each value in x. |
psigamma | returns the (deriv+1)-th derivative of
the log gamma function evaluated for each value in x. |
Classes
gamma is used as the default method for classes that do not
inherit a specific method for the function or for the Math
group of functions. The result retains the class and the attributes.
If this behavior is not appropriate, the designer of the
class should provide a method for the function or for the
Math group.
References
Abramowitz, M., and Stegun, I. A. (Eds.). (1965).
Handbook of Mathematical Functions.
New York: Dover.
Venables, W. N. and Ripley, B. D. (1997).
Modern Applied Statistics with S-PLUS, Second Ed.
New York: Springer.
Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988)
The New S Language.
Wadsworth & Brooks/Cole. (For gamma and lgamma.)
Abramowitz, M. and Stegun, I. A. (1972)
Handbook of Mathematical Functions. New York: Dover.
Chapter 6: Gamma and Related Functions.
http://en.wikipedia.org/wiki/Gamma_function.
http://en.wikipedia.org/wiki/Beta_function.
Note
See family for the family generating function Gamma used
with the glm and gam functions. See GAMMA for the
functions related to the gamma distribution: dgamma (density),
pgamma (probability), qgamma (quantile), rgamma
(sample).
See Also
Examples
gamma(6) # same as 5 factorial
(gamma(5+1.0e-6)-gamma(5))/1.0e-6/gamma(5) # Gives: 1.506119
lgamma(20) # natural log of gamma(20)
(lgamma(5+1.0e-6)-lgamma(5))/1.0e-6 # Gives: 1.506118
digamma(6) # derivative
digamma(5) # Gives: 1.506118
trigamma(6)# second derivative
x <- seq(1, 2, .1)
matrix(c(x, trigamma(x)), ncol=2)
identical(digamma(x), psigamma(x, 0)) # Gives: TRUE
identical(trigamma(x), psigamma(x, 1)) # Gives: TRUE