BB {gamlss.dist} | R Documentation |
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()
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)
mu.link |
Defines the |
sigma.link |
Defines the |
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 |
Definition file for beta binomial distribution.
f(y|mu,sigma)=[Gamma(n+1)/Gamma(y+1)/Gamma(n-y+1)]*[Gamma(y+mu/sigma)*Gamma(1/sigma)*Gamma[n+(1-mu)/sigma-y]]/[Gamma(n+(1/sigma)) * Gamma(mu/sigma) * Gamma((1-mu)/sigma)]
for y=0,1,2,…,n, 0<μ<1 and σ>0. For μ=0.5 and σ=0.5 the distribution is uniform.
Returns a gamlss.family
object which can be used to fit a Beta Binomial distribution in the gamlss()
function.
The functions pBB
and qBB
are calculated using a laborious procedure so they are relatively slow.
The response variable should be a matrix containing two columns, the first with the count of successes and the second with the count of failures.
The parameter mu
represents a probability parameter with limits 0 < mu <1.
n*mu is the mean of the distribution where n is the binomial denominator.
[n mu (1-mu)[1+(n-1) sigma/(sigma+1)]\]^0.5 is the standard deviation of the
Beta Binomial distribution. Hence sigma is a dispersion type parameter
Mikis Stasinopoulos mikis.stasinopoulos@gamlss.org, Bob Rigby and Kalliope Akantziliotou
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.
Stasinopoulos D. M., Rigby R.A. and Akantziliotou C. (2006) Instructions on how to use the GAMLSS package in R. Accompanying documentation in the current GAMLSS help files, (see also http://www.gamlss.org/).
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, http://www.jstatsoft.org/v23/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.
# 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)