geom.ad: AD-compatible geometric distribution

geom.adR Documentation

AD-compatible geometric distribution

Description

Density and distribution function for the geometric distribution, written so that they can be taped by RTMB.

Usage

dgeom.ad(x, prob, log = FALSE)

pgeom.ad(q, prob, lower.tail = TRUE, log.p = FALSE)

Arguments

x, q

integer vector of counts

prob

probability of success in each trial, in (0,1]

log, log.p

logical; if TRUE, probabilities/ densities p are returned as \log(p).

lower.tail

logical; if TRUE (default), probabilities are P[X \le x], otherwise P[X > x].

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.

Value

dgeom.ad gives the probability mass function and pgeom.ad gives the distribution function.

See Also

zigeom, ztgeom, hgeom

Examples

dgeom.ad(0:5, prob = 0.3)
pgeom.ad(0:5, prob = 0.3)

RTMBdist documentation built on Oct. 31, 2026, 5:07 p.m.