rqbinom function

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 (ii)
  • size: integer vector defining the number of trials per cluster (nin_i)
  • prob: probability of success on each trial (π\pi)
  • phi: dispersion parameter (Φ\Phi)

Returns

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

Details

It is assumed that the dispersion parameter (Φ\Phi) is constant for all i=1,...Ii=1, ... I clusters, such that the variance becomes

var(yi)=Φniπ(1π). var(y_i)=\Phi n_i \pi (1-\pi).

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

(a+b)i=(Φni)/(1Φ) (a+b)_i=(\Phi-n_i)/(1-\Phi)

where ai=π(a+b)ia_i=\pi (a+b)_i and bi=(a+b)iaib_i=(a+b)_i-a_i. Then, the binomial proportions for each cluster are sampled from the beta distribution

πiBeta(ai,bi) \pi_i \sim Beta(a_i, b_i)

and the numbers of success for each cluster are sampled to be

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

In this parametrization E(πi)=πE(\pi_i)=\pi and E(yi)=niπE(y_i)=n_i \pi. 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 data set.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
  • Maintainer: Max Menssen
  • License: GPL (>= 2)
  • Last published: 2024-03-04