zibinomUC.RdDensity, distribution function, quantile function and random
generation for the zero-inflated binomial distribution with
parameter pstr0.
dzibinom(x, size, prob, pstr0 = 0, log = FALSE)
pzibinom(q, size, prob, pstr0 = 0)
qzibinom(p, size, prob, pstr0 = 0)
rzibinom(n, size, prob, pstr0 = 0)vector of quantiles.
vector of probabilities.
number of trials. It is the \(N\) symbol in the formula
given in zibinomial.
probability of success on each trial.
Same as in runif.
Same as pbinom.
Probability of a structural zero (i.e., ignoring the binomial distribution), called \(\phi\). The default value of \(\phi=0\) corresponds to the response having an ordinary binomial distribution.
The probability function of \(Y\) is 0 with probability \(\phi\), and \(Binomial(size, prob)\) with probability \(1-\phi\). Thus $$P(Y=0) =\phi + (1-\phi) P(W=0)$$ where \(W\) is distributed \(Binomial(size, prob)\).
dzibinom gives the density,
pzibinom gives the distribution function,
qzibinom gives the quantile function, and
rzibinom generates random deviates.
The argument pstr0 is recycled to the required length,
and must have values which lie in the interval \([0,1]\).
These functions actually allow for zero-deflation.
That is, the resulting probability of a zero count
is less than the nominal value of the parent
distribution.
See Zipois for more information.
prob <- 0.2; size <- 10; pstr0 <- 0.5
(ii <- dzibinom(0:size, size, prob, pstr0 = pstr0))
#> [1] 0.5536870912 0.1342177280 0.1509949440 0.1006632960 0.0440401920
#> [6] 0.0132120576 0.0027525120 0.0003932160 0.0000368640 0.0000020480
#> [11] 0.0000000512
max(abs(cumsum(ii) - pzibinom(0:size, size, prob, pstr0 = pstr0))) # 0?
#> [1] 1.110223e-16
table(rzibinom(100, size, prob, pstr0 = pstr0))
#>
#> 0 1 2 3 4
#> 54 20 10 10 6
table(qzibinom(runif(100), size, prob, pstr0 = pstr0))
#>
#> 0 1 2 3 4 5
#> 46 12 20 15 6 1
round(dzibinom(0:10, size, prob, pstr0 = pstr0) * 100) # Similar?
#> [1] 55 13 15 10 4 1 0 0 0 0 0
if (FALSE) x <- 0:size
barplot(rbind(dzibinom(x, size, prob, pstr0 = pstr0),
dbinom(x, size, prob)),
beside = TRUE, col = c("blue", "green"), ylab = "Probability",
main = paste0("ZIB(", size, ", ", prob, ", pstr0 = ", pstr0, ")",
" (blue) vs Binomial(", size, ", ", prob, ") (green)"),
names.arg = as.character(x), las = 1, lwd = 2) # \dontrun{}
#> Error: object 'x' not found