Learn R Programming

joker (version 0.14.2)

Cauchy: Cauchy Distribution

Description

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 Cauchy,numeric d(distr, x, log = FALSE)

# S4 method for Cauchy,numeric p(distr, q, lower.tail = TRUE, log.p = FALSE)

# S4 method for Cauchy,numeric qn(distr, p, lower.tail = TRUE, log.p = FALSE)

# S4 method for Cauchy,numeric r(distr, n)

# S4 method for Cauchy mean(x)

# S4 method for Cauchy median(x)

# S4 method for Cauchy mode(x)

# S4 method for Cauchy var(x)

# S4 method for Cauchy sd(x)

# S4 method for Cauchy skew(x)

# S4 method for Cauchy kurt(x)

# S4 method for Cauchy entro(x)

# S4 method for Cauchy finf(x)

llcauchy(x, location, scale)

# S4 method for Cauchy,numeric ll(distr, x)

ecauchy(x, type = "mle", ...)

# S4 method for 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 Cauchy,numeric me(distr, x, na.rm = FALSE)

vcauchy(location, scale, type = "mle")

# S4 method for Cauchy avar_mle(distr)

Value

Each type of function returns a different type of object:

  • Distribution Functions: When supplied with one argument (distr), the d(), 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 and x), 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.

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 class Cauchy. 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?

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.

See Also

Functions from the stats package: dcauchy(), pcauchy(), qcauchy(), rcauchy()

Examples

Run this code
# -----------------------------------------------------
# Cauchy Distribution Example
# -----------------------------------------------------

# Create the distribution
x0 <- 3 ; scale <- 5
D <- Cauchy(x0, scale)

# ------------------
# dpqr Functions
# ------------------

d(D, c(-5, 3, 10)) # density function
p(D, c(-5, 3, 10)) # distribution function
qn(D, c(0.4, 0.8)) # inverse distribution function
x <- r(D, 100) # random generator function

# alternative way to use the function
df <- d(D) ; df(x) # df is a function itself

# ------------------
# Moments
# ------------------

median(D) # Median
mode(D) # Mode
entro(D) # Entropy
finf(D) # Fisher Information Matrix

# ------------------
# Point Estimation
# ------------------

ll(D, x)
llcauchy(x, x0, scale)

ecauchy(x, type = "mle")
ecauchy(x, type = "me")

mle(D, x)
me(D, x)
e(D, x, type = "mle")

mle("cauchy", x) # the distr argument can be a character

# ------------------
# Estimator Variance
# ------------------

vcauchy(x0, scale, type = "mle")
avar_mle(D)
v(D, type = "mle")

Run the code above in your browser using DataLab