[R] gamma parameter estimation [was "ks.test"]

Prof Brian D Ripley ripley at stats.ox.ac.uk
Mon Nov 12 19:14:31 CET 2001

```On Mon, 12 Nov 2001, Martin Maechler wrote:

> >>>>> "AOlinto" == aolinto  <aolinto at bignet.com.br> writes:
>
>     AOlinto> Dear Dr. Maechler, Thanks for your e-mail.
>
>        MM> As the function name suggests and help(gamma.shape) clearly says,
>        MM> its estimating the shape parameter alpha, and *ITS* standard error
>        MM> which is not at all the same as the scale parameter you need (and
>        MM> in your case get from coef(Lt.fit) !
>
> {to R-help;  I allow myself to CC this back to R-help again..}
>
>     AOlinto> As you stated, I was not using the scale parameter, but the SE
>     AOlinto> of the shape parameter.
>
>     AOlinto> Nevertheless, in my exemple, using coef(Lt.fit) I got the
>     AOlinto> value 0.01703055(Intercept) which doesn't seem to be the scale
>     AOlinto> parameter either. I read carefully some books and the R help
>     AOlinto> but I couldn't find a solution (probably because I'm not a
>     AOlinto> statistician and, as biologist, I often have problems with
>     AOlinto> mathematical language - but I'm trying to do my best).
>
>     AOlinto> Would you please explain me how to get the scale parameter
>     AOlinto> from coef?
>
> Here is a valid R script I did for you  [ ~/R/MM/STATISTICS/gamma-mle.R ]:
> the comments should contain all the explanations:

[...]

Another way to do this is to use fitdistr in package MASS (recent version).
Unfortunately because R uses incompatible arguments with S for [dqpr]gamma
prior to 1.4.0, the default usage needs R-devel

> set.seed(35)
> xx <- rgamma(10000, shape = 2, scale = 0.1)
> fitdistr(xx, "gamma")
shape         rate
1.97356054   9.95524474
(0.02589806) (0.14862019)

One can make it work in R 1.3.1 by specifying starting values.

> fitdistr(xx, "gamma", list(shape = 2, scale = 0.1))
shape         scale
1.973444351   0.100454939
(0.025871453) (0.001497758)

These are MLEs, with standard errors based on the observed information.

--
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._

```