Reputation:
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
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')
However, yours look like
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:
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