[R] Kolmogorov-Smirnov test, which one to use?

Greg Snow Greg.Snow at imail.org
Thu Aug 5 19:16:00 CEST 2010


It is not clear what question you are trying to answer.  Perhaps if you can give us an explanation of your overall goal then we can be more helpful.

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at imail.org
801.408.8111


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Roslina Zakaria
> Sent: Wednesday, August 04, 2010 8:34 PM
> To: r-help at r-project.org
> Subject: [R] Kolmogorov-Smirnov test, which one to use?
> 
> Hi,
> 
> I have two sets of data, an observed data and generated data.
> The generated data is obtained from the model where the parameters is
> estimated
> from the observed data.
> 
> So I'm not sure which to use either
> one-sample test
> ks.test(x+2, "pgamma", 3, 2) # two-sided, exact
> 
> or
> 
> two-sample test
> ks.test(x, x2, alternative="l")
> 
> If I use the one-sample test I need to specified the model which I
> don't have in
> my case.
> 
> Actually I use the two-sample test and when I compare with what I got
> from using
> Chi-square test the result is too different.
> 
> Data:
> 
>       obs_data  pre_gam
>  [1,]       93  25.6770
>  [2,]      115 127.9095
>  [3,]      125 151.6845
>  [4,]      120 146.9295
>  [5,]      106 107.9385
>  [6,]      101 107.4630
>  [7,]       75  86.5410
>  [8,]       58  55.6335
>  [9,]       46  43.7460
> [10,]       38  32.8095
> [11,]       31  16.1670
> [12,]       17  18.5445
> [13,]       10   9.0345
> [14,]       16  20.9220
> 
> Results:
> > chisq.test(obs_data, p = pre_gam, rescale.p = TRUE)
>         Chi-squared test for given probabilities
> data:  obs_data
> X-squared = 205.4477, df = 13, p-value < 2.2e-16
> 
> > ks.test(obs_data,pre_gam)
>         Two-sample Kolmogorov-Smirnov test
> data:  obs_data and pre_gam
> D = 0.2143, p-value = 0.9205
> alternative hypothesis: two-sided
> 
> 
> Am I doing the right thing?
> 
> Thank you so much for your help.
> 
> 
> 
> 	[[alternative HTML version deleted]]



More information about the R-help mailing list