Two-dimensional Kolmogorov–Smirnov

I would like to run some two dimensional Kolmogorov–Smironov tests to determine whether a two-dimensional distribution fits with a reference.

Is there any package or application that I could use in a relatively straightforward fashion? Or is there a different algorithm that is preferrable? I have just a basic statistical knowledge.


Python implementation

I have written a python implementation using numpy. You can find the code here, you may find more infomation in the docstring in the code.

And here’s another one (not by me). This Notebook provide a Python implementation for 2D K-S test with 2 samples. The .py file can be downloaded here. The code seems to be a straight translation of C code, the efficiency might be a problem if sample size is large.

However you’d better check the codes (no matter which one) with the original papers/books before you use. The python implementations of 2d KS test are far less checked than the ones in R.

More infomation

The algorithm is first developed in two papers (as I see)

A nice introduction and the C implementation can be found in

Here’s a post titled Beware the Kolmogorov-Smirnov test is also related to the subject, you may want to have a look. It encourages using resample method to evaluate the p-value with given KS distance.

Source : Link , Question Author : Manuel J Gomez , Answer Author : Community

Leave a Comment