1

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?

nathanesau
  • 1,681
  • 16
  • 27
  • 2
    the derivative of the incomplete gamma function `pgamma` is equivalent to the density function `dgamma`. So you just want `dgamma(x)/pgamma(x)`. – Ben Bolker Nov 19 '16 at 18:16

1 Answers1

8

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)
Zheyuan Li
  • 71,365
  • 17
  • 180
  • 248