2
$\begingroup$

Here are the codes I input into R:

X = rnorm(10000)
Y = rchisq(10000, 1)

ks.test(X, rchisq(1,1))

Two-sample Kolmogorov-Smirnov test

data:  X and rchisq(1, 1)
D = 0.6369, p-value = 0.812
alternative hypothesis: two-sided

However, if we do ks.test(X, Y), the statistic is highly significant.

I must be using the KS test wrong somehow, but how?

PS I was meant to write pchisq rather than rchisq

$\endgroup$

1 Answer 1

4
$\begingroup$

When you did ks.test(X,Y) your $Y$ variable consisted of 10000 values.

When you did ks.test(X,rchisq(1,1)) your $Y$ variable consisted of a single value:

$\quad\quad$enter image description here

Why would you expect those two things to give similar p-values? Their sample sizes are very different, and the corresponding test statistics will be quite different:

enter image description here


I meant to write pchisq in there

While the statistic may be very close, you won't get the same p-values then either!

Consider that the asymptotic critical values for a one sample test will be $Q^{-1}(\alpha)\cdot\sqrt{\frac{1}{n}}$ and those for the two sample test will be $Q^{-1}(\alpha)\cdot\sqrt{\frac{1}{n_1}+\frac{1}{n_2}}$ (where $$Q(x) = 1 - 2\sum_{k=1}^{\infty}(-1)^{k-1}e^{-2k^2x^2}$$ is the K-S asymptotic distribution).

$\endgroup$
3
  • $\begingroup$ Oh, that is so bad, I am meant to write pchisq in there! $\endgroup$
    – Lost1
    Sep 29, 2014 at 9:32
  • $\begingroup$ See the updates to my answer. $\endgroup$
    – Glen_b
    Sep 29, 2014 at 9:54
  • $\begingroup$ You may like to update your question to ask the pchisq one as a followup to your present question. $\endgroup$
    – Glen_b
    Sep 29, 2014 at 10:08

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.