wasserstein_metric | R Documentation |
Calculates the p
-Wasserstein distance (metric) between two vectors x
and y
wasserstein_metric(x, y, p = 1, wa_ = NULL, wb_ = NULL)
x |
sample (vector) representing the distribution of condition |
y |
sample (vector) representing the distribution of condition |
p |
order of the Wasserstein distance |
wa_ |
optional vector of weights for |
wb_ |
optional vector of weights for |
This implementation of the p
-Wasserstein distance is a Rcpp reimplementation of
the wasserstein1d
function from the R package transport
by Schuhmacher et al.
The p
-Wasserstein distance between x
and y
Schefzik, R., Flesch, J., and Goncalves, A. (2020). waddR: Using the 2-Wasserstein distance to identify differences between distributions in two-sample testing, with application to single-cell RNA-sequencing data.
See the functions squared_wass_approx
and squared_wass_decomp
for
alternative implementations of the 2-Wasserstein distance.
set.seed(24)
x<-rnorm(100)
y1<-rnorm(150)
y2<-rexp(150,3)
y3<-rpois(150,2)
#calculate 2-Wasserstein distance between x and y1
wasserstein_metric(x,y1,p=2)
#calculate squared 2-Wasserstein distance between x and y1
wasserstein_metric(x,y1,p=2)^2
#calculate 2-Wasserstein distance between x and y2
wasserstein_metric(x,y2,p=2)
#calculate squared 2-Wasserstein distance between x and y2
wasserstein_metric(x,y2,p=2)^2
#calculate 2-Wasserstein distance between x and y3
wasserstein_metric(x,y3,p=2)
#calculate squared 2-Wasserstein distance between x and y3
wasserstein_metric(x,y3,p=2)^2
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.