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 (ii)

size

integer vector defining the number of trials per cluster (nin_i)

prob

probability of success on each trial (π\pi)

rho

intra class correlation (ρ\rho)

Details

For beta binomial data with i=1,...Ii=1, ... I clusters, the variance is

var(yi)=niπ(1π)[1+(ni1)ρ]var(y_i)= n_i \pi (1-\pi) [1+ (n_i - 1) \rho]

with ρ\rho as the intra class correlation coefficient

ρ=1/(1+a+b).\rho = 1 / (1+a+b).

For the sampling (a+b)(a+b) is defined as

(a+b)=(1ρ)/ρ(a+b)=(1-\rho)/\rho

where a=π(a+b)a=\pi (a+b) and b=(a+b)ab=(a+b)-a. Then, the binomial proportions for each cluster are sampled from the beta distribution

πiBeta(a,b)\pi_i \sim Beta(a, b)

and the number of successes for each cluster are sampled to be

yiBin(ni,πi).y_i \sim Bin(n_i, \pi_i).

In this parametrization E(πi)=π=a/(a+b)E(\pi_i)=\pi=a/(a+b) and E(yi)=niπE(y_i)=n_i \pi. Please note, that 1+(ni1)ρ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



[Package predint version 2.2.1 Index]