Learn R Programming

gamlss.dist (version 6.1-1)

BB: Beta Binomial Distribution For Fitting a GAMLSS Model

Description

This function defines the beta binomial distribution, a two parameter distribution, for a gamlss.family object to be used in a GAMLSS fitting using the function gamlss()

Usage

BB(mu.link = "logit", sigma.link = "log")
dBB(x, mu = 0.5, sigma = 1, bd = 10, log = FALSE)
pBB(q, mu = 0.5, sigma = 1, bd = 10, lower.tail = TRUE,
      log.p = FALSE)
qBB(p, mu = 0.5, sigma = 1, bd = 10, lower.tail = TRUE, 
       log.p = FALSE, fast = FALSE)
rBB(n, mu = 0.5, sigma = 1, bd = 10, fast = FALSE)

Value

Returns a gamlss.family object which can be used to fit a Beta Binomial distribution in the gamlss() function.

Arguments

mu.link

Defines the mu.link, with "logit" link as the default for the mu parameter. Other links are "probit" and "cloglog"'(complementary log-log)

sigma.link

Defines the sigma.link, with "log" link as the default for the sigma parameter. Other links are "inverse", "identity" and "sqrt"

mu

vector of positive probabilities

sigma

the dispersion parameter

bd

vector of binomial denominators

p

vector of probabilities

x,q

vector of quantiles

n

number of random values to return

log, log.p

logical; if TRUE, probabilities p are given as log(p)

lower.tail

logical; if TRUE (default), probabilities are P[X <= x], otherwise, P[X > x]

fast

a logical variable if fast=TRUE the dBB function is used in the calculation of the inverse c.d.f function. This is faster to the default fast=FALSE, where the pBB{} is used, but not always consistent with the results obtained from pBB(), for example if p <- pBB(c(0,1,2,3,4,5), mu=.5 , sigma=1, bd=5) do not ensure that qBB(p, mu=.5 , sigma=1, bd=5) will be c(0,1,2,3,4,5)

Author

Mikis Stasinopoulos, Bob Rigby and Kalliope Akantziliotou

Warning

The functions pBB and qBB are calculated using a laborious procedure so they are relatively slow.

Details

Definition file for beta binomial distribution. $$f(y|\mu,\sigma)=\frac{\Gamma(n+1)} {\Gamma(y+1)\Gamma(n-y+1)} \frac{\Gamma(\frac{1}{\sigma}) \Gamma(y+\frac{\mu}{\sigma}) \Gamma[n+\frac{(1-\mu)}{\sigma}-y]}{\Gamma(n+\frac{1}{\sigma}) \Gamma(\frac{\mu}{\sigma}) \Gamma(\frac{1-\mu}{\sigma})}$$ for \(y=0,1,2,\ldots,n\), \(0<\mu<1\) and \(\sigma>0\), see pp. 523-524 of Rigby et al. (2019). . For \(\mu=0.5\) and \(\sigma=0.5\) the distribution is uniform.

References

Rigby, R. A. and Stasinopoulos D. M. (2005). Generalized additive models for location, scale and shape, (with discussion), Appl. Statist., 54, part 3, pp 507-554.

Rigby, R. A., Stasinopoulos, D. M., Heller, G. Z., and De Bastiani, F. (2019) Distributions for modeling location, scale, and shape: Using GAMLSS in R, Chapman and Hall/CRC, tools:::Rd_expr_doi("10.1201/9780429298547"). An older version can be found in https://www.gamlss.com/.

Stasinopoulos D. M. Rigby R.A. (2007) Generalized additive models for location scale and shape (GAMLSS) in R. Journal of Statistical Software, Vol. 23, Issue 7, Dec 2007, tools:::Rd_expr_doi("10.18637/jss.v023.i07").

Stasinopoulos D. M., Rigby R.A., Heller G., Voudouris V., and De Bastiani F., (2017) Flexible Regression and Smoothing: Using GAMLSS in R, Chapman and Hall/CRC. tools:::Rd_expr_doi("10.1201/b21973")

(see also https://www.gamlss.com/).

See Also

gamlss.family, BI,

Examples

Run this code
# BB()# gives information about the default links for the Beta Binomial distribution 
#plot the pdf
plot(function(y) dBB(y, mu = .5, sigma = 1, bd =40), from=0, to=40, n=40+1, type="h")
#calculate the cdf and plotting it
ppBB <- pBB(seq(from=0, to=40), mu=.2 , sigma=3, bd=40)
plot(0:40,ppBB, type="h")
#calculating quantiles and plotting them  
qqBB <- qBB(ppBB, mu=.2 , sigma=3, bd=40)
plot(qqBB~ ppBB)
# when the argument fast is useful
p <- pBB(c(0,1,2,3,4,5), mu=.01 , sigma=1, bd=5)
qBB(p, mu=.01 , sigma=1, bd=5, fast=TRUE)
#  0 1 1 2 3 5
qBB(p, mu=.01 , sigma=1, bd=5, fast=FALSE)
#  0 1 2 3 4 5
# generate random sample
tN <- table(Ni <- rBB(1000, mu=.2, sigma=1, bd=20))
r <- barplot(tN, col='lightblue')
# fitting a model 
# library(gamlss)
#data(aep)   
# fits a Beta-Binomial model
#h<-gamlss(y~ward+loglos+year, sigma.formula=~year+ward, family=BB, data=aep) 

Run the code above in your browser using DataLab