Kolmogorov-Smirnov Test – Addressing Stability Issues with Small and Large Values in R

kolmogorov-smirnov testnormality-assumptionr

Out of curiosity, I realised that the Kolmogorov-Smirnov normality test returns two very different p-values depending on whether the dataset has small or large numbers. Is this normal and is there a number size limit for this test? From what I saw, the Shapiro-Wilk test was much more stable.

I tried this

ks.test(c(0.5379796,1.1230795,-0.4047321,-0.8150001,0.9706860),"pnorm")

One-sample Kolmogorov-Smirnov test

data:  c(0.5379796, 1.1230795, -0.4047321, -0.8150001, 0.970686)

D = 0.3047, p-value = 0.6454

alternative hypothesis: two-sided

And then I multiplied each value by 100



ks.test(c(53.79796,112.30795,-40.47321,-81.50001,97.06860),"pnorm")

    One-sample Kolmogorov-Smirnov test

data:  c(53.79796, 112.30795, -40.47321, -81.50001, 97.06860)

D = 0.6, p-value = 0.03008

alternative hypothesis: two-sided

With the same data, the Shapiro-Wilk test returns a p-value of 0.3999.

Best Answer

The ways you’ve coded it, you’re asking the KS test about a null hypothesis that the distribution is $N(0,1)$. In the first set of numbers, that looks plausible. Consequently, the p-value is high. In the second set of numbers, that does not seem to be the case. Numbers like those don’t typically come from a $N(0,1)$ distribution. Consequently, the p-value is low.

By multiplying by a factor, you’ve changed the variance. Since the KS test considers all aspects of the distribution, variance included, the test correctly regards the two data sets as different.

The reason that Shapiro-Wilk is more stable is because it evaluates normality. Multiplying by a positive factor does not change the normality, so Shapiro-Wilk will not have the same kind of sensitivity to a variance change that KS has.