在 R 编程中计算 gamma函数的对数导数 - digamma()函数
R语言中的digamma()
函数用于计算使用gamma函数计算的gamma值的对数导数。
digamma函数基本上是,
digamma(x) = d(ln(factorial(n-1)))/dx
Syntax: digamma(x)
Parameters:
x: Numeric vector
示例 1:
# R program to find logarithmic derivative
# of the gamma value
# Calling the digamma() Function
digamma(2)
digamma(4)
digamma(5.2)
输出:
[1] 0.4227843
[1] 1.256118
[1] 1.549434
示例 2:
# R program to find logarithmic derivative
# of the gamma value
# Creating a vector
x <- c(2.3, 3, 1.2)
# Calling the digamma() Function
digamma(x)
# Calling digamma() function
# on negative values
digamma(-2.3)
digamma(-2)
输出:
[1] 0.6000399 0.9227843 -0.2890399
[1] 3.317323
[1] NaN
Warning message:
In digamma(-2) : NaNs produced