Compute the Natural Logarithm of the Absolute Value of Gamma Function in R Programming – lgamma() Function
lgamma()
function in R Language is used to compute the natural logarithm of the absolute gamma value of a numeric vector computed using the gamma function.
lgamma function is basically,
lgamma(x) = ln(factorial(x - 1))
Syntax: lgamma(x)
Parameters:
x: Non-negative Numeric Vector
Example 1:
# R program to calculate the # natural logarithm of gamma value # Calling lgamma Function lgamma( 2 ) lgamma( 3 ) lgamma( 5 ) |
Output:
[1] 0 [1] 0.6931472 [1] 3.178054
Example 2:
# R program to calculate the lgamma value # Creating vectors x1 < - c( 2 , 3 , 5 ) x2 < - c( 6 , 7 , 8 ) x3 < - c( - 1 , - 2 , - 3 ) # Calling lgamma() Function lgamma(x1) lgamma(x2) lgamma(x3) |
Output:
[1] 0.0000000 0.6931472 3.1780538 [1] 4.787492 6.579251 8.525161 [1] Inf Inf Inf Warning messages: 1: value out of range in 'lgamma' 2: value out of range in 'lgamma' 3: value out of range in 'lgamma'
Here, in the above code, the NaN is produced for a Negative numeric vector.