Learn R Programming

emdbook (version 1.3.2.1)

dbetabinom: Beta-binomial distribution

Description

Density function and random variate generator for the beta-binomial function, parameterized in terms of probability and overdispersion

Usage

dbetabinom(x, prob, size,  theta, shape1, shape2, log = FALSE)
rbetabinom(n, prob, size, theta, shape1, shape2)

Arguments

x
a numeric vector of values
prob
numeric vector: mean probability of underlying beta distribution
size
integer: number of samples
theta
overdispersion parameter
shape1
shape parameter of per-trial probability distribution
shape2
shape parameter of per-trial probability distribution
log
(logical) return log probability density?
n
integer number of random variates to return

Value

  • A vector of probability densities or random deviates.

Details

The beta-binomial distribution is the result of compounding a beta distribution of probabilities with a binomial sampling process. The density function is $$p(x) = \frac{C(N,x) \mbox{Beta}(N-x+\theta(1-p),x+\theta p)}{\mbox{Beta}(\theta(1-p),\theta p)}$$ The parameters shape1 and shape2 are the more traditional parameterization in terms of the parameters of the per-trial probability distribution.

References

Morris (1997), American Naturalist 150:299-327

See Also

dbeta, dbinom

Examples

Run this code
set.seed(100)
  n <- 9
  z <- rbetabinom(1000, 0.5, size=n, theta=4)
  plot(table(z)/length(z),ylim=c(0,0.34),col="gray",lwd=4)
  points(0:n,dbinom(0:n,size=n,prob=0.5),col=2,pch=16,type="b")
  points(0:n,dbetabinom(0:n,size=n,theta=4,
           prob=0.5),col=3,pch=17,type="b")
  ## correspondence with SuppDists 
  if (require(SuppDists)) {
    d1a = dghyper(0:5,a=-5,N=-10,k=5)
    d1b = dbetabinom(0:5,shape1=5,shape2=5,size=5)
    max(abs(d1a-d1b))
    p1a = pghyper(0:5,a=-5,N=-10,k=5,lower.tail=TRUE)
    p1b = cumsum(d1b)
    max(abs(p1a-p1b))
  }

Run the code above in your browser using DataLab