Skip to content
Prev 295711 / 398503 Next

Kolmogorov-Smirnov test and the plot of max distance between two ecdf curves

Hello,

Try the following.
(i've changed the color of the first ecdf.)


loga <- log10(a+1) # do this
logb <- log10(b+1) # only once

f.a <- ecdf(loga)
f.b <- ecdf(logb)
# (2) max distance D

x <- seq(min(loga, logb), max(loga, logb), length.out=length(loga))
x0 <- x[which( abs(f.a(x) - f.b(x)) == max(abs(f.a(x) - f.b(x))) )]
y0 <- f.a(x0)
y1 <- f.b(x0)

plot(f.a, verticals=TRUE, do.points=FALSE, col="blue")
plot(f.b, verticals=TRUE, do.points=FALSE, col="green", add=TRUE)
## alternatine, use standard R plot of ecdf
#plot(f.a, col="blue")
#lines(f.b, col="green")

points(c(x0, x0), c(y0, y1), pch=16, col="red")
segments(x0, y0, x0, y1, col="red", lty="dotted")
## alternative, down to x axis
#segments(x0, 0, x0, y1, col="red", lty="dotted")


Hope this helps,

Rui Barradas

maxbre wrote
--
View this message in context: http://r.789695.n4.nabble.com/Kolmogorov-Smirnov-test-and-the-plot-of-max-distance-between-two-ecdf-curves-tp4631437p4631438.html
Sent from the R help mailing list archive at Nabble.com.