Kolmogorov-Smirnov of two heart rate samples

I'm accumulating a lot of vital signs from emergency department patients, and would like to assess if different features yield significantly different distributions.

Eg. for heart rate I have 888.424 measurements (stored in all_hr) for all patients and 321.357 measurements for geriatric patients (stored in g_hr). Summary stats yield:

summary(all_hr$hr) Min. 1st Qu. Median Mean 3rd Qu. Max. 2.00 74.00 87.00 88.56 101.00 242.00 summary(g_hr$hr)
Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
2.00   72.00   85.00   87.77  100.00  207.00

When plotting the ecdfs for these samples I get: I'm trying to comprehend how to use the Kolgomorov-Smirnov ks.test() function in R for this:

ks.test(all_hr$hr,g_hr$hr,alternative="two.sided")

Two-sample Kolmogorov-Smirnov test

data:  all_hr$hr and g_hr$hr
D = 0.0289, p-value < 2.2e-16
alternative hypothesis: two-sided

Warning:
In ks.test(all_hr$hr, g_hr$hr, alternative = "two.sided") :
p-values will be approximate in the presence of ties

So as far as I understand this test, the hypothesis that samples are from different distributions is true?

Now, I've also attempted a similar approach, but grouping patients by speciality ward instead. E.g. here is the ecdfs two randomly drawn 6.000 sample distributions for neurological and gastro-internal patients: Yet, when running ks.test on these two samples, I also get the same result

ks.test(N.vs.hr.rs$hr,S.vs.hr.rs$hr,alternative="two.sided")

Two-sample Kolmogorov-Smirnov test

data:  N.vs.hr.rs$hr and S.vs.hr.rs$hr
D = 0.6307, p-value < 2.2e-16
alternative hypothesis: two-sided

Warninf:
In ks.test(N.vs.hr.rs$hr, S.vs.hr.rs$hr, alternative = "two.sided") :
p-values will be approximate in the presence of ties

So, in summary...is this test a valid way of asserting differences in distributions? And should I have no quarrels with the fact that two very dissimilar ecdf plots yield the same ks.test results?

migrated from stackoverflow.comJul 9 '14 at 12:54

This question came from our site for professional and enthusiast programmers.