The Geometric distribution is a discrete probability distribution that models the number of failures before the first success in a sequence of independent Bernoulli trials, each with success probability \(0 < p \leq 1\).
Usage
Geom(prob = 0.5)
# S4 method for class 'Geom,numeric'
d(distr, x, log = FALSE)
# S4 method for class 'Geom,numeric'
p(distr, q, lower.tail = TRUE, log.p = FALSE)
# S4 method for class 'Geom,numeric'
qn(distr, p, lower.tail = TRUE, log.p = FALSE)
# S4 method for class 'Geom,numeric'
r(distr, n)
# S4 method for class 'Geom'
mean(x)
# S4 method for class 'Geom'
median(x)
# S4 method for class 'Geom'
mode(x)
# S4 method for class 'Geom'
var(x)
# S4 method for class 'Geom'
sd(x)
# S4 method for class 'Geom'
skew(x)
# S4 method for class 'Geom'
kurt(x)
# S4 method for class 'Geom'
entro(x)
# S4 method for class 'Geom'
finf(x)
llgeom(x, prob)
# S4 method for class 'Geom,numeric'
ll(distr, x)
egeom(x, type = "mle", ...)
# S4 method for class 'Geom,numeric'
mle(distr, x, na.rm = FALSE)
# S4 method for class 'Geom,numeric'
me(distr, x, na.rm = FALSE)
vgeom(prob, type = "mle")
# S4 method for class 'Geom'
avar_mle(distr)
# S4 method for class 'Geom'
avar_me(distr)
Arguments
- prob
numeric. Probability of success.
- distr
an object of class
Geom
.- x
For the density function,
x
is a numeric vector of quantiles. For the moments functions,x
is an object of classGeom
. For the log-likelihood and the estimation functions,x
is the sample of observations.- log, log.p
logical. Should the logarithm of the probability be returned?
- q
numeric. Vector of quantiles.
- lower.tail
logical. If TRUE (default), probabilities are \(P(X \leq x)\), otherwise \(P(X > x)\).
- p
numeric. Vector of probabilities.
- n
number of observations. If
length(n) > 1
, the length is taken to be the number required.- type
character, case ignored. The estimator type (mle or me).
- ...
extra arguments.
- na.rm
logical. Should the
NA
values be removed?
Value
Each type of function returns a different type of object:
Distribution Functions: When supplied with one argument (
distr
), thed()
,p()
,q()
,r()
,ll()
functions return the density, cumulative probability, quantile, random sample generator, and log-likelihood functions, respectively. When supplied with both arguments (distr
andx
), they evaluate the aforementioned functions directly.Moments: Returns a numeric, either vector or matrix depending on the moment and the distribution. The
moments()
function returns a list with all the available methods.Estimation: Returns a list, the estimators of the unknown parameters. Note that in distribution families like the binomial, multinomial, and negative binomial, the size is not returned, since it is considered known.
Variance: Returns a named matrix. The asymptotic covariance matrix of the estimator.
Details
The probability mass function (PMF) of the Geometric distribution is: $$ P(X = k) = (1 - p)^k p, \quad k \in \mathbb{N}_0.$$
Examples
# -----------------------------------------------------
# Geom Distribution Example
# -----------------------------------------------------
# Create the distribution
p <- 0.4
D <- Geom(p)
# ------------------
# dpqr Functions
# ------------------
d(D, 0:4) # density function
#> [1] 0.40000 0.24000 0.14400 0.08640 0.05184
p(D, 0:4) # distribution function
#> [1] 0.40000 0.64000 0.78400 0.87040 0.92224
qn(D, c(0.4, 0.8)) # inverse distribution function
#> [1] 0 3
x <- r(D, 100) # random generator function
# alternative way to use the function
df <- d(D) ; df(x) # df is a function itself
#> [1] 0.03110400 0.40000000 0.24000000 0.24000000 0.05184000 0.24000000
#> [7] 0.24000000 0.40000000 0.14400000 0.24000000 0.40000000 0.40000000
#> [13] 0.40000000 0.01866240 0.03110400 0.08640000 0.40000000 0.40000000
#> [19] 0.40000000 0.40000000 0.14400000 0.24000000 0.40000000 0.05184000
#> [25] 0.05184000 0.40000000 0.14400000 0.24000000 0.40000000 0.40000000
#> [31] 0.40000000 0.14400000 0.24000000 0.05184000 0.01866240 0.14400000
#> [37] 0.24000000 0.40000000 0.08640000 0.24000000 0.40000000 0.14400000
#> [43] 0.40000000 0.24000000 0.01119744 0.40000000 0.40000000 0.05184000
#> [49] 0.14400000 0.40000000 0.40000000 0.40000000 0.40000000 0.40000000
#> [55] 0.14400000 0.24000000 0.40000000 0.40000000 0.24000000 0.08640000
#> [61] 0.40000000 0.40000000 0.40000000 0.14400000 0.40000000 0.40000000
#> [67] 0.40000000 0.08640000 0.08640000 0.14400000 0.05184000 0.24000000
#> [73] 0.40000000 0.40000000 0.40000000 0.08640000 0.14400000 0.40000000
#> [79] 0.24000000 0.24000000 0.40000000 0.24000000 0.01866240 0.40000000
#> [85] 0.14400000 0.14400000 0.24000000 0.08640000 0.05184000 0.24000000
#> [91] 0.05184000 0.14400000 0.40000000 0.40000000 0.24000000 0.40000000
#> [97] 0.40000000 0.40000000 0.05184000 0.08640000
# ------------------
# Moments
# ------------------
mean(D) # Expectation
#> [1] 1.5
median(D) # Median
#> [1] 1
mode(D) # Mode
#> [1] 0
var(D) # Variance
#> [1] 3.75
sd(D) # Standard Deviation
#> [1] 1.936492
skew(D) # Skewness
#> [1] 2.065591
kurt(D) # Excess Kurtosis
#> [1] 6.266667
entro(D) # Entropy
#> [1] 1.682529
finf(D) # Fisher Information Matrix
#> [1] 10.41667
# List of all available moments
mom <- moments(D)
mom$mean # expectation
#> [1] 1.5
# ------------------
# Point Estimation
# ------------------
ll(D, x)
#> [1] -164.6771
llgeom(x, p)
#> [1] -164.6771
egeom(x, type = "mle")
#> $prob
#> [1] 0.4115226
#>
egeom(x, type = "me")
#> $prob
#> [1] 0.4115226
#>
mle(D, x)
#> $prob
#> [1] 0.4115226
#>
me(D, x)
#> $prob
#> [1] 0.4115226
#>
e(D, x, type = "mle")
#> $prob
#> [1] 0.4115226
#>
mle("geom", x) # the distr argument can be a character
#> $prob
#> [1] 0.4115226
#>
# ------------------
# Estimator Variance
# ------------------
vgeom(p, type = "mle")
#> prob
#> 0.096
vgeom(p, type = "me")
#> prob
#> 0.096
avar_mle(D)
#> prob
#> 0.096
avar_me(D)
#> prob
#> 0.096
v(D, type = "mle")
#> prob
#> 0.096