[R] Kolmogorov-Smirnov test help

Uwe Ligges ligges at statistik.uni-dortmund.de
Tue Nov 22 11:28:24 CET 2005


Lisa Dowson wrote:

> Hi
> 
> I am conducting 2-sample Kolmogorov Smirnov tests for my Masters project to
> determine if two independant tree populations have the same size-class
> distribution or not. The trees have been placed into size-class categories
> based on their basal diameters. Once I started running the stats on my data,
> I got confused with the results. Just to show an example of what I was
> testing I ran stats comparing population1 to population 2. and then
> comparing population 3 to population 2.
>   Popn1 Popn2 Popn3  880 769 0  34 40 19  10 24 19  2 2 8  2 2 36  0 0 0

If I interpret your data correctly, we can look at the step functions by:

  plot.ecdf(x[,1], xlim=c(-10, 900), verticals=TRUE)
  plot.ecdf(x[,2], xlim=c(-10, 900), col.hor="blue", col.vert="blue", 
add=TRUE, verticals=TRUE)
  plot.ecdf(x[,3], xlim=c(-10, 900), col.hor="red", col.vert="red", 
add=TRUE, verticals=TRUE)

and see that there is no good reason why the test should reject the Null 
  for so few (6!) observations.

Note that you need at least 4 observations in each group to be able to 
reject anything at alpha=0.05 even for completely different distributions:

  ks.test(1:3, 101:103)


> Common sense tells me that P1 and P2 are similar and that P3 and P2 are
> dissimilar. However, for the P1 versus P2 test I am getting p-value of 1
> (saying they are strongly similar -what I expected) and for the P3 versus P2
> test, a p-value of 0.9307 (saying they are strongly similar, but slightly
> less similar than the other test- not what I expected at all). However,
> common sense tells me that P3 and P2 are not similar at all and that I
> should be expecting a far lower p-value for the test comparing P3 and P2.

Sometimes common sense is dangerous. Sort your data, look again, look 
into the plot, and rethink...

Uwe Ligges




> Any help would be greatly appreciated
> 
> Thanks
> 
> Lisa
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html




More information about the R-help mailing list