bgeom: Beta-Geometric

bgeomR Documentation

Beta-Geometric

Description

Probability density function (PDF), cumulative density function (CDF), quantile function, and random variate generation of the Beta-Geometric distribution (BGD). Herein, we consider the unshifted sBGD PDF (dbgeom):

f(x | \alpha,\beta) = \frac{B(\alpha + 1, \beta + x - 1)}{B(\alpha,\beta)}

for x = 1,2,..., and 0 < p \leq 1 and the shifted PDF (dbgeom2):

f(x | \alpha,\beta) = \frac{B(\alpha + 1, \beta + x)}{B(\alpha,\beta)}

with parameters \alpha (shape1) and \beta (shape1) as given in references (1-2), for x = 0,1,2,..., and 0 < p \leq 1, where B(.) is the beta(a,b) function:

B(a,b)= \frac{\Gamma(a)\Gamma(b)}{\Gamma(a+b)}

Usage

dbgeom(x, shape1, shape2, log = FALSE)

pbgeom(q, shape1, shape2, lower.tail = TRUE, log.p = FALSE)

qbgeom(p, shape1, shape2, qmax = 10000, lower.tail = TRUE, log.p = FALSE)

rbgeom(n, shape1, shape2)

dbgeom2(x, shape1, shape2, log = FALSE)

pbgeom2(q, shape1, shape2, lower.tail = TRUE, log.p = FALSE)

qbgeom2(p, shape1, shape2, qmax = 10000, lower.tail = TRUE, log.p = FALSE)

rbgeom2(n, shape1, shape2)

Arguments

x, q

A numeric vector.

shape1, shape2

shape parameters to pass to Beta distribution, Beta.

lower.tail

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

log.p, log

logical; if TRUE, probabilities/densities p are returned as log(p).

p

A vector of probabilities.

qmax

The maximum expected quantile. An argument to be used with qbgeom function.

n

The number of observations

Details

Details about the BGD can be found in reference (1-3).

## The Cumulative Distribution Function (CDF) The CDF is computed as:

F(x|\alpha, \beta) = \Sigma_{i=0}^{x} f(x |\alpha, \beta)

## The quantile function

The quantile function is the inverse of the CDF, i.e., F^{-1}. Since there is not analytical function for the CDF, we compute the quantile \hat{q}_i for the probability value p_i as the argument x_i that minimizes the difference 1/2 (F(x_i|\alpha, \beta) - p_i), formally:

\hat{q}_i = \underset{x \in \mathbb{Z}^+}{\operatorname{Min}} \left \{ \frac{1}{2} (F(x_i|\alpha, \beta) - p_i)^2 \: | \: F(x_i|\alpha, \beta) \leq p_i \right \}

## Random variate generation (random sampling)

To generate a random variate X \sim \: F(x|\alpha, \beta), first, we must generate a random variate \pi (probabilities): \pi \sim \: B_x(x|\alpha, \beta) (rbeta). Hence, we can generate X \sim \: F(x|\alpha, \beta) as:

X = G^{-1}(R_B(n|\alpha, \beta) | \pi)

where R_B(n|\alpha, \beta) stands for the function to generate random variate from Beta distribution: rbeta and G^{-1}(p|\pi) the quantile of the geometric distribution.

Value

The PDF, CDF, quantile and random generation functions for BGD.

Author(s)

Robersy Sanchez (https://genomaths.com).

References

1. Weinberg, P. & Gladen, B.C. (1986). The Beta-Geometric distribution applied to comparative fecundability studies. Biometrics, 42, 547-560. 2. Gupta, A. K., Nadarajah, S (2004). The Beta-Geometric Distribution. In Handbook of Beta Distribution and Its Applications Statistics. 3. Paul, Sudhir R. (2005) "Testing Goodness Of Fit Of The Geometric Distribution: An Application To Human Fecundability Data," Journal of Modern Applied Statistical Methods: Vol. 4 : Iss. 2 , Article 8. DOI: 10.22237/jmasm/1130803620

Examples

## Generate random variates from the unshifted Beta-Geometric
set.seed(122)
x1 <- rbgeom(1e3, shape1 = 2, shape2 = 40)
summary(x1)

## The nonlinear fit 
cdf <- fit_cdf(x1, distNames = "Beta-Geometric I",
              plot = T)
cfs <- coefs(cdf)
cdf

## The histogram with the density (PDF) curve.
hist(x1, 600, freq = FALSE, xlim = c(0, 50),
     panel.first={points(0, 0, pch=16, cex=1e6, col="grey95")
         grid(col="white", lty = 1)})
x <- round(seq(min(x1), max(x1), by = 1))
lines(x, dbgeom(x, shape1 = 2, shape2 = 40), col = "red")
lines(x, dbgeom(x, shape1 = cfs[1], shape2 = cfs[2]), col = "dodgerblue")

## Kolmogorov-Smirnov tests can fail
set.seed(122)
x2 <- rbgeom(1e3, shape1 = 2, shape2 = 30)
summary(x2)

cdf <- fit_cdf(x2, distNames = "Beta-Geometric I",
              plot = TRUE)
cdf

## Bootstrap test for Goodness of fit (GoF)
## using Kolmogorov-Smirnov (for the sake of reducing compuational time,
## the sample.size was set small, default is NULL).
mcgoftest(x2, cdf, stat = "ks", sample.size = 100)


## Generate random variates from the shifted Beta-Geometric
set.seed(122)
x1 <- rbgeom2(1e3, shape1 = 2, shape2 = 40)
summary(x1)

## The nonlinear fit 
cdf_sf <- fit_cdf(x1, distNames = "Beta-Geometric II",
            plot = T)
cdf_sf


genomaths/usefr documentation built on June 10, 2025, 9:18 p.m.