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.

  • $\begingroup$ Perhaps I am missing something, but I think the Kolmogorov–Smirnov test applies to one-dimensional distributions. If you are interested on one of the proposal extensions (there are several because there is no natural extension to the multivariate case), please specify which one. $\endgroup$
    – user10525
    Apr 28, 2012 at 10:42
  • 2
    $\begingroup$ I'd rather say there is a natural extension to the multivariate case, but it involves the distribution of $\sup |K(t)|$ where $K$ is the Kiefer process (two-dimensional Brownian bridge), and this distribution is badly known. $\endgroup$ Apr 28, 2012 at 11:47

3 Answers 3


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.


A two-dimensional extension of the Kolmogorov-Smirnov test has been described by Justel, Pena and Zamar in a "A multivariate Komogorov-Smirnov test of goodness of fit". @Procrastinator's comments suggests there may be other such proposals.

However, I haven't seen a package with a straightforward implementation.

Depending on what you want to do, kde.test() in Tarn Duong's ks package for R might be more useful.


you may find this Matlab code to be useful.


  • 4
    $\begingroup$ Welcome to this site! Could you provide a brief description of the resources available on that page? $\endgroup$
    – chl
    Apr 10, 2013 at 17:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.