Package 'mcauchyd'

Title: Multivariate Cauchy Distribution; Kullback-Leibler Divergence
Description: Distance between multivariate Cauchy distributions, as presented by N. Bouhlel and D. Rousseau (2022) <doi:10.3390/e24060838>. Manipulation of multivariate Cauchy distributions.
Authors: Pierre Santagostini [aut, cre], Nizar Bouhlel [aut]
Maintainer: Pierre Santagostini <[email protected]>
License: GPL (>= 3)
Version: 1.3.3
Built: 2024-12-23 13:40:02 UTC
Source: CRAN

Help Index


Tools for Multivariate Cauchy Distributions

Description

This package provides tools for multivariate Cauchy distributions (MCD):

  • Calculation of distances/divergences between MCD:

  • Tools for MCD:

Author(s)

Pierre Santagostini [email protected], Nizar Bouhlel [email protected]

References

N. Bouhlel, D. Rousseau, A Generic Formula and Some Special Cases for the Kullback–Leibler Divergence between Central Multivariate Cauchy Distributions. Entropy, 24, 838, July 2022. doi:10.3390/e24060838 #' @keywords internal

See Also

Useful links:


Contour Plot of the Bivariate Cauchy Density

Description

Draws the contour plot of the probability density of the multivariate Cauchy distribution with 2 variables with location parameter mu and scatter matrix Sigma.

Usage

contourmcd(mu, Sigma,
                   xlim = c(mu[1] + c(-10, 10)*Sigma[1, 1]),
                   ylim = c(mu[2] + c(-10, 10)*Sigma[2, 2]),
                   zlim = NULL, npt = 30, nx = npt, ny = npt,
                   main = "Multivariate Cauchy density",
                   sub = NULL, nlevels = 10,
                   levels = pretty(zlim, nlevels), tol = 1e-6, ...)

Arguments

mu

length 2 numeric vector.

Sigma

symmetric, positive-definite square matrix of order 2. The scatter matrix.

xlim, ylim

x-and y- limits.

zlim

z- limits. If NULL, it is the range of the values of the density on the x and y values within xlim and ylim.

npt

number of points for the discretisation.

nx, ny

number of points for the discretisation among the x- and y- axes.

main, sub

main and sub title, as for title.

nlevels, levels

arguments to be passed to the contour function.

tol

tolerance (relative to largest variance) for numerical lack of positive-definiteness in Sigma, for the estimation of the density. see dmcd.

...

additional arguments to plot.window, title, Axis and box, typically graphical parameters such as cex.axis.

Value

Returns invisibly the probability density function.

Author(s)

Pierre Santagostini, Nizar Bouhlel

References

N. Bouhlel, D. Rousseau, A Generic Formula and Some Special Cases for the Kullback–Leibler Divergence between Central Multivariate Cauchy Distributions. Entropy, 24, 838, July 2022. doi:10.3390/e24060838

See Also

dmcd: probability density of a multivariate Cauchy density

plotmcd: 3D plot of a bivariate Cauchy density.

Examples

mu <- c(1, 4)
Sigma <- matrix(c(0.8, 0.2, 0.2, 0.2), nrow = 2)
contourmcd(mu, Sigma)

Density of a Multivariate Cauchy Distribution

Description

Density of the multivariate (pp variables) Cauchy distribution (MCD) with location parameter mu and scatter matrix Sigma.

Usage

dmcd(x, mu, Sigma, tol = 1e-6)

Arguments

x

length pp numeric vector.

mu

length pp numeric vector. The location parameter.

Sigma

symmetric, positive-definite square matrix of order pp. The scatter matrix.

tol

tolerance (relative to largest eigenvalue) for numerical lack of positive-definiteness in Sigma.

Details

The density function of a multivariate Cauchy distribution is given by:

f(xμ,Σ)=Γ(1+p2)πp/2Γ(12)Σ12[1+(xμ)TΣ1(xμ)]1+p2\displaystyle{ f(\mathbf{x}|\boldsymbol{\mu}, \Sigma) = \frac{\Gamma\left(\frac{1+p}{2}\right)}{\pi^{p/2} \Gamma\left(\frac{1}{2}\right) |\Sigma|^\frac{1}{2} \left[ 1 + (\mathbf{x}-\boldsymbol{\mu})^T \Sigma^{-1} (\mathbf{x}-\boldsymbol{\mu}) \right]^\frac{1+p}{2}} }

Value

The value of the density.

Author(s)

Pierre Santagostini, Nizar Bouhlel

See Also

rmcd: random generation from a MCD.

plotmcd, contourmcd: plot of a bivariate Cauchy density.

Examples

mu <- c(0, 1, 4)
sigma <- matrix(c(1, 0.6, 0.2, 0.6, 1, 0.3, 0.2, 0.3, 1), nrow = 3)
dmcd(c(0, 1, 4), mu, sigma)
dmcd(c(1, 2, 3), mu, sigma)

Kullback-Leibler Divergence between Centered Multivariate Cauchy Distributions

Description

Computes the Kullback-Leibler divergence between two random vectors distributed according to multivariate Cauchy distributions (MCD) with zero location vector.

Usage

kldcauchy(Sigma1, Sigma2, eps = 1e-06)

Arguments

Sigma1

symmetric, positive-definite matrix. The scatter matrix of the first distribution.

Sigma2

symmetric, positive-definite matrix. The scatter matrix of the second distribution.

eps

numeric. Precision for the computation of the partial derivative of the Lauricella DD-hypergeometric function (see Details). Default: 1e-06.

Details

Given X1X_1, a random vector of Rp\mathbb{R}^p distributed according to the MCD with parameters (0,Σ1)(0, \Sigma_1) and X2X_2, a random vector of Rp\mathbb{R}^p distributed according to the MCD with parameters (0,Σ2)(0, \Sigma_2).

Let λ1,,λp\lambda_1, \dots, \lambda_p the eigenvalues of the square matrix Σ1Σ21\Sigma_1 \Sigma_2^{-1} sorted in increasing order:

λ1<<λp1<λp\lambda_1 < \dots < \lambda_{p-1} < \lambda_p

Depending on the values of these eigenvalues, the computation of the Kullback-Leibler divergence of X1X_1 from X2X_2 is given by:

  • if λ1<1\lambda_1 < 1 and λp>1\lambda_p > 1:
    KL(X1X2)=12lni=1pλi+1+p2(lnλp\displaystyle{ KL(X_1||X_2) = -\frac{1}{2} \ln{ \prod_{i=1}^p{\lambda_i}} + \frac{1+p}{2} \bigg( \ln{\lambda_p} }
    a{FD(p)(a,12,,12,a+12p;a+1+p2;1λ1λp,,1λp1λp,11λp)}a=0)\displaystyle{ - \frac{\partial}{\partial a} \bigg\{ F_D^{(p)} \bigg( a, \underbrace{\frac{1}{2}, \dots, \frac{1}{2}, a + \frac{1}{2}}_p ; a + \frac{1+p}{2} ; 1 - \frac{\lambda_1}{\lambda_p}, \dots, 1 - \frac{\lambda_{p-1}}{\lambda_p}, 1 - \frac{1}{\lambda_p} \bigg) \bigg\}\bigg|_{a=0} \bigg) }

  • if λp<1\lambda_p < 1:
    KL(X1X2)=12lni=1pλi\displaystyle{ KL(X_1||X_2) = -\frac{1}{2} \ln{ \prod_{i=1}^p{\lambda_i}} } 1+p2a{FD(p)(a,12,,12p;a+1+p2;1λ1,,1λp)}a=0\displaystyle{ - \frac{1+p}{2} \frac{\partial}{\partial a} \bigg\{ F_D^{(p)} \bigg( a, \underbrace{\frac{1}{2}, \dots, \frac{1}{2}}_p ; a + \frac{1+p}{2} ; 1 - \lambda_1, \dots, 1 - \lambda_p \bigg) \bigg\}\bigg|_{a=0} }

  • if λ1>1\lambda_1 > 1:
    KL(X1X2)=12lni=1pλi1+p2i=1p1λi\displaystyle{ KL(X_1||X_2) = -\frac{1}{2} \ln{ \prod_{i=1}^p{\lambda_i}} - \frac{1+p}{2} \prod_{i=1}^p\frac{1}{\sqrt{\lambda_i}} }
    ×a{FD(p)(1+p2,12,,12p;a+1+p2;11λ1,,11λp)}a=0\displaystyle{ \times \frac{\partial}{\partial a} \bigg\{ F_D^{(p)} \bigg( \frac{1+p}{2}, \underbrace{\frac{1}{2}, \dots, \frac{1}{2}}_p ; a + \frac{1+p}{2} ; 1 - \frac{1}{\lambda_1}, \dots, 1 - \frac{1}{\lambda_p} \bigg) \bigg\}\bigg|_{a=0} }

where FD(p)F_D^{(p)} is the Lauricella DD-hypergeometric function defined for pp variables:

FD(p)(a;b1,...,bp;g;x1,...,xp)=m10...mp0(a)m1+...+mp(b1)m1...(bp)mp(g)m1+...+mpx1m1m1!...xpmpmp!\displaystyle{ F_D^{(p)}\left(a; b_1, ..., b_p; g; x_1, ..., x_p\right) = \sum\limits_{m_1 \geq 0} ... \sum\limits_{m_p \geq 0}{ \frac{ (a)_{m_1+...+m_p}(b_1)_{m_1} ... (b_p)_{m_p} }{ (g)_{m_1+...+m_p} } \frac{x_1^{m_1}}{m_1!} ... \frac{x_p^{m_p}}{m_p!} } }

Value

A numeric value: the Kullback-Leibler divergence between the two distributions, with two attributes attr(, "epsilon") (precision of the partial derivative of the Lauricella DD-hypergeometric function,see Details) and attr(, "k") (number of iterations).

Author(s)

Pierre Santagostini, Nizar Bouhlel

References

N. Bouhlel, D. Rousseau, A Generic Formula and Some Special Cases for the Kullback–Leibler Divergence between Central Multivariate Cauchy Distributions. Entropy, 24, 838, July 2022. doi:10.3390/e24060838

Examples

Sigma1 <- matrix(c(1, 0.6, 0.2, 0.6, 1, 0.3, 0.2, 0.3, 1), nrow = 3)
Sigma2 <- matrix(c(1, 0.3, 0.1, 0.3, 1, 0.4, 0.1, 0.4, 1), nrow = 3)
kldcauchy(Sigma1, Sigma2)
kldcauchy(Sigma2, Sigma1)

Sigma1 <- matrix(c(0.5, 0, 0, 0, 0.4, 0, 0, 0, 0.3), nrow = 3)
Sigma2 <- diag(1, 3)
# Case when all eigenvalues of Sigma1 %*% solve(Sigma2) are < 1
kldcauchy(Sigma1, Sigma2)
# Case when all eigenvalues of Sigma1 %*% solve(Sigma2) are > 1
kldcauchy(Sigma2, Sigma1)

Logarithm of the Pochhammer Symbol

Description

Computes the logarithm of the Pochhammer symbol.

Usage

lnpochhammer(x, n)

Arguments

x

numeric.

n

positive integer.

Details

The Pochhammer symbol is given by:

(x)n=Γ(x+n)Γ(x)=x(x+1)...(x+n1)\displaystyle{ (x)_n = \frac{\Gamma(x+n)}{\Gamma(x)} = x (x+1) ... (x+n-1) }

So, if n>0n > 0:

log((x)n)=log(x)+log(x+1)+...+log(x+n1)\displaystyle{ log\left((x)_n\right) = log(x) + log(x+1) + ... + log(x+n-1) }

If n=0n = 0, log((x)n)=log(1)=0\displaystyle{ log\left((x)_n\right) = log(1) = 0}

Value

Numeric value. The logarithm of the Pochhammer symbol.

Author(s)

Pierre Santagostini, Nizar Bouhlel

See Also

pochhammer()

Examples

lnpochhammer(2, 0)
lnpochhammer(2, 1)
lnpochhammer(2, 3)

Plot of the Bivariate Cauchy Density

Description

Plots the probability density of the multivariate Cauchy distribution with 2 variables with location parameter mu and scatter matrix Sigma.

Usage

plotmcd(mu, Sigma, xlim = c(mu[1] + c(-10, 10)*Sigma[1, 1]),
                ylim = c(mu[2] + c(-10, 10)*Sigma[2, 2]), n = 101,
                xvals = NULL, yvals = NULL, xlab = "x", ylab = "y",
                zlab = "f(x,y)", col = "gray", tol = 1e-6, ...)

Arguments

mu

length 2 numeric vector.

Sigma

symmetric, positive-definite square matrix of order 2. The scatter matrix.

xlim, ylim

x-and y- limits.

n

A one or two element vector giving the number of steps in the x and y grid, passed to plot3d.function.

xvals, yvals

The values at which to evaluate x and y. If used, xlim and/or ylim are ignored.

xlab, ylab, zlab

The axis labels.

col

The color to use for the plot. See plot3d.function.

tol

tolerance (relative to largest variance) for numerical lack of positive-definiteness in Sigma, for the estimation of the density. see dmcd.

...

Additional arguments to pass to plot3d.function.

Value

Returns invisibly the probability density function.

Author(s)

Pierre Santagostini, Nizar Bouhlel

References

N. Bouhlel, D. Rousseau, A Generic Formula and Some Special Cases for the Kullback–Leibler Divergence between Central Multivariate Cauchy Distributions. Entropy, 24, 838, July 2022. doi:10.3390/e24060838

See Also

dmcd: probability density of a multivariate Cauchy density

contourmcd: contour plot of a bivariate Cauchy density.

plot3d.function: plot a function of two variables.

Examples

mu <- c(1, 4)
Sigma <- matrix(c(0.8, 0.2, 0.2, 0.2), nrow = 2)
plotmcd(mu, Sigma)

Pochhammer Symbol

Description

Computes the Pochhammer symbol.

Usage

pochhammer(x, n)

Arguments

x

numeric.

n

positive integer.

Details

The Pochhammer symbol is given by:

(x)n=Γ(x+n)Γ(x)=x(x+1)...(x+n1)\displaystyle{ (x)_n = \frac{\Gamma(x+n)}{\Gamma(x)} = x (x+1) ... (x+n-1) }

Value

Numeric value. The value of the Pochhammer symbol.

Author(s)

Pierre Santagostini, Nizar Bouhlel

Examples

pochhammer(2, 0)
pochhammer(2, 1)
pochhammer(2, 3)

Simulate from a Multivariate Cauchy Distribution

Description

Produces one or more samples from the multivariate (pp variables) Cauchy distribution (MCD) with location parameter mu and scatter matrix Sigma.

Usage

rmcd(n, mu, Sigma, tol = 1e-6)

Arguments

n

integer. Number of observations.

mu

length pp numeric vector. The location parameter.

Sigma

symmetric, positive-definite square matrix of order pp. The scatter matrix.

tol

tolerance for numerical lack of positive-definiteness in Sigma (for mvrnorm, see Details).

Details

A sample from a MCD with parameters μ\boldsymbol{\mu} and Σ\Sigma can be generated using:

X=μ+Yu\displaystyle{\mathbf{X} = \boldsymbol{\mu} + \frac{\mathbf{Y}}{\sqrt{u}}}

where Y\mathbf{Y} is a random vector distributed among a centered Gaussian density with covariance matrix Σ\Sigma (generated using mvrnorm) and uu is distributed among a Chi-squared distribution with 1 degree of freedom.

Value

A matrix with pp columns and nn rows.

Author(s)

Pierre Santagostini, Nizar Bouhlel

See Also

dmcd: probability density of a MCD.

Examples

mu <- c(0, 1, 4)
sigma <- matrix(c(1, 0.6, 0.2, 0.6, 1, 0.3, 0.2, 0.3, 1), nrow = 3)
x <- rmcd(100, mu, sigma)
x
apply(x, 2, median)