Sampling of overdispersed binomial data with constant overdispersion
Sampling of overdispersed binomial data with constant overdispersion
rqbinom samples overdispersed binomial data with constant overdispersion from the beta-binomial distribution such that the quasi-binomial assumption is fulfilled.
rqbinom(n, size, prob, phi)
Arguments
n: defines the number of clusters (i)
size: integer vector defining the number of trials per cluster (ni)
prob: probability of success on each trial (π)
phi: dispersion parameter (Φ)
Returns
a data.frame with two columns (succ, fail)
Details
It is assumed that the dispersion parameter (Φ) is constant for all i=1,...I clusters, such that the variance becomes
var(yi)=Φniπ(1−π).
For the sampling (a+b)i is defined as
(a+b)i=(Φ−ni)/(1−Φ)
where ai=π(a+b)i and bi=(a+b)i−ai. Then, the binomial proportions for each cluster are sampled from the beta distribution
πi∼Beta(ai,bi)
and the numbers of success for each cluster are sampled to be
yi∼Bin(ni,πi).
In this parametrization E(πi)=π and E(yi)=niπ. Please note, the quasi-binomial assumption is not in contradiction with the beta-binomial distribution if all cluster sizes are the same.
Examples
# Sampling of example dataset.seed(456)qb_dat1 <- rqbinom(n=10, size=50, prob=0.1, phi=3)qb_dat1
set.seed(456)qb_dat2 <- rqbinom(n=3, size=c(40,50,60), prob=0.1, phi=3)qb_dat2