rbbinom {predint} | R Documentation |
Sampling of beta-binomial data
Description
rbbinom()
samples beta-binomial data according to Menssen and Schaarschmidt (2019).
Usage
rbbinom(n, size, prob, rho)
Arguments
n |
defines the number of clusters ( |
size |
integer vector defining the number of trials per cluster ( |
prob |
probability of success on each trial ( |
rho |
intra class correlation ( |
Details
For beta binomial data with i=1, ... I
clusters, the variance is
var(y_i)= n_i \pi (1-\pi) [1+ (n_i - 1) \rho]
with \rho
as the intra class correlation coefficient
\rho = 1 / (1+a+b).
For the sampling (a+b)
is defined as
(a+b)=(1-\rho)/\rho
where a=\pi (a+b)
and b=(a+b)-a
. Then, the binomial proportions
for each cluster are sampled from the beta distribution
\pi_i \sim Beta(a, b)
and the number of successes for each cluster are sampled to be
y_i \sim Bin(n_i, \pi_i).
In this parametrization E(\pi_i)=\pi=a/(a+b)
and E(y_i)=n_i \pi
.
Please note, that 1+ (n_i-1) \rho
is a constant if all cluster sizes are
the same and hence, in this special case, also the quasi-binomial assumption is
fulfilled.
Value
a data.frame
with two columns (succ, fail)
References
Menssen M, Schaarschmidt F.: Prediction intervals for overdispersed binomial data with application to historical controls. Statistics in Medicine. 2019;38:2652-2663. doi:10.1002/sim.8124
Examples
# Sampling of example data
set.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