distl2d: L^2 distance between probability densities

View source: R/distl2d.R

distl2dR Documentation

L^2 distance between probability densities


L^2 distance between two multivariate (p > 1) or univariate (dimension: p = 1) probability densities, estimated from samples.


distl2d(x1, x2, method = "gaussiand", check = FALSE, varw1 = NULL, varw2 = NULL)


x1, x2

the samples from the probability densities (see l2d).


string. It can be:

  • "gaussiand" if the densities are considered to be Gaussian.

  • "kern" if they are estimated using the Gaussian kernel method.


logical. When TRUE (the default is FALSE) the function checks if the covariance matrices (if method = "gaussiand") or smoothing bandwidth matrices (if method = "kern") are not degenerate, before computing the inner product.

Notice that if p = 1, it checks if the variances or smoothing parameters are not zero.

varw1, varw2

the bandwidths when the densities are estimated by the kernel method (see l2d).


The function distl2d computes the distance between f_1 and f_2 from the formula

||f_1 - f_2||^2 = <f_1, f_1> + <f_2, f_2> - 2 <f_1, f_2>

For some information about the method used to compute the L^2 inner product or about the arguments, see l2d.


The L^2 distance between the two densities.

Be careful! If check = FALSE and one smoothing bandwidth matrix is degenerate, the result returned can not be considered.


Rachid Boumaza, Pierre Santagostini, Smail Yousfi, Gilles Hunault, Sabine Demotes-Mainard

See Also

matdistl2d in order to compute pairwise distances between several densities.


m1 <- c(0,0)
v1 <- matrix(c(1,0,0,1),ncol = 2) 
m2 <- c(0,1)
v2 <- matrix(c(4,1,1,9),ncol = 2)
x1 <- mvrnorm(n = 3,mu = m1,Sigma = v1)
x2 <- mvrnorm(n = 5, mu = m2, Sigma = v2)
distl2d(x1, x2, method = "gaussiand")
distl2d(x1, x2, method = "kern")
distl2d(x1, x2, method = "kern", varw1 = v1, varw2 = v2)

dad documentation built on Aug. 30, 2023, 5:06 p.m.