0
$\begingroup$

I want to test how well my data fits a uniform distribution and use this as one factor in a likelihood function I am constructing.

Unfortunately, I have no solid basis in statistics. So far, I figured out that a good criterion to use is the Kolmogorov-Smirnov test. I can do the test, but I do not know what the resulting number I get means.

What I want to have is the value of the PDF describing whether or not my sample is coming from the given distribution, so that I can plug this into my likelihood function. How do I get it?

Thank you!

$\endgroup$
3
  • $\begingroup$ What are you using to perform the test? If you can, post the code you're using, and the output, so that people can see what you're looking at. $\endgroup$
    – naught101
    Dec 15, 2012 at 1:08
  • $\begingroup$ Unfortunately, I do not have the code here at the moment. I basically follow the Wikipedia entry at en.wikipedia.org/wiki/Kolmogorov%E2%80%93Smirnov_test until I am left with the number $D_n$, which one, as far as I understand, usually looks up in a table to accept or reject the distribution. $\endgroup$
    – gozero
    Dec 15, 2012 at 1:19
  • $\begingroup$ You might take interest in my answer on how one-sample K-S test is calculated. $\endgroup$
    – ttnphns
    Dec 15, 2012 at 16:35

1 Answer 1

1
$\begingroup$

You are right that you need to compare $D$ to a reference distribution, traditionally (though not very often these days) looked up in a table.

The footnotes to the Wikipedia article you link to include some references to routines that will calculate the reference tables for the statistic (which can be complex) so you can calculate a p value - which is the probability that a value as extreme as you have calculated would have been generated by your reference distribution.

Stats packages will do this automatically, if you can draw on one of these, eg see the following input and output for sample data in R:

> # generate data from a normal distribution, mean=1, standard deviation=1
> x <- rnorm(100,1,1)
> 
> # test - could it have come from a slightly different normal distribution?
> ks.test(x, "pnorm", .8, 1.5)

        One-sample Kolmogorov-Smirnov test

data:  x 
D = 0.1594, p-value = 0.01245
alternative hypothesis: two-sided 

> 
> # test against the distribution it really came from
> ks.test(x, "pnorm", 1, 1)

        One-sample Kolmogorov-Smirnov test

data:  x 
D = 0.0806, p-value = 0.5338
alternative hypothesis: two-sided 

> 
> # test against a uniform distribution
> ks.test(x, "punif", min(x), max(x))

        One-sample Kolmogorov-Smirnov test

data:  x 
D = 0.1499, p-value = 0.02238
alternative hypothesis: two-sided 
$\endgroup$
4
  • $\begingroup$ Thank you for the answer. My problem lies more on the side of understanding what exactly this number $D$ is. I am comparing the CDF of my data to another CDF, then using the supremum of this and compare it to what exactly from a reference distribution? $\endgroup$
    – gozero
    Dec 15, 2012 at 10:24
  • $\begingroup$ You calculate the probability of seeing a more extreme value than $D$ from the reference distribution. That calculation, as Peter Ellis has written, is reflected in the "p-value" number in the output from most K-S test routines. $\endgroup$
    – jbowman
    Dec 15, 2012 at 15:17
  • $\begingroup$ I see, that should have made the thing clear from the beginning. Thank you all! I suppose there is no easy way to get the PDF of the underlying distribution $p(x_0)$, where $x_0$ corresponds to the point which has $P(x_0) = D$? $\endgroup$
    – gozero
    Dec 15, 2012 at 23:44
  • $\begingroup$ Yes, D under the null hypothesis has a distribution that is non-trivial to describe. But there are well documented methods out there for calculating it yourself if you need to for some reason. $\endgroup$ Dec 15, 2012 at 23:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.