1
$\begingroup$

So a classmate and I are working with the same data and code for a problem in a data analysis class. My code for this section looks like this:

aml <- c(1.56, 1.28, 1.94, 1.15, 1.31, 1.92, 0.91, 0.96)
natl <- c(1.17,0.76, 1.24, 1.01, 1.26, 1.18, 0.80)
ks.test(aml, natl, alternative = "less")

When I run this code I get

D^- = 0.625, p-value = 0.05411

When he runs the code he gets

D^- = 0.625, p-value = 0.027055

There is no difference in our inputs, however, where my output says "Two-sample Kolmogorov-Smirnov test," His output says " Exact Two-sample Kolmogorov-Smirnov test."

At first I tried to see if I could get the same result as him by using:

ks.test(aml, natl, alternative = "less", exact = T)

But this didn't change anything. He also tried using:

ks.test(aml, natl, alternative = "less", exact = F)

But he still got his original answer.

We've tried everything to reconcile this difference. We've tried sweeping environments, restarting R, checking our numbers, etc. etc. etc. Does anyone know what's happening here?

$\endgroup$

2 Answers 2

1
$\begingroup$

Your classmate obtains a p-value which is exactly half of the one you have. This is precisely what would happen if you run the test with two-sided as value of alternative and they run it with either less or greater (i.e. one-sided).

Are you really-totally-absolutely-100% sure that you use alternative = "less"? Because given that two-sided is the default value for this parameter, any typo in either "alternative" or "less" could probably cause this result.

$\endgroup$
2
  • $\begingroup$ Yeah, we've noticed that the two values differ by a factor of two, but there's no typo. The only difference is that his output specifies that an exact test was performed and mine doesn't. $\endgroup$ Commented Nov 11, 2022 at 18:47
  • $\begingroup$ @SpaceManSpiff the exact parameter can't explain this difference as far as I know. Then there must some very specific difference with the data, I guess. $\endgroup$
    – Erwan
    Commented Nov 12, 2022 at 15:23
0
$\begingroup$

I just poked around with the data you posted and can't get p-value = 0.027055 regardless of the settings. If I had to guess, this is a typo or data problem

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.