[R] Goodness of fit for gamma distributions

Remko Duursma remkoduursma at gmail.com
Wed Jan 28 00:32:08 CET 2009


It sounds like you just want to graph it though. For gammas, it's nice
to graph the log of the density, because
the tail is so thin and long, so you don't see much otherwise:

mydata <- rgamma(10000, shape=1.1, rate=2.5)

# now suppose you fit a gamma distribution, and get these estimated parameters:
shapeest <- 1.101
rateest <- 2.49

h <- hist(mydata, breaks=50, plot=FALSE)
plot(h$mids, log(h$density))
curve(log(dgamma(x, shape=shapeest, rate=rateest)), add=TRUE)


#Remko


-------------------------------------------------
Remko Duursma
Post-Doctoral Fellow

Centre for Plant and Food Science
University of Western Sydney
Hawkesbury Campus
Richmond NSW 2753

Dept of Biological Science
Macquarie University
North Ryde NSW 2109
Australia

Mobile: +61 (0)422 096908



On Wed, Jan 28, 2009 at 1:13 AM, Dan31415 <d.m.mitchell at reading.ac.uk> wrote:
>
> Thanks for that Remko, but im slightly confused because isnt this testing the
> goodness of fit of 2 slightly different gamma distributions, not of how well
> a gamma distribution is representing the data.
>
> e.g.
>
> data.vec<-as.vector(data)
>
> (do some mle to find the parameters of a gamma distribution for data.vec)
>
> xrarea<-seq(-2,9,0.05)
> yrarea<-dgamma(xrarea,shape=7.9862,rate=2.6621)
>
> so now yrarea is the gamma distribution and i want to compare it with
> data.vec to see how well it fits.
>
> regards,
> Dann
>
>
> Remko Duursma-2 wrote:
>>
>> Hi Dann,
>>
>> there is probably a better way to do this, but this works anyway:
>>
>> # your data
>> gamdat <- rgamma(10000, shape=1, rate=0.5)
>>
>> # comparison to gamma:
>> gamsam <- rgamma(10000, shape=1, rate=0.6)
>>
>> qqplot(gamsam,gamdat)
>> abline(0,1)
>>
>>
>> greetings
>> Remko
>>
>>
>> -------------------------------------------------
>> Remko Duursma
>> Post-Doctoral Fellow
>>
>> Centre for Plant and Food Science
>> University of Western Sydney
>> Hawkesbury Campus
>> Richmond NSW 2753
>>
>> Dept of Biological Science
>> Macquarie University
>> North Ryde NSW 2109
>> Australia
>>
>> Mobile: +61 (0)422 096908
>>
>>
>>
>> On Tue, Jan 27, 2009 at 3:38 AM, Dan31415 <d.m.mitchell at reading.ac.uk>
>> wrote:
>>>
>>> I'm looking for goodness of fit tests for gamma distributions with large
>>> data
>>> sizes. I have a matrix with around 10,000 data values in it and i have
>>> fitted a gamma distribution over a histogram of the data.
>>>
>>> The problem is testing how well that distribution fits. Chi-squared seems
>>> to
>>> be used more for discrete distributions and kolmogorov-smirnov seems that
>>> large sample sizes make it had to evaluate the D statistic. Also i
>>> haven't
>>> found a qq plot for gamma, although i think this might be an appropriate
>>> test.
>>>
>>> in summary
>>> -is there a gamma goodness of fit test that doesnt depend on the sample
>>> size?
>>> -is there a way of using qqplot for gamma distributions, if so how would
>>> you
>>> calculate it from a matrix of data values?
>>>
>>> regards,
>>> Dann
>>> --
>>> View this message in context:
>>> http://www.nabble.com/Goodness-of-fit-for-gamma-distributions-tp21668711p21668711.html
>>> Sent from the R help mailing list archive at Nabble.com.
>>>
>>> ______________________________________________
>>> R-help at r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide
>>> http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>>
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>>
>
> --
> View this message in context: http://www.nabble.com/Goodness-of-fit-for-gamma-distributions-tp21668711p21686095.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>




More information about the R-help mailing list