0

Recently I wanted to compare two sets of points and found the R package 'ks'. The function kde.test (a kernel density based global two-sample comparison test, not KS test) is what I need. For example

library(MASS)
data(crabs)
x1 <- crabs[crabs$sp=="B", c(4,6)]
x2 <- crabs[crabs$sp=="O", c(4,6)]
kt <- kde.test(x1=x1, x2=x2)

But unfortunately I'm not familiar in R and most of my work was done using Python, so it's hard to transfer my scripts to R. At the same time, the function of 'ks' (mainly kde.test) is important to my work. Does anyone know if there's a Python version of 'ks', or if there's a package with similar features in Python?

  • Please provide enough code so others can better understand or reproduce the problem. – Community Jun 01 '22 at 12:40
  • Which function exactly from said R package you need to used? – Daweo Jun 01 '22 at 12:41
  • Does this help: 1. [CALCULATE KS STATISTIC WITH PYTHON](https://www.listendata.com/2019/07/KS-Statistics-Python.html) or 2. [KS test: R vs Python](https://stackoverflow.com/questions/65631347/ks-test-r-vs-python) or 3. [Is there a Python package hat allows to perform a Kolmogorov Smirnov test](https://stackoverflow.com/questions/61476887/is-there-a-python-package-hat-allows-to-perform-a-kolmogorov-smirnov-test-agains) – DarrylG Jun 01 '22 at 12:43
  • Thanks to your reply @Daweo . Actually the function kde.test is what I used. It's a kernel density based global two-sample comparison test. Maybe I didn't describe it very clearly in the question. I'm going to edit that. – zxc969321555 Jun 01 '22 at 13:25

1 Answers1

2

You can use SciPy in Python.

Performs the (one-sample or two-sample) Kolmogorov-Smirnov test for goodness of fit.

The one-sample test compares the underlying distribution F(x) of a sample against a given distribution G(x). The two-sample test compares the underlying distributions of two independent samples. Both tests are valid only for continuous distributions.

  • Thanks to your reply. I don't use KS test because my datasets are spatial points so they are 2-d and I also have searched other functions in scipy. So I'm afraid there's no function in scipy for me. – zxc969321555 Jun 01 '22 at 13:35