rbbinom() samples beta-binomial data according to Menssen and Schaarschmidt (2019).
rbbinom(n, size, prob, rho)
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 (π)
rho: intra class correlation (ρ)
Returns
a data.frame with two columns (succ, fail)
Details
For beta binomial data with i=1,...I clusters, the variance is
var(yi)=niπ(1−π)[1+(ni−1)ρ]
with ρ as the intra class correlation coefficient
ρ=1/(1+a+b).
For the sampling (a+b) is defined as
(a+b)=(1−ρ)/ρ
where a=π(a+b) and b=(a+b)−a. Then, the binomial proportions for each cluster are sampled from the beta distribution
πi∼Beta(a,b)
and the number of successes for each cluster are sampled to be
yi∼Bin(ni,πi).
In this parametrization E(πi)=π=a/(a+b) and E(yi)=niπ. Please note, that 1+(ni−1)ρ is a constant if all cluster sizes are the same and hence, in this special case, also the quasi-binomial assumption is fulfilled.
Examples
# Sampling of example dataset.seed(234)bb_dat1 <- rbbinom(n=10, size=50, prob=0.1, rho=0.06)bb_dat1
set.seed(234)bb_dat2 <- rbbinom(n=3, size=c(40,50,60), prob=0.1, rho=0.06)bb_dat2
References
Menssen M, Schaarschmidt F.: Prediction intervals for overdispersed binomial data with application to historical controls. Statistics in Medicine. 2019;38:2652-2663. tools:::Rd_expr_doi("10.1002/sim.8124")