[R] KS test and plot max distance between two ecdf curves

maxbre mbressan at arpa.veneto.it
Fri May 25 10:07:01 CEST 2012


Given this example

a<-c(0,70,50,100,70,650,1300,6900,1780,4930,1120,700,190,940,
    
760,100,300,36270,5610,249680,1760,4040,164890,17230,75140,1870,22380,5890,2430)

b<-c(0,0,10,30,50,440,1000,140,70,90,60,60,20,90,180,30,90,
     3220,490,20790,290,740,5350,940,3910,0,640,850,260)


out<-ks.test(log10(a+1),log10(b+1))

# (1) max distance D 
out$statistic

f.a<-ecdf(log10(a+1))
f.b<-ecdf(log10(b+1))

# (2) max distance D 
max(abs(f.a(x)-f.b(x)))


plot(f.a, verticals=TRUE, do.points=FALSE, 
     col="red")
plot(f.b, verticals=TRUE, do.points=FALSE, col="green", add=TRUE)


my questions are:

- how to plot the max distance between the two ecdf curves in the above
given graph?
(sorry but for some reasons I can’t manage that…)

-why of the difference between the max distance D calculated with ks.test()
as in (1) and the max distance “manually” D calculated as in (2)?
(I guess it has something to do with the fact that KS is obtained with a
maximisation that depends on the range of x values not necessarly coincident
in the two different approaches)

thanks

max


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



More information about the R-help mailing list