Learn R Programming

DiscreteDists (version 1.1.1)

BerG: The Bernoulli-geometric distribution

Description

The function BerG() defines the Bernoulli-geometric distribution, a two parameter distribution, for a gamlss.family object to be used in GAMLSS fitting using the function gamlss().

Usage

BerG(mu.link = "log", sigma.link = "log")

Value

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

Arguments

mu.link

defines the mu.link, with "log" link as the default for the mu parameter.

sigma.link

defines the sigma.link, with "log" link as the default for the sigma.

Author

Hermes Marques, hermes.marques@ufrn.br

Details

The BerG distribution with parameters \(\mu\) and \(\sigma\) has a support 0, 1, 2, ... and mass function given by

\(f(x | \mu, \sigma) = \frac{(1-\mu+\sigma)}{(1+\mu+\sigma)}\) if \(x=0\),

\(f(x | \mu, \sigma) = 4 \mu \frac{(\mu+\sigma-1)^{x-1}}{(\mu+\sigma+1)^{x+1}}\) if \(x=1, 2, ...\),

with \(\mu > 0\), \(\sigma > 0\) and \(\sigma>|\mu-1|\).

References

Bourguignon, M., & de Medeiros, R. M. (2022). A simple and useful regression model for fitting count data. Test, 31(3), 790-827.

See Also

dBerG.

Examples

Run this code
# Example 1
# Generating some random values with
# known mu and sigma
y <- rBerG(n=500, mu=0.75, sigma=0.5)

# Fitting the model
library(gamlss)
mod1 <- gamlss(y~1, family=BerG,
               control=gamlss.control(n.cyc=500, trace=FALSE))

# Extracting the fitted values for mu and sigma
exp(coef(mod1, what="mu"))
exp(coef(mod1, what="sigma"))

# Example 2
# Generating random values under some model

# A function to simulate a data set with Y ~ BerG
gendat <- function(n) {
  x1 <- runif(n)
  x2 <- runif(n)
  x3 <- runif(n)
  x4 <- runif(n)
  mu    <- exp(1 + 1.2*x1 + 0.2*x2)
  sigma <- exp(2 + 1.5*x3 + 1.5*x4)
  y <- rBerG(n=n, mu=mu, sigma=sigma)
  data.frame(y=y, x1=x1, x2=x2, x3=x3, x4=x4)
}

set.seed(16494786)
datos <- gendat(n=500)

mod2 <- gamlss(y~x1+x2, sigma.fo=~x3+x4, family=BerG, data=datos,
               control=gamlss.control(n.cyc=500, trace=TRUE))

summary(mod2)

# Example using the dataset grazing from the bergreg package
# https://github.com/rdmatheus/bergreg

# This example corresponds to example 5.1
# presented by Bourguignon & Medeiros (2022)
# A simple and useful regression model for fitting count data

data("grazing")
hist(grazing$birds)

mod3 <- gamlss(birds ~ when + grazed,
               sigma.fo=~1,
               family=BerG, data=grazing,
               control=gamlss.control(n.cyc=500, trace=TRUE))

summary(mod3)

Run the code above in your browser using DataLab