# wasserstein_metric: wasserstein_metric In waddR: Statistical tests for detecting differential distributions based on the 2-Wasserstein distance

## Description

The order `p` Wasserstein metric (or distance) is defined as the `p`-th root of the total cost of turning one pile of mass x into a new pile of mass y. The cost a single transport x_i into y_i is the `p`-th power of the euclidean distance between x_i and y_i.

## Usage

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

## Arguments

 `x` NumericVector representing an empirical distribution under condition A `y` NumericVector representing an empirical distribution under condition B `p` order of the wasserstein distance `wa_` NumericVector representing the weights of datapoints (interpreted as clusters) in x `wb_` NumericVector representing the weights of datapoints (interpreted as clusters) in y

## Details

The masses in x and y can also be represented as clusters P and Q with weights W_P and W_Q. The wasserstein distance then becomes the optimal flow F, which is the sum of all optimal flows f_{ij} from (p_i, w_{p,i}) to (q_i, w_{q,i}).

This implementation of the Wasserstein metric is a Rcpp reimplementation of the wasserstein1d function by Dominic Schuhmacher from the package transport.

## Value

The wasserstein (transport) distance between x and y

## References

Schefzik and Goncalves 2019

 ```1 2 3 4 5 6 7``` ```# input: one dimensional data in two conditions x <- rnorm(100, 42, 2) y <- c(rnorm(61, 20, 1), rnorm(41, 40, 2)) # output: The exact Wasserstein distance between the two input # vectors. Reimplementation of the wasserstein1d function found in # the packge transport. d.wass <- wasserstein_metric(x,y,2) ```