aDistDens: Aitchison distance between densities

View source: R/aDistDens.R

aDistDensR Documentation

Aitchison distance between densities

Description

Computes the distance between probability densities in the Bayes Hilbert space, i.e. the L^2 distance of their functional clr transforms. It is the functional counterpart of the Aitchison distance aDist for compositions.

Usage

aDistDens(z, z_step, f, g = NULL, p = NULL, type = c("rows", "cross"))

Arguments

z

numeric vector, equidistant grid of points on the domain.

z_step

spacing of the grid z, typically diff(z[1:2]).

f

strictly positive density values on the grid: a vector of the same length as z for one density, or a matrix with one density per row and length(z) columns.

g

NULL, or density values in the same format as f.

p

optional vector of the same length as z: density of the reference measure P with respect to the Lebesgue measure. NULL (default) means the Lebesgue measure.

type

"rows" (default): the distances between corresponding rows of f and g (a single number for two densities); "cross": the matrix of distances between all rows of f and all rows of g. Ignored if g is NULL.

Details

For densities f and g with respect to the Lebesgue measure on [a, b], the distance is

d(f, g)^2 = \int_a^b \left(\mathrm{fcenLR}(f)(t) - \mathrm{fcenLR}(g)(t)\right)^2 dt,

see fcenLR. If the density p of a reference measure P is given, f and g are P-densities and the distance of the weighted Bayes space B^2(P) is computed,

d_P(f, g)^2 = \int \left(\mathrm{fcenLR}_P(f)(t) - \mathrm{fcenLR}_P(g)(t)\right)^2 p(t)\,dt,

see fcenLRp.

The integrals are approximated by the trapezoidal rule (trapzc) on the equidistant grid z. On this grid the distance equals the weighted Aitchison distance aDist(f, g, weights = c * p) of the density values, where c = h (1/2, 1, \dots, 1, 1/2) are the trapezoidal weights for spacing h; aDistDens uses exactly this computation. Like the Aitchison distance, the result does not change if a density is multiplied by a positive constant, so the densities do not need to be normalised.

The distance follows the convention of Egozcue and Pawlowsky-Glahn (2016), without the factor 1/P(\Omega) that van den Boogaart et al. (2014) include in the inner product of the Bayes space; for that convention divide the result by \sqrt{b - a} (or by \sqrt{P(\Omega)}).

Value

If g is NULL, the distances between all densities in f as an object of class "dist". Otherwise a vector (type = "rows") or a matrix (type = "cross") of distances.

Author(s)

Matthias Templ

References

Egozcue, J.J., Diaz-Barrero, J.L. and Pawlowsky-Glahn, V. (2006) Hilbert space of probability density functions based on Aitchison geometry. Acta Mathematica Sinica, English Series, 22 (4), 1175-1182. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1007/s10114-005-0678-2")}

Egozcue, J.J. and Pawlowsky-Glahn, V. (2016) Changing the reference measure in the simplex and its weighting effects. Austrian Journal of Statistics, 45 (4), 25-44. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.17713/ajs.v45i4.126")}

Talska, R., Menafoglio, A., Hron, K., Egozcue, J. J., Palarea-Albaladejo, J. (2020). Weighting the domain of probability densities in functional data analysis. Stat, 9 (1), e283. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1002/sta4.283")}

van den Boogaart, K.G., Egozcue, J.J. and Pawlowsky-Glahn, V. (2014) Bayes Hilbert spaces. Australian & New Zealand Journal of Statistics, 56 (2), 171-194. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1111/anzs.12074")}

See Also

aDist, fcenLR, fcenLRp, trapzc

Examples

t <- seq(-4.7, 4.7, length = 1000)
t_step <- diff(t[1:2])
f <- dnorm(t, mean = 0, sd = 1.5)
g <- dnorm(t, mean = 1, sd = 1.5)

aDistDens(t, t_step, f, g)
# same value from the clr transforms
sqrt(trapzc(t_step, (fcenLR(t, t_step, f) - fcenLR(t, t_step, g))^2))

# scale invariance: densities need not be normalised
aDistDens(t, t_step, 10 * f, g)

# distance matrix of several densities (one per row)
dens <- t(sapply(c(0, 0.5, 1, 2), function(m) dnorm(t, mean = m, sd = 1.5)))
aDistDens(t, t_step, dens)

# with respect to a reference measure P (here a normal distribution)
p <- dnorm(t, sd = 2) / trapzc(t_step, dnorm(t, sd = 2))
aDistDens(t, t_step, f / p, g / p, p = p)

robCompositions documentation built on Nov. 1, 2026, 1:06 a.m.