The Kolmogorov-Smirnov Two-Sample Test:

The Kolmogorov-Smirnov two-sample test is a nonparametric procedure that tests for differences between two distributions.  The null hypothesis for this test is that the two samples are distributed identically (i.e., taken from the same population).  Therefore, the test is sensitive to differences between the two distributions in location (mode, mean, and median), dispersion (variance, range of values), skewness, etc.

The two-sample test measures the agreement between two cumulative distributions.  If two samples have, in fact, been drawn from the same distribution, then the cumulative distributions of both samples should be close to each other, inasmuch as they both should show only random deviations from the overall population distribution.  If the cumulative distributions of the two samples are “too far apart” at any point, this suggests that the two samples come from different populations.

An example using the Kolmogorov-Smirnov test:

The data in Table 1 below are the diameters (in mm) of galls that were collected for two categories: (1) galls with live gall fly larva and (2) galls that were attacked by birds. To perform the Kolmogorov-Smirnov test, proceed as follows.

  1. Arrange the data in two columns as in Table 1 (next page), which tallies each gall and its diameter (in a column of increasing gall diameter) for the two different gall samples.
  2. In a second table (as in Table 2 below), determine the cumulative frequencies (F1 and F2) for the gall sizes in the two samples. For example, in column (2) of Table 2, note that there are 2 measurements for sample 1 that are in the first bin (i.e., the 16-17 mm category). In contrast, there are no such measurements for sample 2 in column (3). For each subsequent entry in columns (2) and (3), respectively, the number of galls of that size is added to the previous total number of galls, to generate the cumulative frequency. Note that the final entry in each column must equal the sample size (n1 and n2, respectively).
  3. Compute the relative cumulative frequencies by dividing the cumulative frequencies in columns (2) and (3) by their sample sizes (n1 and n2). Enter these values into columns (4) and (5), respectively. Note that the final entry in each of these columns must equal 1.00.

KS_data

Gall size = all diameters that are greater than the previous value                                                                          and less than or equal to the value in the cell

  1. Compute d, the absolute value of the difference between the relative cumulative frequencies in columns (4) and (5). Enter this in column (6).
  2. Locate the largest difference, D, in column (6). For this example, D is 0.567 (at arrow).
  3. Calculate the critical value for the Kolmogorov-Smirnov two-sample test (Dcrit) using the formulae in Table 3 below; the numbers in the columns labeled ‘Level of significance’ are the corresponding p values for each calculation. Keep in mind that the lower a p value you can select, the stronger your argument that the two data sets are significantly different. Thus, if your results are significant for a p value of 0.05 (second calculation on the left side of the table), see how low a p value you can select and still have your observed D value greater than the calculated Dcritical for that p

KS_table3

  1. Compare D (from step 5) to the critical value of D obtained in step 6. In this example, the      critical value for D is 0.555 (at a p value of 0.05).  Since the observed D (0.567) is larger than the critical value computed from the expression in Table 3, we can reject the null  hypothesis at the level of significance associated with that calculated Dcritical value. Thus, we  conclude that birds attack larger galls at higher frequency than expected by chance.

Note that a significant K-S test only tells you that the two distributions differ. It does not tell you HOW they differ (i.e., which way the two distributions are shifted relative to one another). Thus, you should also compute the means and medians for your two sample sets prior to evaluating your original hypothesis, to identify the general trends in your data.