Learn R Programming

HRQoL (version 1.0)

BI:

Description

Density and random generation for the binomial distribution with optional dispersion parameter.

Usage

dBI(m,p,phi)
rBI(k,m,p,phi)

Arguments

k
number of simulations.
m
number of trials in each binomial observation.
p
probability parameter of the binomial distribution.
phi
dispersion parameter of the binomial distribution. If phi=1, the binomial distribution without dispersion parameter will be considered. Default 1.

Value

dBI gives the density of the binomial distribution for those m, p and phi parameters. rBI generates k random observations based on a binomial distribution for those m, p and phi parameters.

Details

The binomial distribution belongs to the exponential family of distributions. Consequenlty, although the usual binomial distribution only consists of two paramters, an additional dispersion parameter can be included. The inclusion of a dispersion parameter softens the relationship between the expectation and variance that the binomial distribution keeps, i.e. the model allows overdispersion to be included, $$E[y]=mp, Var[y]=phi*mp(1-p).$$ The density function of the binomial distribution with dispersion parameter is based on the exponential family approach and it is defined as $$f(y)=exp\{[y*log(p/(1-p))+m*log(1-p)]/phi+c(y,phi)\},$$ where \(c()\) is a function that it is approximated with the deviance of the model by quadratic approximations of the log-likelihood function.

References

Pawitan Y. (2001): In All Likelihood: Statistical Modelling and Inference Using Likelihood. Oxford University Press

See Also

The rbinom functions of package stats. This function performs simulations based on a binomial distribution without dispersion parameter.

Examples

Run this code
k <- 1000
m <- 10
p <- 0.765
phi <- 4.35

#simulating
y <- rBI(k,m,p,phi)
y

#density function
d <- dBI(m,p,phi)
d

#plot the simulated variable and fit the density
hist(y,col="lightgrey")
lines(seq(0,m),k*d,col="blue",lwd=2)

Run the code above in your browser using DataLab