# Kolmogorov-Smirnov test rejects the null, but visualy samples and CDF appear identical

I have simulated 1,000 samples in R and want to test if they where drawn from the distribution function.

$G(x)= 1-F_{\chi^2(1/(1-\alpha),b(e^{-(r-q)T}x)}(b(S_0)), \forall x\ge0$

$b(y)=\dfrac{2(r-q)y^{2(1-\alpha)}}{\sigma^2(1-\alpha)(1-e^{-2(r-q)(1-\alpha)T}}$

If i plot the empirical cdf using ecdf against $G(X)$

samples      #Vector containing 1000 samples
cumDesFunc   #function G(x), where the values beside x are given

ecdfFunc <- ecdf(samples)

curve(expr = ecdfFunc, from = 0, to = 1000, ylab = cumProb)


I get two CDF's which are almost identical

However when i do a Kolmogorov-Smirnov test i get the following output

ks.test(x = samples, y = cumDesFunc)

>>data: samples
>>D = 0.17202, p-value = p-value < 2.2e-16
>>alternative hypothesis: two-sided


So i overwhelmingly reject the null hypothesis that the samples are drawn from the $G(x)$ distribution.

From my (limited) understanding, D should represent the maximum absolut distance between the x and y's cumulative distribution function, but surely this is no where near 0.17202.

So my question is therefore: How can the test reject the null hypothesis and what is the interpretation of D?

• Without seeing the function cumDesFunc or the data, it's hard to say, but looking at the far left of your chart, it seems possible that you have a spike of data such that the 18th percentile of the data is at the 1st percentile of the CDF or vice versa. That's where I would look to start. – jbowman Oct 1 '17 at 17:49