Title: | Multivariate t Distribution |
---|---|
Description: | Distance between multivariate t distributions, as presented by N. Bouhlel and D. Rousseau (2023) <doi:10.1109/LSP.2023.3324594>. |
Authors: | Pierre Santagostini [aut, cre], Nizar Bouhlel [aut] |
Maintainer: | Pierre Santagostini <[email protected]> |
License: | GPL (>= 3) |
Version: | 1.1.2 |
Built: | 2024-12-23 13:40:58 UTC |
Source: | CRAN |
DistributionsThis package provides tools for multivariate distributions (MTD):
Calculation of distances/divergences between MTD:
Renyi divergence, Bhattacharyya distance, Hellinger distance: diststudent
Kullback-Leibler divergence: kldstudent
Tools for MTD:
Probability density: dmtd
Simulation from a MTD: rmtd
Plot of the density of a MTD with 2 variables: plotmtd
, contourmtd
Pierre Santagostini [email protected], Nizar Bouhlel [email protected]
S. Kotz and Saralees Nadarajah (2004), Multivariate Distributions and Their Applications, Cambridge University Press.
N. Bouhlel and D. Rousseau (2023), Exact Rényi and Kullback-Leibler Divergences Between Multivariate t-Distributions, IEEE Signal Processing Letters. doi:10.1109/LSP.2023.3324594 #' @keywords internal
Useful links:
Report bugs at https://forgemia.inra.fr/imhorphen/mstudentd/-/issues
DensityDraws the contour plot of the probability density of the multivariate distribution with 2 variables
with location parameter
mu
and scatter matrix Sigma
.
contourmtd(nu, 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 t density", sub = NULL, nlevels = 10, levels = pretty(zlim, nlevels), tol = 1e-6, ...)
contourmtd(nu, 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 t density", sub = NULL, nlevels = 10, levels = pretty(zlim, nlevels), tol = 1e-6, ...)
nu |
numeric. The degrees of freedom. |
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 |
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 |
nlevels , levels
|
arguments to be passed to the |
tol |
tolerance (relative to largest variance) for numerical lack of positive-definiteness in Sigma, for the estimation of the density. see |
... |
additional arguments to |
Returns invisibly the probability density function.
Pierre Santagostini, Nizar Bouhlel
S. Kotz and Saralees Nadarajah (2004), Multivariate Distributions and Their Applications, Cambridge University Press.
dmtd
: probability density of a multivariate density
plotmtd
: 3D plot of a bivariate density.
nu <- 1 mu <- c(1, 4) Sigma <- matrix(c(0.8, 0.2, 0.2, 0.2), nrow = 2) contourmtd(nu, mu, Sigma)
nu <- 1 mu <- c(1, 4) Sigma <- matrix(c(0.8, 0.2, 0.2, 0.2), nrow = 2) contourmtd(nu, mu, Sigma)
DistributionsComputes the distance or divergence (Renyi divergence, Bhattacharyya distance or Hellinger distance) between two random vectors distributed according to multivariate $t$ distributions (MTD) with zero mean vector.
diststudent(nu1, Sigma1, nu2, Sigma2, dist = c("renyi", "bhattacharyya", "hellinger"), bet = NULL, eps = 1e-06)
diststudent(nu1, Sigma1, nu2, Sigma2, dist = c("renyi", "bhattacharyya", "hellinger"), bet = NULL, eps = 1e-06)
nu1 |
numéric. The degrees of freedom of the first distribution. |
Sigma1 |
symmetric, positive-definite matrix. The correlation matrix of the first distribution. |
nu2 |
numéric. The degrees of freedom of the second distribution. |
Sigma2 |
symmetric, positive-definite matrix. The correlation matrix of the second distribution. |
dist |
character. The distance or divergence used.
One of |
bet |
numeric, positive and not equal to 1. Order of the Renyi divergence.
Ignored if |
eps |
numeric. Precision for the computation of the partial derivative of the Lauricella |
Given , a random vector of
distributed according to the MTD
with parameters
and
, a random vector of
distributed according to the MTD
with parameters
.
Let ,
and
the eigenvalues of the square matrix
sorted in increasing order:
The Renyi divergence between and
is:
with given by:
If :
If :
If and
:
where is the Lauricella
-hypergeometric function defined for
variables:
Its computation uses the lauricella
function.
The Bhattacharyya distance is given by:
And the Hellinger distance is given by:
A numeric value: the Renyi divergence between the two distributions,
with two attributes attr(, "epsilon")
(precision of the result of the Lauricella -hypergeometric function,see Details)
and
attr(, "k")
(number of iterations).
Pierre Santagostini, Nizar Bouhlel
N. Bouhlel and D. Rousseau (2023), Exact Rényi and Kullback-Leibler Divergences Between Multivariate t-Distributions, IEEE Signal Processing Letters. doi:10.1109/LSP.2023.3324594
nu1 <- 2 Sigma1 <- matrix(c(2, 1.2, 0.4, 1.2, 2, 0.6, 0.4, 0.6, 2), nrow = 3) nu2 <- 4 Sigma2 <- matrix(c(1, 0.3, 0.1, 0.3, 1, 0.4, 0.1, 0.4, 1), nrow = 3) # Renyi divergence diststudent(nu1, Sigma1, nu2, Sigma2, bet = 0.25) diststudent(nu2, Sigma2, nu1, Sigma1, bet = 0.25) # Bhattacharyya distance diststudent(nu1, Sigma1, nu2, Sigma2, dist = "bhattacharyya") diststudent(nu2, Sigma2, nu1, Sigma1, dist = "bhattacharyya") # Hellinger distance diststudent(nu1, Sigma1, nu2, Sigma2, dist = "hellinger") diststudent(nu2, Sigma2, nu1, Sigma1, dist = "hellinger")
nu1 <- 2 Sigma1 <- matrix(c(2, 1.2, 0.4, 1.2, 2, 0.6, 0.4, 0.6, 2), nrow = 3) nu2 <- 4 Sigma2 <- matrix(c(1, 0.3, 0.1, 0.3, 1, 0.4, 0.1, 0.4, 1), nrow = 3) # Renyi divergence diststudent(nu1, Sigma1, nu2, Sigma2, bet = 0.25) diststudent(nu2, Sigma2, nu1, Sigma1, bet = 0.25) # Bhattacharyya distance diststudent(nu1, Sigma1, nu2, Sigma2, dist = "bhattacharyya") diststudent(nu2, Sigma2, nu1, Sigma1, dist = "bhattacharyya") # Hellinger distance diststudent(nu1, Sigma1, nu2, Sigma2, dist = "hellinger") diststudent(nu2, Sigma2, nu1, Sigma1, dist = "hellinger")
DistributionDensity of the multivariate ( variables)
distribution (MTD)
with degrees of freedom
nu
, mean vector mu
and
correlation matrix Sigma
.
dmtd(x, nu, mu, Sigma, tol = 1e-6)
dmtd(x, nu, mu, Sigma, tol = 1e-6)
x |
length |
nu |
numeric. The degrees of freedom. |
mu |
length |
Sigma |
symmetric, positive-definite square matrix of order |
tol |
tolerance (relative to largest variance) for numerical lack of positive-definiteness in Sigma. |
The density function of a multivariate distribution
with
variables is given by:
When (univariate case) it becomes:
The value of the density.
Pierre Santagostini, Nizar Bouhlel
S. Kotz and Saralees Nadarajah (2004), Multivariate Distributions and Their Applications, Cambridge University Press.
nu <- 1 mu <- c(0, 1, 4) Sigma <- matrix(c(0.8, 0.3, 0.2, 0.3, 0.2, 0.1, 0.2, 0.1, 0.2), nrow = 3) dmtd(c(0, 1, 4), nu, mu, Sigma) dmtd(c(1, 2, 3), nu, mu, Sigma) # Univariate dmtd(1, 3, 0, 1) dt(1, 3)
nu <- 1 mu <- c(0, 1, 4) Sigma <- matrix(c(0.8, 0.3, 0.2, 0.3, 0.2, 0.1, 0.2, 0.1, 0.2), nrow = 3) dmtd(c(0, 1, 4), nu, mu, Sigma) dmtd(c(1, 2, 3), nu, mu, Sigma) # Univariate dmtd(1, 3, 0, 1) dt(1, 3)
DistributionsComputes the Kullback-Leibler divergence between two random vectors distributed
according to multivariate distributions (MTD) with zero location vector.
kldstudent(nu1, Sigma1, nu2, Sigma2, eps = 1e-06)
kldstudent(nu1, Sigma1, nu2, Sigma2, eps = 1e-06)
nu1 |
numeric. The degrees of freedom of the first distribution. |
Sigma1 |
symmetric, positive-definite matrix. The scatter matrix of the first distribution. |
nu2 |
numeric. The degrees of freedom of the second 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 |
Given , a random vector of
distributed according to the centered MTD
with parameters
and
, a random vector of
distributed according to the MCD
with parameters
.
Let the eigenvalues of the square matrix
sorted in increasing order:
The Kullback-Leibler divergence of from
is given by:
where is the digamma function (see Special)
and
is given by:
If :
If :
If and
:
is the Lauricella
-hypergeometric function defined for
variables:
A numeric value: the Kullback-Leibler divergence between the two distributions,
with two attributes attr(, "epsilon")
(precision of the partial derivative of the Lauricella -hypergeometric function,see Details)
and
attr(, "k")
(number of iterations).
Pierre Santagostini, Nizar Bouhlel
N. Bouhlel and D. Rousseau (2023), Exact Rényi and Kullback-Leibler Divergences Between Multivariate t-Distributions, IEEE Signal Processing Letters. doi:10.1109/LSP.2023.3324594
nu1 <- 2 Sigma1 <- matrix(c(2, 1.2, 0.4, 1.2, 2, 0.6, 0.4, 0.6, 2), nrow = 3) nu2 <- 4 Sigma2 <- matrix(c(1, 0.3, 0.1, 0.3, 1, 0.4, 0.1, 0.4, 1), nrow = 3) kldstudent(nu1, Sigma1, nu2, Sigma2) kldstudent(nu2, Sigma2, nu1, Sigma1)
nu1 <- 2 Sigma1 <- matrix(c(2, 1.2, 0.4, 1.2, 2, 0.6, 0.4, 0.6, 2), nrow = 3) nu2 <- 4 Sigma2 <- matrix(c(1, 0.3, 0.1, 0.3, 1, 0.4, 0.1, 0.4, 1), nrow = 3) kldstudent(nu1, Sigma1, nu2, Sigma2) kldstudent(nu2, Sigma2, nu1, Sigma1)
-Hypergeometric FunctionComputes the Lauricella -hypergeometric Function function.
lauricella(a, b, g, x, eps = 1e-06)
lauricella(a, b, g, x, eps = 1e-06)
a |
numeric. |
b |
numeric vector. |
g |
numeric. |
x |
numeric vector. |
eps |
numeric. Precision for the nested sums (default 1e-06). |
If is the length of the
and
x
vectors,
the Lauricella -hypergeometric Function function is given by:
where is the Pochhammer symbol (see
pochhammer
).
If , this sum converges.
Otherwise there is an error.
The eps
argument gives the required precision for its computation.
It is the attr(, "epsilon")
attribute of the returned value.
Sometimes, the convergence is too slow and the required precision cannot be reached.
If this happens, the attr(, "epsilon")
attribute is the precision that was really reached.
A numeric value: the value of the Lauricella function,
with two attributes attr(, "epsilon")
(precision of the result) and attr(, "k")
(number of iterations).
Pierre Santagostini, Nizar Bouhlel
N. Bouhlel and D. Rousseau, Exact Rényi and Kullback-Leibler Divergences Between Multivariate t-Distributions. IEEE Signal Processing Letters Processing Letters, vol. 26 no. 7, July 2019. doi:10.1109/LSP.2019.2915000
Computes the logarithm of the Pochhammer symbol.
lnpochhammer(x, n)
lnpochhammer(x, n)
x |
numeric. |
n |
positive integer. |
The Pochhammer symbol is given by:
So, if :
If ,
Numeric value. The logarithm of the Pochhammer symbol.
Pierre Santagostini, Nizar Bouhlel
lnpochhammer(2, 0) lnpochhammer(2, 1) lnpochhammer(2, 3)
lnpochhammer(2, 0) lnpochhammer(2, 1) lnpochhammer(2, 3)
DensityPlots the probability density of the multivariate distribution with 2 variables
with location parameter
mu
and scatter matrix Sigma
.
plotmtd(nu, 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, ...)
plotmtd(nu, 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, ...)
nu |
numeric. The degrees of freedom. |
mu |
length 2 numeric vector. The mean vector. |
Sigma |
symmetric, positive-definite square matrix of order 2. The correlation 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 |
xvals , yvals
|
The values at which to evaluate |
xlab , ylab , zlab
|
The axis labels. |
col |
The color to use for the plot. See |
tol |
tolerance (relative to largest variance) for numerical lack of positive-definiteness in Sigma, for the estimation of the density. see |
... |
Additional arguments to pass to |
Returns invisibly the probability density function.
Pierre Santagostini, Nizar Bouhlel
S. Kotz and Saralees Nadarajah (2004), Multivariate Distributions and Their Applications, Cambridge University Press.
dmtd
: probability density of a multivariate density
contourmtd
: contour plot of a bivariate density.
plot3d.function
: plot a function of two variables.
nu <- 1 mu <- c(1, 4) Sigma <- matrix(c(0.8, 0.2, 0.2, 0.2), nrow = 2) plotmtd(nu, mu, Sigma)
nu <- 1 mu <- c(1, 4) Sigma <- matrix(c(0.8, 0.2, 0.2, 0.2), nrow = 2) plotmtd(nu, mu, Sigma)
Computes the Pochhammer symbol.
pochhammer(x, n)
pochhammer(x, n)
x |
numeric. |
n |
positive integer. |
The Pochhammer symbol is given by:
Numeric value. The value of the Pochhammer symbol.
Pierre Santagostini, Nizar Bouhlel
pochhammer(2, 0) pochhammer(2, 1) pochhammer(2, 3)
pochhammer(2, 0) pochhammer(2, 1) pochhammer(2, 3)
DistributionProduces one or more samples from the multivariate ( variables)
distribution (MTD)
with degrees of freedom
nu
, mean vector mu
and
correlation matrix Sigma
.
rmtd(n, nu, mu, Sigma, tol = 1e-6)
rmtd(n, nu, mu, Sigma, tol = 1e-6)
n |
integer. Number of observations. |
nu |
numeric. The degrees of freedom. |
mu |
length |
Sigma |
symmetric, positive-definite square matrix of order |
tol |
tolerance for numerical lack of positive-definiteness in Sigma (for |
A sample from a MTD with parameters ,
and
can be generated using:
where is a random vector distributed among a centered Gaussian density
with covariance matrix
(generated using
mvrnorm
)
and is distributed among a Chi-squared distribution with
degrees of freedom.
A matrix with columns and
rows.
Pierre Santagostini, Nizar Bouhlel
S. Kotz and Saralees Nadarajah (2004), Multivariate Distributions and Their Applications, Cambridge University Press.
dmtd
: probability density of a MTD.
nu <- 3 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 <- rmtd(10000, nu, mu, Sigma) head(x) dim(x) mu; colMeans(x) nu/(nu-2)*Sigma; var(x)
nu <- 3 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 <- rmtd(10000, nu, mu, Sigma) head(x) dim(x) mu; colMeans(x) nu/(nu-2)*Sigma; var(x)