nathanesau nathanesau - 20 days ago 8
R Question

R - Derivative of Log Incomplete Gamma Function

The following functions are available in R:


  • gamma
    to compute gamma function

  • digamma
    to compute derivative of log gamma function

  • pgamma
    to compute incomplete gamma function

  • ? to compute derivative of log incomplete gamma function



I'm wonder what function can compute the derivative of log incomplete gamma function. I noticed the
gsl
package has a function
gamma_inc
but not sure how to compute the derivative of the log of this function.

If no function exists, is there a simple way to approximate this derivative in
R
?

Answer

In fact, my comment and Ben Bolker's together give the answer.

I suggested the use of chain rule of derivation:

log(u(x))' = u'(x) / u(x)

then Ben pointed out that the derivative of pgamma (CDF) is just dgamma (PDF). So, we have

dgamma(x) / pgamma(x)

A properly defined function would be

f <- function (x, shape, rate) dgamma(x, shape, rate) / pgamma(x, shape, rate)