# Can the Kolmogorov-Smirnov statistic be used to check if these

Disclaimer: Note this is a simplified version of my actual problem. These are not my real data.

The set up

The hexbin plot shows mass and height of goats in Iceland. There are a few thousand samples.

I measure the mass and height of goats in Japan. These are shown by the red dots. There are far fewer samples.

The problem

My hypothesis is the measurements of the Japanese goats and the Icelandic goats are from the same underlying sample.

I was going to use the Kolmogorov-Smirnov two-sample test to test for this, but one of the distributions is far from continuous. I can just use a chi-square goodness of fit test either.

Is there a different test I can do to show goat_Japan = goat_iceland?

• Do you want to compare the two-dimensional distributions? – Dave Sep 25 '19 at 10:11
• Yeah, and that is where I run into issues with the chi-square test, as I want to compare both 2D distributions. In Python, I want to write something like p_value = stat_test(distA['Height], distA['Mass'], distB['Height'], distB['Mass']) – Sean Mooney Sep 25 '19 at 10:17
• Another question: why do you say that one of the distributions is far from continuous? You have empirical distributions that are necessarily discrete. However, hypothesis testing cares about the populations from which the empirical distributions are drawn. Do you have reason to believe that one of the population distributions is discrete while the other is continuous? (I would say that you have no reason to believe that for your posted example. Your real data may be a different story.) – Dave Sep 25 '19 at 10:30
• Oh yeah, you are correct. I do believe the underlying distributions are continuous, my sampling of them is just discrete. – Sean Mooney Sep 25 '19 at 10:33
• The sampling is always discrete, so you can use tests for continuous populations. I wonder if either of these links answer your question: stats.stackexchange.com/questions/71036/… stats.stackexchange.com/questions/25946/… – Dave Sep 25 '19 at 10:41

As mentioned by others, it looks like a classical case for two-dimensional Kolmogorov-Smirnov, first published by J. A. Peacock, Two-dimensional goodness-of-fit testing in astronomy, Monthly Notices Royal Astronomy Society 202 (1983) 615–627. Free PDF

Here few additional references not mentioned so far:

1. Lopes et al. 'The two-dimensional Kolmogorov-Smirnov test'. Great discussion of all relevant implementation to date. Free PDF here.
2. Recent fast implementation of the test by Xiao 'A fast algorithm for two-dimensional Kolmogorov–Smirnov two sample tests', Computational Statistics and Data Analysis 105 (2017) 53–58. link to PDF. R package
3. Matlab implementation by Muir can be found here
4. Cooke's algorithm mentioned by Lopes et al. can be found here
5. and last but not least it's covered in Numerical Recipes link

Also wanted to mention the 'earth mover distance', EMD, https://en.wikipedia.org/wiki/Earth_mover%27s_distance which is an alternative solution. “EMD is a measure of the distance between two probability distributions over a region D. In mathematics, this is known as the Wasserstein metric.” Python code is available here.

Dave pointed me along the right lines in a comment to the question, and cleared up some confusion. I believe I found an answer (with a Python script to do it) here.