user4988137
user4988137

Reputation:

Ks test from Dagum distribution in matlab

I have generated x numbers with Dagum distribution using inverse cdf method and now I want to run ks test but I constantly get this error:

Error using kstest (line 142)
CDF must define an increasing function of X.

This is my code:

N=20000;
a=5;
p=1;
b=1;
u=rand(1,N);
x=b*(u.^(-1/p)-1).^(-1/a);

cdf=(1+(x/b).^(-a)).^(-p);
X=0:length(x)-1;
h=kstest(x,[X' cdf']);

How should I run ks test with Dagum distribution'

Thank you!

Upvotes: 0

Views: 393

Answers (1)

Ander Biguri
Ander Biguri

Reputation: 35525

The problem is that CDF should be a cumulative distribution function. The definition of a CDF inplies that its an increasing function, the only way it could decrease would be by having negative probabilities, which make no sense.

When you give kstest a CDF, it should look something like this:

plot(X',cdf')

enter image description here

However, yours look like

enter image description here

Which is obviously wrong. Therefore the error you get is: https://en.wikipedia.org/wiki/Cumulative_distribution_function, because it should, else it has no mathematical sense.

However, looking further, it looks like you have defined X=0:length(x)-1;. This makes no sense, as you are "rearanging" your cdf to point out to linear indexes instead of the real data. After some tests, I realised that if you use x instead of X, then everything looks like its working.

Your cdf looks like:

enter image description here

and you can call h=kstest(x,[x' cdf']); without any problem.

As a side note, cdf is a MATLAB function, do not call a variable like that, or you will never be able to use the function!

Upvotes: 2

Related Questions