rbbinom function

Sampling of beta-binomial data

Sampling of beta-binomial data

rbbinom() samples beta-binomial data according to Menssen and Schaarschmidt (2019).

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)

Returns

a data.frame with two columns (succ, fail)

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.

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

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")

  • Maintainer: Max Menssen
  • License: GPL (>= 2)
  • Last published: 2024-03-04