wasserstein_metric: Calculate the p-Wasserstein distance

View source: R/RcppExports.R

wasserstein_metricR Documentation

Calculate the p-Wasserstein distance

Description

Calculates the p-Wasserstein distance (metric) between two vectors x and y

Usage

wasserstein_metric(x, y, p = 1, wa_ = NULL, wb_ = NULL)

Arguments

x

sample (vector) representing the distribution of condition A

y

sample (vector) representing the distribution of condition B

p

order of the Wasserstein distance

wa_

optional vector of weights for x

wb_

optional vector of weights for y

Details

This implementation of the p-Wasserstein distance is a Rcpp reimplementation of the wasserstein1d function from the R package transport by Schuhmacher et al.

Value

The p-Wasserstein distance between x and y

References

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 Also

See the functions squared_wass_approx and squared_wass_decomp for alternative implementations of the 2-Wasserstein distance.

Examples

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


goncalves-lab/waddR documentation built on June 29, 2023, 12:18 a.m.