# wasserstein_metric: Calculate the p-Wasserstein distance In goncalves-lab/waddR: Statistical tests for detecting differential distributions based on the 2-Wasserstein distance

## Description

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

## Usage

 `1` ```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 the functions `squared_wass_approx` and `squared_wass_decomp` for alternative implementations of the 2-Wasserstein distance.
 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20``` ```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 ```