Fitting Distributions

Hello everyone,

I have a task to determine which distribution corresponds to the probability density function constructed from my data.
To address this, I use the KS-test for distributions that I consider somewhat similar to my own.

However, when applying the fit to several distributions, I encounter the following error:

ERROR: suffstats is not implemented for (GeneralizedPareto, Vector{Float64}).

Could you advise how to fix this error? Or should I approach my problem differently from the beginning?

Code:

using JLD2, Distributions, HypothesisTests, Statistics

function get_PDF(IEI; shift = 10)
    total_count_IEI = length(IEI)
    array_PDF = Float64[]
    for index in 1:total_count_IEI
        count_IEI_i = count(IEI[index]-shift .<= IEI .<= IEI[index]+shift)
        PDF_IEI_i = count_IEI_i / total_count_IEI
        push!(array_PDF, PDF_IEI_i)
    end
    return array_PDF
end

path_to_save_PDF = "/home/sergey/work/data/3Rulkov_chemical/EEs/"
name_PDF = "PDFok g1 = 4.7; g2 = 5.0.jld2"
name_thresholds = "ampl_spikes g1 = 4.7; g2 = 5.0.jld2"

PDF_EEs = load(path_to_save_PDF*name_PDF)["PDF_ok"]
ampl_spikes = load(path_to_save_PDF*name_thresholds)["ampl_spikes"]

data = abs.(ampl_spikes);
data = sort(data);
PDF_positive_spikes = get_PDF(data; shift = 0.03)

weibull_dst = fit(Weibull, data)
expon_dst = fit(Exponential, data)

noncent_dst = fit(GeneralizedPareto, data) # error
fit(NoncentralChisq, data) # error


ks_test_weib = ExactOneSampleKSTest(data, weibull_dst)

ks_test_exp = ExactOneSampleKSTest(data, expon_dst)

Link to the data: data for KS-test - Google Drive

Thanks for your help!

PDF for my data:

I think this means that Distributions.jl doesn’t support fitting these distributions, so you’ll have to resort to maximum likelihood (or whatever other appropriate methods) using numerical optimization packages like Optimization.jl.

1 Like

For GeneralizedPareto and GeneralizedExtremeValue you can use ExtremeStats.jl

2 Likes

that looks like a binned distribution?

If you have an (extended) PDF, and you’re trying to fit binned data to it, you might be able to use:

you can use this package together with Optimization.jl and this will give you the parameter estimation based on maximal likelihood.

Then, you should be able to use those parameters to perform KS test

1 Like

Thank you for the link to the math package.

Could you please advise on a math package for fitting the dragon-king distribution? I was unable to find anything related to this distribution in Julia.

I don’t think this is a binned distribution. It is a usual way of constructing a PDF to identify extreme events in nonlinear dynamical systems.

What do you mean by extended PDF? Sorry, my level of knowledge in statistics is not good enough.

Thank you for the link to the package. I will try to use it.

I don’t know of any package. You can search for keywords in juliahub.com to find packages with some overlap.

it means the function you call PDF is not always properly normalized to 1 in the interval, depending on the parameters you choose

Can I obtain a PDF using kernel density estimation, or is it not applicable in my case?

Thank you for your help