[R] ks.test

aolinto@bignet.com.br aolinto at bignet.com.br
Fri Nov 9 15:04:48 CET 2001


Dear R-List members,

I want to check if a set of measurements follows better a 
gamma or a lognormal distribution (see data below).

Using shapiro.test I can test for normality (shapiro.test(log
(Lt)).

To test for gamma (and normal) distribution I would use 
ks.test but I need to specify its shape and scale. How should 
I calculate these values in R?

I tried

> Lt.fit <- glm(Lt ~ 1, family=Gamma)
> gamma.shape(Lt.fit)
                
Alpha: 18.851759
SE:     3.737472

> ks.test(Lt,"pgamma",18.851759,3.737472)

        One-sample Kolmogorov-Smirnov test

data:  Lt 
D = 0.4063, p-value = 1.358e-07 
alternative hypothesis: two.sided

But I'm not sure about it. Using the software Statistica I got 
shape = 18.853508 and scale = 3.114434 and

> ks.test(Lt,"pgamma",18.853508,3.114434)

        One-sample Kolmogorov-Smirnov test

data:  Lt 
D = 0.1122, p-value = 0.5553 
alternative hypothesis: two.sided

With

> hist(Lt, freq=F)
> curve(dgamma(x,18.851759,3.737472),add=T,col="blue") 
> curve(dgamma(x,18.853508,3.114434),add=T,col="red") 

I could see that Statistica's parameters fitted better to Lt 
distribution. Probably I'm doing something wrong in R.

Thanks in advance,

Antonio Olinto

--------
> sample.dat

      Lt
1   60.0
2   79.0
3   48.0
4   57.0
5   84.0
6   57.0
7   57.0
8   43.0
9   58.0
10  63.0
11  66.0
12  53.5
13  60.0
14  62.0
15  41.0
16  65.0
17  50.0
18  85.0
19  68.0
20  46.0
21  45.0
22  59.0
23  53.0
24  37.0
25  61.0
26 106.0
27  47.0
28  49.0
29  56.0
30  42.0
31  54.0
32  87.0
33  51.0
34  78.0
35  45.0
36  49.4
37  67.0
38  84.5
39  54.0
40  57.0
41  49.0
42  57.0
43  59.0
44  83.0
45  43.5
46  42.5
47  59.5
48  65.0
49  44.0
50  49.0


-----------------------------------------------------



-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list