AD-compatible geometric distribution
geom.ad.RdDensity and distribution function for the geometric distribution, written so
that they can be taped by RTMB.
Details
stats already provides the geometric distribution, but its versions
cannot be differentiated. These are AD-compatible replacements, reached
automatically whenever an argument is an AD variable, so stats::dgeom
and stats::pgeom are left untouched for ordinary use.
The parameterisation is the same as in stats: \(X\) is the number of
failures before the first success, so
$$P(X = x;\,\pi) = \pi\,(1 - \pi)^{x}, \quad x = 0, 1, 2, \ldots$$
The density is obtained from the negative binomial with size = 1, for
which RTMB provides an AD method; the distribution function
\(1 - (1-\pi)^{x+1}\) is elementary.