Zero-inflated density constructer
zero_inflate.Rd
Constructs a zero-inflated density function from a given probability density function
Arguments
- dist
either a probability density function or a probability mass function
- discrete
logical; if
TRUE
, the density forx = 0
will bezeroprob + (1-zeroprob) * dist(0, ...)
. Otherwise it will just bezeroprob
. In standard cases, this will be determined automatically. For non-standard cases, set this toTRUE
orFALSE
depending on the type ofdist
. See details.
Value
zero-inflated density function with first argument x
, second argument zeroprob
, and additional arguments ...
that will be passed to dist
.
Details
The definition of zero-inflation is different for discrete and continuous distributions. For discrete distributions with p.m.f. \(f\) and zero-inflation probability \(p\), we have $$\Pr(X = 0) = p + (1 - p) \cdot f(0),$$ and $$\Pr(X = x) = (1 - p) \cdot f(x), \quad x > 0.$$
For continuous distributions with p.d.f. \(f\), we have $$f_{\text{zinfl}}(x) = p \cdot \delta_0(x) + (1 - p) \cdot f(x),$$ where \(\delta_0\) is the Dirac delta function at zero.
Examples
# Zero-inflated normal distribution
dzinorm <- zero_inflate(dnorm)
dzinorm(c(NA, 0, 2), 0.5, mean = 1, sd = 1)
#> [1] NA 0.5000000 0.1209854
# Zero-inflated Poisson distribution
zipois <- zero_inflate(dpois)
zipois(c(NA, 0, 1), 0.5, 1)
#> [1] NA 0.6839397 0.1839397
# Non-standard case: Zero-inflated reparametrised beta distribution
dzibeta2 <- zero_inflate(dbeta2, discrete = FALSE)