MATLAB Answers

Kolmogorov Smirnov test help?

55 views (last 30 days)
arthurk on 20 Jan 2020
Edited: Adam Danz on 21 Jan 2020
I have the test data below, the kstest(x) function compares the distribution of the data below against a standard normal distribution (mean of 0 and std of 1). Is it better to simply call the function as kstest(x) or correct the data so that its standard deviation and mean is 1 and 0 respectively?
Also when doing so, do you guys get probability as 0.1267 for uncorrected and 0.6506 for corrected?
It's just that I got significantly different values earlier.
Another question is that are the probabilities realistic? When plotting the values on excel the graphs are more or less normally distributed, however they don't pass the significance level of 5%.


Sign in to comment.

Answers (1)

Adam Danz
Adam Danz on 20 Jan 2020
Edited: Adam Danz on 20 Jan 2020
"Is it better to simply call the function as kstest(x) or correct the data so that its standard deviation and mean is 1 and 0 respectively"
The one-sample Kolmogorov-Smirnov test tests the null hypothesis that the data comes from a standard normal distribution (mean 0, std 1). If you correct your data so that it does have a mean of 0 and std of 1, what's the point of testing it?
If you want a more general test that your data come from a normal distribution with any mean or std, use the Anderson-Darling test or the Lilliefors test.
Null hypotheses (from the documentation)
One-sample Kolmogorov-Smirnov test: the data in vector x comes from a standard normal distribution (mean 0, std 1).
Lilliefors test: the data in vector x comes from a distribution in the normal family.
Anderson-Darling test: the data in vector x is from a population with a normal distribution.
If the null hypothesis is rejected (an outcome of 1 for all three tests), the data do not come from those distributions at a 5% significance level.
Note that if there is a failure to reject the null hypothesis (an outcome of 0 for all three tests), that does not indicate that the data do come from those distributions. This is a common misunderstanding of interpretting hypothesis testing.
Here's a domonstration showing the difference between the kstest and the two other ones.
% Create a data from a normal distributions with
% mean 0 and std 1.
x0 = randn(1,10000);
% Use that same exact data to create a normal distribution
% with mean 5 and std 2
x1 = x0*2 + 5;
% Plot both distributions
hold on
Notice how this creates two normal distribtions. The blue distribtuion has a mean of 0 and std of 1 while the reddish distribution has a mean of 5 and std of 2 (approximately).
% Look at the results of the ks-tests
ks0 = kstest(x0) % fail to reject
ks1 = kstest(x1) % reject null hyp
% Look at the results of the Lilliefors test
lt0 = lillietest(x0) % fail to reject
lt1 = lillietest(x1) % fail to reject
% Look at the results from the Anderson-Darling test
ad0 = adtest(x0) % fail to reject
ad1 = adtest(x1) % fail to reject
As you can see, the blue distribution is identified as a standard normal distribution and rightfully so since it has a mean of 0 and std of 1 (approximately) while the other distribution does not. However, both distributions are normal as indicated by both the lillietest() and adtest().


Show 1 older comment
Adam Danz
Adam Danz on 20 Jan 2020
In case you haven't seen the update in my answer, I copy-pasted the wrong comments next to the normality tests. They are corrected now.
When any of the tests output a value of 1 (true) that means you are rejecting the null hypothesis (that the values come from those distributions).
Since the data in my demo are indeed good fits to normal distributions, they fail to reject the null hypothesis except for the kstest() on the reddish distribution which clearly isn't a standard normal distribution.
arthurk on 21 Jan 2020
Hmmm, thank you for the correction.
Your clarification has contradicted my understanding of the null hypothesis, so I hope you can help me clear it up.
The definition of the null hypothesis: A null hypothesis is a type of hypothesis used in statistics that proposes that no statistical significance exists in a set of given observations.
Therefore, I would believe that between a normally distributed data and a crude looking one like the examples you gave. The tests would come back true, because there is relationship between the two. i.e it rejects the null hypothesis
Failing to reject would mean otherwise.
Where have I gone wrong?
Adam Danz
Adam Danz on 21 Jan 2020
That definition from Investopedia isn't precise enough. Even wiki's definition isn't precise enough: the null hypothesis is a general statement or default position that there is nothing significantly different happening.
To be more precise, the null hypothesis is typically a test statement that there is no difference in what you're testing at some arbitrary significance level.
The key differences between this definition and other others are
  1. The null hypothesis is not a general statement. On the contrary. It's specific to the test you're testing.
  2. It doesn't test that "nothing is significant" or "no significance exists". Instead, it only tests whatever specific property that the test is designed to test and it bases the significance on an arbitrary alpha value (ie, p=0.05).
These very common misconceptions are why 100s of scientists, statisticians, and researchers have supported a movement to stop significance testing.
Critically, the null hpothesis is whatever the test deems it to be. Look at the matlab documentation for the kstest:

Sign in to comment.

Sign in to answer this question.