pdist: Distance Measures between Multiple Empirical Cumulative...

Description Usage Arguments Value See Also Examples

View source: R/pdist.R

Description

We measure distance between two empirical cumulative distribution functions (ECDF). For simplicity, we only take an input of ecdf objects from stats package.

Usage

1
pdist(elist, type = c("KS", "Lp", "Wasserstein"), p = 2, as.dist = FALSE)

Arguments

elist

a length N list of ecdf objects.

type

name of the distance/dissimilarity measure. Case insensitive.

p

exponent for Lp or Wasserstein distance.

as.dist

a logical; TRUE to return dist object, FALSE to return an (N\times N) symmetric matrix of pairwise distances.

Value

either dist object of an (N\times N) symmetric matrix of pairwise distances by as.dist argument.

See Also

ecdf

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
## toy example : 10 of random and uniform distributions
mylist = list()
for (i in 1:10){
  mylist[[i]] = stats::ecdf(stats::rnorm(50, sd=2))
}
for (i in 11:20){
  mylist[[i]] = stats::ecdf(stats::runif(50, min=-5))
}

## compute several distance measures
dk = pdist(mylist, type="KS")          # Kolmogorov-Smirnov
dl = pdist(mylist, type="Lp")          # L2 
dw = pdist(mylist, type="Wasserstein") # 2-Wasserstein

## visualize
opar = par(mfrow=c(1,3), pty="s")
image(dk[,nrow(dk):1], axes=FALSE, main="Kolmogorov-Smirnov")
image(dl[,nrow(dl):1], axes=FALSE, main="L2")
image(dw[,nrow(dw):1], axes=FALSE, main="2-Wasserstein")
par(opar)

kyoustat/T4ecdf documentation built on Dec. 15, 2019, 10:12 p.m.