# Kolmogorov-Smirnov test for PDF

**URL:** <https://discourse.julialang.org/t/kolmogorov-smirnov-test-for-pdf/99771>\
**Category:** Statistics\
**Created:** [June 2, 2023, 1:59pm UTC](https://discourse.julialang.org/t/kolmogorov-smirnov-test-for-pdf/99771 "2023-06-02T13:59:55Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sergey\_Novak](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sergey_novak/32/37716_2.png) [@Sergey\_Novak](https://discourse.julialang.org/u/Sergey_Novak)\
**Post date:** [June 2, 2023, 1:59pm UTC](https://discourse.julialang.org/t/kolmogorov-smirnov-test-for-pdf/99771/1 "2023-06-02T13:59:55Z")

</div>

Hello!  
I have probability density function(PDF) for my data. I need use Kolmogorov-Smirnov test to check which distribution corresponds PDF.  
I have not dealt with statistics before, is it possible to throw off some example for my case?

Link on my data: [data - Google Drive](https://drive.google.com/drive/folders/1Y9B-DuJZiBcFtT6DFv9sEwk4YWjKZmQS?usp=sharing)  
Image with log scale:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/9/b/9bf1563a148b6fbf2cc584767e1ecc249e77c5c8.png)  
Code for image:

```julia
sel_1 = load("sel_presentation.jld")["data"]
pdf_1 = load("pdf_presentation.jld")["data"];
EE_mapcopy = pdf_1;
EE_mapcopy = [iszero(x) ? NaN : x for x in EE_mapcopy];

f = Figure(resolution = (600, 600))

ax = Axis(f[1, 1], yscale = log10,
xlabel = L"|x_{||}|n", ylabel = L"PDF",
xlabelsize = 35, ylabelsize = 35,
xticklabelsize = 30, yticklabelsize = 30 )

ax.xgridvisible = false
ax.ygridvisible = false

lines!(sel_1, EE_mapcopy, linewidth = 3.0, color = :blue)

display(f)

```

---

<div class="post-metadata">

**Author:** ![gdalle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdalle/32/27854_2.png) [@gdalle](https://discourse.julialang.org/u/gdalle)\
**Post date:** [June 2, 2023, 2:17pm UTC](https://discourse.julialang.org/t/kolmogorov-smirnov-test-for-pdf/99771/2 "2023-06-02T14:17:52Z")

</div>

You can do it with [HypothesisTests.jl](https://juliastats.org/HypothesisTests.jl/stable/nonparametric/#Kolmogorov-Smirnov-test), but for that you have to choose a distribution to compare your data with. Do you have any idea what that might be?

---

<div class="post-metadata">

**Author:** ![Sergey\_Novak](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sergey_novak/32/37716_2.png) [@Sergey\_Novak](https://discourse.julialang.org/u/Sergey_Novak)\
**Post date:** [June 2, 2023, 2:26pm UTC](https://discourse.julialang.org/t/kolmogorov-smirnov-test-for-pdf/99771/3 "2023-06-02T14:26:04Z")

</div>

Thank you  
I am trying to reproduce the result of the article. There is dragon king. That is, several distributions. The first should be power law

Image from article:  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/6/8/68826f7012f3a6b94db79b1ed818ce160a121f1b.png)  
Link on article: [Phys. Rev. E 97, 062311 (2018) - Dragon-king-like extreme events in coupled bursting neurons](https://journals.aps.org/pre/abstract/10.1103/PhysRevE.97.062311)

---

<div class="post-metadata">

**Author:** ![gdalle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdalle/32/27854_2.png) [@gdalle](https://discourse.julialang.org/u/gdalle)\
**Post date:** [June 2, 2023, 4:44pm UTC](https://discourse.julialang.org/t/kolmogorov-smirnov-test-for-pdf/99771/4 "2023-06-02T16:44:59Z")

</div>

As long as you find your target distribution here you should be fine: [Univariate Distributions · Distributions.jl](https://juliastats.org/Distributions.jl/stable/univariate/#Index)

---

<div class="post-metadata">

**Author:** ![dlakelan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dlakelan/32/8491_2.png) [@dlakelan](https://discourse.julialang.org/u/dlakelan)\
**Post date:** [June 2, 2023, 5:48pm UTC](https://discourse.julialang.org/t/kolmogorov-smirnov-test-for-pdf/99771/5 "2023-06-02T17:48:20Z")

</div>

> [@Sergey\_Novak](#):
>
> I need use Kolmogorov-Smirnov test to check which distribution corresponds PDF.

Please note, all that the K-S test can do is tell you which distributions probably Do NOT correspond to your PDF (ie. a small p value means probably not that pdf). A large p value does not mean “yes this pdf” it means “this is one of the ones that might work”. It’s also fairly sensitive so with a lot of data it will say no to pretty much anything because no data is actually from a given PDF (only simulated data would work perfectly).

---

<div class="post-metadata">

**Author:** ![blackeneth](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/blackeneth/32/10353_2.png) [@blackeneth](https://discourse.julialang.org/u/blackeneth)\
**Post date:** [June 2, 2023, 7:46pm UTC](https://discourse.julialang.org/t/kolmogorov-smirnov-test-for-pdf/99771/6 "2023-06-02T19:46:07Z")

</div>

The KS test is not suitable for detecting dragon kings.

Have a look a look at these three papers for different methods for detecting DKs:

Janczura, J.; Weron, R. (2012). “Black swans or dragon-kings? A simple test for deviations from the power law”. The European Physical Journal Special Topics. 205 (1): 79–93.

Robust statistical tests of Dragon-Kings beyond power law distributions  
Eur. Phys. J. Special Topics 205, 95-115 (2012)

Wheatley, Spencer and Sornette, Didier, Multiple Outlier Detection in Samples with Exponential & Pareto Tails: Redeeming the Inward Approach & Detecting Dragon Kings (August 17, 2015). Swiss Finance Institute Research Paper No. 15-28

R had package “dragonking” which implements these methods.
