The Exponential distribution is a continuous probability distribution often used to model the time between independent events that occur at a constant average rate. It is defined by the rate parameter \(\lambda > 0\).
Usage
Exp(rate = 1)
# S4 method for class 'Exp,numeric'
d(distr, x, log = FALSE)
# S4 method for class 'Exp,numeric'
p(distr, q, lower.tail = TRUE, log.p = FALSE)
# S4 method for class 'Exp,numeric'
qn(distr, p, lower.tail = TRUE, log.p = FALSE)
# S4 method for class 'Exp,numeric'
r(distr, n)
# S4 method for class 'Exp'
mean(x)
# S4 method for class 'Exp'
median(x)
# S4 method for class 'Exp'
mode(x)
# S4 method for class 'Exp'
var(x)
# S4 method for class 'Exp'
sd(x)
# S4 method for class 'Exp'
skew(x)
# S4 method for class 'Exp'
kurt(x)
# S4 method for class 'Exp'
entro(x)
# S4 method for class 'Exp'
finf(x)
llexp(x, rate)
# S4 method for class 'Exp,numeric'
ll(distr, x)
eexp(x, type = "mle", ...)
# S4 method for class 'Exp,numeric'
mle(distr, x, na.rm = FALSE)
# S4 method for class 'Exp,numeric'
me(distr, x, na.rm = FALSE)
vexp(rate, type = "mle")
# S4 method for class 'Exp'
avar_mle(distr)
# S4 method for class 'Exp'
avar_me(distr)
Arguments
- rate
numeric. The distribution parameter.
- distr
an object of class
Exp
.- x
For the density function,
x
is a numeric vector of quantiles. For the moments functions,x
is an object of classExp
. 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 density function (PDF) of the Exponential distribution is given by: $$ f(x; \lambda) = \lambda e^{-\lambda x}, \quad x \geq 0 .$$
Examples
# -----------------------------------------------------
# Exp Distribution Example
# -----------------------------------------------------
# Create the distribution
rate <- 5
D <- Exp(rate)
# ------------------
# dpqr Functions
# ------------------
d(D, c(0.3, 2, 10)) # density function
#> [1] 1.115651e+00 2.269996e-04 9.643749e-22
p(D, c(0.3, 2, 10)) # distribution function
#> [1] 0.7768698 0.9999546 1.0000000
qn(D, c(0.4, 0.8)) # inverse distribution function
#> [1] 0.1021651 0.3218876
x <- r(D, 100) # random generator function
# alternative way to use the function
df <- d(D) ; df(x) # df is a function itself
#> [1] 1.89987690 2.36931267 2.87148233 2.74866636 1.81625942 2.14904160
#> [7] 0.28175009 4.56760768 1.09349174 0.55779297 4.35602554 0.18890265
#> [13] 4.62891545 3.88241279 3.74935436 4.79008384 0.02844234 2.61570046
#> [19] 3.53960260 3.63514303 1.85420176 0.34136504 2.15088222 0.04922910
#> [25] 4.10220503 1.70539679 4.23510894 0.51545035 0.32568537 4.26716539
#> [31] 1.82615671 1.48345821 2.23857336 3.83841219 2.00453620 2.29161131
#> [37] 1.51727683 1.46398022 2.60290035 1.53101548 2.67608246 1.41405854
#> [43] 2.19931336 4.18380765 2.90573574 0.28884700 3.86703149 2.86690371
#> [49] 2.07474056 2.81270867 3.62690085 0.83397951 1.70165990 3.94251708
#> [55] 1.19258253 4.01383551 0.62372620 2.43040021 0.40834374 4.10935165
#> [61] 1.22289564 3.74197009 1.35856446 3.50883604 1.55563954 0.71899625
#> [67] 1.36363264 3.03567438 3.50887986 2.24864180 1.86893107 1.79055463
#> [73] 1.23685773 4.31248100 2.69409546 1.32429995 0.90656930 0.51632727
#> [79] 2.01382100 2.04640433 0.81883860 4.77134465 1.69830222 2.57596949
#> [85] 2.50862141 2.49922833 1.24203905 4.40907816 4.78664006 3.93452419
#> [91] 2.90532206 3.43348595 1.47234436 0.26083641 4.66876037 4.80286053
#> [97] 3.07056132 3.51662543 2.99126895 1.80387736
# ------------------
# Moments
# ------------------
mean(D) # Expectation
#> [1] 0.2
median(D) # Median
#> [1] 0.1386294
mode(D) # Mode
#> [1] 0
var(D) # Variance
#> [1] 0.04
sd(D) # Standard Deviation
#> [1] 0.2
skew(D) # Skewness
#> [1] 2
kurt(D) # Excess Kurtosis
#> [1] 6
entro(D) # Entropy
#> [1] -0.6094379
finf(D) # Fisher Information Matrix
#> [1] 0.04
# List of all available moments
mom <- moments(D)
mom$mean # expectation
#> [1] 0.2
# ------------------
# Point Estimation
# ------------------
ll(D, x)
#> [1] 59.8082
llexp(x, rate)
#> [1] 59.8082
eexp(x, type = "mle")
#> $rate
#> [1] 4.943858
#>
eexp(x, type = "me")
#> $rate
#> [1] 4.943858
#>
mle(D, x)
#> $rate
#> [1] 4.943858
#>
me(D, x)
#> $rate
#> [1] 4.943858
#>
e(D, x, type = "mle")
#> $rate
#> [1] 4.943858
#>
mle("exp", x) # the distr argument can be a character
#> $rate
#> [1] 4.943858
#>
# ------------------
# Estimator Variance
# ------------------
vexp(rate, type = "mle")
#> rate
#> 25
vexp(rate, type = "me")
#> rate
#> 25
avar_mle(D)
#> rate
#> 25
avar_me(D)
#> rate
#> 25
v(D, type = "mle")
#> rate
#> 25