I have a series of data sets whose distributions I would like to quantitatively compare using Mathematica. For the purpose of this explanation, I will show two extreme comparisons (4 data sets total), where visually and experimentally the first comparison should show a greater dissimilarity than the second comparison.
Histogram[{t0sync[[1 ;; 1000]], 1.02 t8sync[[1 ;; 1000]]}, {"Raw", 500}, PlotRange -> {{0, 5000}, {0, 100}}]
Histogram[{t0desync[[1 ;; 1000]], 1.02 t8desync[[1 ;; 1000]]}, {"Raw", 500}, PlotRange -> {{0, 5000}, {0, 100}}]
DiscretePlot[{CDF[EmpiricalDistribution[t0sync[[1 ;; 1000]]], x], CDF[EmpiricalDistribution[1.02 t8sync[[1 ;; 1000]]], x]}, {x, 0, 5000}]
DiscretePlot[{CDF[EmpiricalDistribution[t0desync[[1 ;; 1000]]], x], CDF[EmpiricalDistribution[1.02 t8desync[[1 ;; 1000]]], x]}, {x, 0, 5000}]
Looking at the CDFs, I would expect the Kolmogorov-Smirnov Test of the first comparison should result in ~0.8 and the second comparison to result in ~0.1, but I am getting ~0 for both.
KolmogorovSmirnovTest[t0sync[[1 ;; 1000]], 1.02 t8sync[[1 ;; 1000]]]
3.069630061892*10^-375
KolmogorovSmirnovTest[t0desync[[1 ;; 1000]], 1.02 t8desync[[1 ;; 1000]]]
1.18559*10^-7
Does anyone have any insight as to why I'm getting these low of values when the CDFs indicate otherwise? Also, I'm not sure what is the easiest way to share the 4 datasets of 1000 points each for this example - please advise.
KolmogorovSmirnovTest
, I don't see your usage: my understanding is that the second argument should be a distribution (e.g.LaplaceDistribution[1,2]
). I don't see why you even get a result. $\endgroup$KolmogorovSmirnovTest[data1, data2]
option but that is given as one of the examples. Yes, that option should be made more explicit. $\endgroup$KolmogorovSmirnovTest
returns a P-value which is close to zero for both. P-values are not of much use if you want to characterize the "size" of the difference between two distributions. A P-value just tells you the probability of seeing at least as extreme a sample difference in CDF's under the assumption that the samples are from the same distribution. That's usually not very interesting. You'd be better off to pick some summary statistics (mean, median, standard deviation, interquartile range, etc.) that have meaning to whatever subject matter you're dealing with and compare those. $\endgroup$