Somebody already did the job for you. Try fitdistr{MASS} i.e.
x=scan("clipboard")#Read your data from clipboard
sh=(mean(x))^2/var(x)
sc=var(x)/mean(x)
fitdistr(x,"gamma", list(shape=sh, scale=sc))
Now you probably know that you have to be carfeul when estimating
distribution parameters from such a small number of observations.
PS: this is a very "popular" question so in the future before you post
a
question try RSiteSearch() i.e. RSiteSearch("fit gamma") gave me 273
hits
Cheers
Francisco
>From: Nadja Riedwyl <riedwyl at giub.unibe.ch>
>To: r-help at stat.math.ethz.ch
>Subject: [R] fit data with gammadistribution
>Date: Mon, 12 Sep 2005 12:58:00 +0200
>
>hello
>my data is
>data2:2743 4678 21427 6194 10286 1505 12811 2161 6853 2625 14542
>694
>11491 14924 28640 17097 2136 5308 3477 91301 11488 3860 64114 14334
>
>by calculating
>shape<-(mean(data2))^2/var(data2)
>scale<-var(data2)/mean(data2)
>
>i get the idea what the parameters of the gammadistribution would be.
>but if i try using the method mle() i get stock and i don't know, how to
>make
>it work. can anybody help me? thank you very much, indeed.
>Nadja
>I tried so fare
>
>ll<-function(lambda,alfa)
>{n<-24
>x<-data2
>-n*alfa*log(lambda)+n*log(gamma(alfa))-(alfa-1)*sum(log(x))+lambda*sum(x)
>est<-mle(minuslogl=ll,start=list(lambda=29827.51,alfa=0.4954725))
>summary(est)
>
>NaN's are produced with optim, i just don't know how to avoid this!
>
>______________________________________________
>R-help at stat.math.ethz.ch mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide!
>http://www.R-project.org/posting-guide.html