nathanesau - 20 days ago 8

R Question

The following functions are available in R:

- to compute gamma function
`gamma`

- to compute derivative of log gamma function
`digamma`

- to compute incomplete gamma function
`pgamma`

- ? 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`

`gamma_inc`

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)
```