[R] Gamma distribution parameter estimation
J. R. M. Hosking
JRMH001 at gmail.com
Sun Aug 7 21:15:07 CEST 2011
On 2011-08-06 15:14, Alexander Engelhardt wrote:
> Hey,
> I have a set of income data which I'd like to fit to a gamma
> distribution. How can I estimate the two parameters of the gamma
> distribution for a vector, e.g.
>
> c(2039L, 2088L, 5966L, 2353L, 1966L, 2312L, 3305L, 2013L, 3376L,
> 3363L, 3567L, 4798L, 2032L, 1699L, 3001L, 2329L, 3944L, 2568L,
> 1699L, 4545L)
>
> I sense this will be a very easy one-liner, but my searching didn't come
> up with results yet.
>
> Thanks in advance,
> Alex
Straightforward, using the method of L-moments:
x <- c(2039L, 2088L, 5966L, 2353L, 1966L, 2312L, 3305L, 2013L, 3376L,
3363L, 3567L, 4798L, 2032L, 1699L, 3001L, 2329L, 3944L, 2568L,
1699L, 4545L)
library(lmom)
(pargam <- pelgam(samlmu(x))) # Parameter estimates
evplot(x, quagam, pargam) # check goodness of fit
Note that allowing the distribution to have a nonzero lower bound,
by fitting a 3-parameter gamma distribution ("Pearson type III" in
the terminology of package lmom), gives a visually much better fit:
evdistq(quape3, pelpe3(samlmu(x)), col='blue')
J. R. M. Hosking
More information about the R-help
mailing list