[R] Question about Kolmogorov-Smirnov test behavior
Shea Lutton
shea at eagleseven.com
Thu Jan 7 14:09:05 CET 2016
Dear R-Help,
I am trying to understand the output of the KS test on a pair of files. I am trying to determine if the CDF of one distribution is less than (to the left of) the CDF of a second distribution. My problem is that regardless of whether I run A against B, or B against A, the KS output seems to indicate significance that A is less than B AND B is less than A. Can anybody help me understand where my mistake is or if I am misinterpreting the results?
Here is my code:
file_a = readLines("./file_a.txt")
file_b = readLines("./file_b.txt")
a <- as.numeric(file_a)
b <- as.numeric(file_b)
ks.test(b, a, alternative = "less")
ks.test(a, b, alternative = "less")
And here is the output:
Two-sample Kolmogorov-Smirnov test
data: b and a
D^- = 0.087769, p-value < 2.2e-16
alternative hypothesis: the CDF of x lies below that of y
Two-sample Kolmogorov-Smirnov test
data: a and b
D^- = 0.085083, p-value < 2.2e-16
alternative hypothesis: the CDF of x lies below that of y
> plot(ecdf(a), col = "blue")
> plot(ecdf(b), add = TRUE, col = "red", lty = 1, pch = 26)
> plot(density(a))
> lines(density(b), col = "red")
My data files can be found here, they are simple columns of numbers.
file_a.txt : http://pastebin.com/e3bmnEDt
file_b.txt : http://pastebin.com/5VBzHRXZ
Many thanks,
____________________________
Shea Lutton
Chicago, IL
More information about the R-help
mailing list