wass_stat {twosamples} | R Documentation |
Wasserstein Distance Test A two-sample test based on Wasserstein's distance.
wass_stat(a, b, power = 1) wass_test(a, b, nboots = 2000, p = default.p)
a |
a vector of numbers |
b |
a vector of numbers |
power |
power to raise test stat to |
nboots |
Number of bootstrap iterations |
p |
power to raise test stat to |
The Wasserstein test compares two ECDFs by looking at the Wasserstein distance between the two. This is of course the area between the two ECDFs. Formally – if E is the ECDF of sample 1 and F is the ECDF of sample 2, then WASS = Integral |E(x)-F(x)| across all x. The test p-value is calculated by randomly resampling two samples of the same size using the combined sample. Intuitively the Wasserstein test improves on CVM by allowing more extreme observations to carry more weight. At a higher level – CVM/AD/KS/etc only require ordinal data. Wasserstein gains its power because it takes advantages of the properties of interval data – i.e. the distances have some meaning.
Output is a length 2 Vector with test stat and p-value in that order. That vector has 3 attributes – the sample sizes of each sample, and the number of bootstraps performed for the pvalue.
wass_stat
: Wasserstein metric between two ECDFs
wass_test
: Permutation based two sample test using Wasserstein metric
vec1 = rnorm(20) vec2 = rnorm(20,4) wass_test(vec1,vec2)