[R] find parameters for a gamma distribution

Gabor Grothendieck ggrothendieck at myway.com
Sat Jan 1 19:05:44 CET 2005


 <digitalpenis <at> bluebottle.com> writes:

: 
: hello,
: 
: i have just started exploring R as an alternative to matlab for data 
analysis. so far everything is _very_
: promising. i have a question though regarding parameter estimation. i have 
some data which, from a
: histogram plot, appears to arise from a gamma distribution. i gather that 
you can fit the data to the
: distribution using glm(). i am just not quite sure how this is done in 
practice... so here is a simple
: example with artificial data:
: 
: d <- rgamma(100000, 20, scale = 2)
: h <- hist(d, breaks = c(seq(10, 80, 2), 100))
: 
: H <- data.frame(x = h$mids, y = h$density)
: 
: g <- glm(y ~ x, data = H, family = Gamma)
: summary(g)
: 
: Call:
: glm(formula = y ~ x, family = Gamma, data = H)
: 
: Deviance Residuals: 
:     Min       1Q   Median       3Q      Max  
: -3.8654  -2.0887  -0.7685   0.7147   1.4508  
: 
: Coefficients:
:             Estimate Std. Error t value Pr(>|t|)
: (Intercept)  30.4758    26.7258   1.140    0.262
: x             1.0394     0.6825   1.523    0.137
: 
: (Dispersion parameter for Gamma family taken to be 1.343021)
: 
:     Null deviance: 119.51  on 35  degrees of freedom
: Residual deviance: 116.28  on 34  degrees of freedom
: AIC: -260.49
: 
: Number of Fisher Scoring iterations: 7
: 
: now i suppose that the estimates parameters are:
: 
: 	shape = 30.4758
: 	scale = 1.0394
: 
: am i interpreting the output correctly? and, if so, why are these estimates 
so poor? i would, perhaps
: naively, expected the parameters from an artificial sample like this to be 
pretty good.
: 
: my apologies if i am doing something stupid here but my statistics 
capabilties are rather limited!

library(MASS)
?fitdistr
example(fitdistr) # note the gamma example




More information about the R-help mailing list