Extbetabinom {VGAM}R Documentation

The Beta-Binomial Distribution

Description

Density, distribution function, quantile function and random generation for the extended beta-binomial distribution.

Usage

dextbetabinom(x, size, prob, rho = 0,
     log = FALSE, forbycol = TRUE)
pextbetabinom(q, size, prob, rho = 0,
     lower.tail = TRUE, forbycol = TRUE)
qextbetabinom(p, size, prob, rho = 0,
     forbycol = TRUE)
rextbetabinom(n, size, prob, rho = 0)

Arguments

x, q

vector of quantiles.

p

vector of probabilities.

size

number of trials.

n

number of observations. Same as runif.

prob

the probability of success \mu. Must be in the unit closed interval [0,1].

rho

the correlation parameter \rho, which may be negative for underdispersion or else be in the interval [0, 1) for overdispersion. The default value of 0 corresponds to the usual binomial distribution with probability prob.

log, lower.tail

Same meaning as runif.

forbycol

Logical. A for loop cycles over either the rows or columns and this argument determines which. The rows are 1:length(x) and the columns are 0:max(size). The best choice is data set dependent.

Details

The extended beta-binomial distribution allows for a slightly negative correlation parameter between binary responses within a cluster (e.g., a litter). An exchangeable error structure with correlation \rho is assumed.

Value

dextbetabinom gives the density, pextbetabinom gives the distribution function, qextbetabinom gives the quantile function and rextbetabinom generates random deviates.

Warning

Setting rho = 1 is not recommended as NaN is returned, however the code may be modified in the future to handle this special case.

Note

Currently most of the code is quite slow. Speed improvements are a future project. Use forbycol optimally.

See Also

extbetabinomial, Betabinom, Binomial.

Examples

set.seed(1); rextbetabinom(10, 100, 0.5)
set.seed(1);        rbinom(10, 100, 0.5)  # Same

## Not run: N <- 9; xx <- 0:N; prob <- 0.5; rho <- -0.02
dy <- dextbetabinom(xx, N, prob, rho)
barplot(rbind(dy, dbinom(xx, size = N, prob)),
  beside = TRUE, col = c("blue","green"), las = 1,
  main = paste0("Beta-binom(size=", N, 
  ", prob=", prob, ", rho=", rho, ") (blue) vs\n",
  " Binom(size=", N, ", prob=", prob, ") (green)"),
  names.arg = as.character(xx), cex.main = 0.8)
sum(dy * xx)  # Check expected values are equal
sum(dbinom(xx, size = N, prob = prob) * xx)
cumsum(dy) - pextbetabinom(xx, N, prob, rho)  # 0?

## End(Not run)

[Package VGAM version 1.1-10 Index]