rnbinom function

Sampling of negative binomial data

Sampling of negative binomial data

rnbinom() samples negative-binomial data. The following description of the sampling process is based on the parametrization used by Gsteiger et al. 2013.

rnbinom(n, lambda, kappa, offset = NULL)

Arguments

  • n: defines the number of clusters (II)
  • lambda: defines the overall Poisson mean (λ\lambda)
  • kappa: dispersion parameter (κ\kappa)
  • offset: defines the number of experimental units per cluster (nin_i)

Returns

rnbinom() returns a data.frame with two columns: y as the observations and offset as the number of offsets per observation.

Details

The variance of the negative-binomial distribution is

var(Yi)=niλ(1+κniλ). var(Y_i) = n_i \lambda (1+ \kappa n_i \lambda).

Negative-biomial observations can be sampled based on predefined values of κ\kappa, λ\lambda and nin_i:

Define the parameters of the gamma distribution as a=1κa=\frac{1}{\kappa} and bi=1κniλb_i=\frac{1}{\kappa n_i \lambda}. Then, sample the Poisson means for each cluster

λiGamma(a,bi). \lambda_i \sim Gamma(a, b_i).

Finally, the observations yiy_i are sampled from the Poisson distribution

yiPois(λi) y_i \sim Pois(\lambda_i)

Examples

# Sampling of negative-binomial observations # with different offsets set.seed(123) rnbinom(n=5, lambda=5, kappa=0.13, offset=c(3,3,2,3,2))

References

Gsteiger, S., Neuenschwander, B., Mercier, F. and Schmidli, H. (2013): Using historical control information for the design and analysis of clinical trials with overdispersed count data. Statistics in Medicine, 32: 3609-3622. tools:::Rd_expr_doi("10.1002/sim.5851")

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