The Cauchy distribution is an absolute continuous probability distribution characterized by its location parameter \(x_0\) and scale parameter \(\gamma > 0\).
Usage
Cauchy(location = 0, scale = 1)
# S4 method for class 'Cauchy,numeric'
d(distr, x, log = FALSE)
# S4 method for class 'Cauchy,numeric'
p(distr, q, lower.tail = TRUE, log.p = FALSE)
# S4 method for class 'Cauchy,numeric'
qn(distr, p, lower.tail = TRUE, log.p = FALSE)
# S4 method for class 'Cauchy,numeric'
r(distr, n)
# S4 method for class 'Cauchy'
mean(x)
# S4 method for class 'Cauchy'
median(x)
# S4 method for class 'Cauchy'
mode(x)
# S4 method for class 'Cauchy'
var(x)
# S4 method for class 'Cauchy'
sd(x)
# S4 method for class 'Cauchy'
skew(x)
# S4 method for class 'Cauchy'
kurt(x)
# S4 method for class 'Cauchy'
entro(x)
# S4 method for class 'Cauchy'
finf(x)
llcauchy(x, location, scale)
# S4 method for class 'Cauchy,numeric'
ll(distr, x)
ecauchy(x, type = "mle", ...)
# S4 method for class 'Cauchy,numeric'
mle(
distr,
x,
par0 = "me",
method = "L-BFGS-B",
lower = c(-Inf, 1e-05),
upper = c(Inf, Inf),
na.rm = FALSE
)
# S4 method for class 'Cauchy,numeric'
me(distr, x, na.rm = FALSE)
vcauchy(location, scale, type = "mle")
# S4 method for class 'Cauchy'
avar_mle(distr)
Arguments
- location, scale
numeric. Location and scale parameters.
- distr
an object of class
Cauchy
.- x
For the density function,
x
is a numeric vector of quantiles. For the moments functions,x
is an object of classCauchy
. 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.
- par0, method, lower, upper
arguments passed to optim for the mle optimization.
- 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 Cauchy distribution is given by: $$ f(x; x_0, \gamma) = \frac{1}{\pi \gamma \left[1 + \left(\frac{x - x_0}{\gamma}\right)^2\right]}.$$
The MLE of the Cauchy distribution parameters is not available in closed form
and has to be approximated numerically. This is done with optim()
.
The default method used is the L-BFGS-B method with lower bounds
c(-Inf, 1e-5)
and upper bounds c(Inf, Inf)
. The par0
argument can
either be a numeric (both elements satisfying lower <= par0 <= upper
)
or a character specifying the closed-form estimator to be used as
initialization for the algorithm ("me"
- the default value).
Note that the me()
estimator for the Cauchy distribution is not a
moment estimator; it utilizes the sample median instead of the sample
mean.
Examples
# -----------------------------------------------------
# Cauchy Distribution Example
# -----------------------------------------------------
# Create the distribution
x0 <- 3 ; scale <- 5
D <- Cauchy(x0, scale)
# ------------------
# dpqr Functions
# ------------------
d(D, c(-5, 3, 10)) # density function
#> [1] 0.01788258 0.06366198 0.02150742
p(D, c(-5, 3, 10)) # distribution function
#> [1] 0.1778077 0.5000000 0.8025685
qn(D, c(0.4, 0.8)) # inverse distribution function
#> [1] 1.375402 9.881910
x <- r(D, 100) # random generator function
# alternative way to use the function
df <- d(D) ; df(x) # df is a function itself
#> [1] 4.495215e-02 5.988423e-02 6.346378e-02 2.748064e-02 6.312939e-02
#> [6] 7.761154e-04 4.777694e-02 6.155906e-02 1.043303e-03 9.013950e-03
#> [11] 5.483888e-03 3.043508e-02 3.696916e-04 6.332635e-06 6.352595e-02
#> [16] 6.255582e-02 1.372709e-03 6.344792e-02 1.247492e-03 1.153462e-02
#> [21] 6.218878e-06 6.022580e-02 6.309034e-02 1.287954e-02 6.351241e-02
#> [26] 8.168228e-04 3.404109e-02 2.569378e-03 3.749158e-02 1.139680e-02
#> [31] 8.769975e-03 1.161357e-02 4.959531e-02 1.168138e-03 4.555847e-02
#> [36] 6.294724e-02 2.457766e-02 6.327364e-02 9.530000e-03 4.680007e-02
#> [41] 1.201784e-02 2.362168e-02 5.372659e-02 2.551076e-02 4.659739e-02
#> [46] 5.639920e-02 4.557955e-03 5.065729e-02 5.987046e-02 1.749810e-02
#> [51] 1.302616e-02 6.361489e-02 2.953371e-03 2.683870e-02 4.716099e-03
#> [56] 1.611663e-03 4.949695e-02 6.250720e-02 1.912409e-02 1.302444e-04
#> [61] 6.182647e-02 4.940659e-02 6.105330e-02 3.425083e-02 5.987893e-02
#> [66] 5.310415e-02 4.349224e-02 2.190097e-03 2.858259e-02 1.317051e-02
#> [71] 6.347343e-02 5.078716e-03 1.140682e-02 1.352965e-02 5.156731e-02
#> [76] 1.842270e-02 5.201057e-02 4.865491e-02 5.521374e-02 3.428899e-02
#> [81] 3.806395e-03 5.733399e-02 1.403388e-02 3.400095e-02 2.806059e-02
#> [86] 5.093214e-02 6.329526e-02 5.596420e-02 6.310795e-02 1.281236e-02
#> [91] 6.170678e-02 4.523291e-04 2.302247e-02 7.343031e-03 5.488240e-02
#> [96] 9.956255e-03 2.429431e-02 7.572407e-03 6.292009e-02 1.578130e-02
# ------------------
# Moments
# ------------------
median(D) # Median
#> [1] 3
mode(D) # Mode
#> [1] 3
entro(D) # Entropy
#> [1] 4.140462
finf(D) # Fisher Information Matrix
#> location scale
#> location 0.02 0.00
#> scale 0.00 0.02
# ------------------
# Point Estimation
# ------------------
ll(D, x)
#> [1] -413.4715
llcauchy(x, x0, scale)
#> [1] -413.4715
ecauchy(x, type = "mle")
#> $location
#> [1] 1.652551
#>
#> $scale
#> [1] 4.804924
#>
ecauchy(x, type = "me")
#> $location
#> [1] 1.940115
#>
#> $scale
#> [1] 4.525654
#>
mle(D, x)
#> $location
#> [1] 1.652551
#>
#> $scale
#> [1] 4.804924
#>
me(D, x)
#> $location
#> [1] 1.940115
#>
#> $scale
#> [1] 4.525654
#>
e(D, x, type = "mle")
#> $location
#> [1] 1.652551
#>
#> $scale
#> [1] 4.804924
#>
mle("cauchy", x) # the distr argument can be a character
#> $location
#> [1] 1.652551
#>
#> $scale
#> [1] 4.804924
#>
# ------------------
# Estimator Variance
# ------------------
vcauchy(x0, scale, type = "mle")
#> location scale
#> location 50 0
#> scale 0 50
avar_mle(D)
#> location scale
#> location 50 0
#> scale 0 50
v(D, type = "mle")
#> location scale
#> location 50 0
#> scale 0 50