Skip to content

fit data with gammadistribution

2 messages · Nadja Riedwyl, Francisco J. Zagmutt

#
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!
#
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