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
Hi Alex, Try> require(MASS)Loading required package: MASS> b <- c(2039L, 2088L, 5966L, 2353L, 1966L, 2312L, 3305L, 2013L, 3376L,+ 3363L, 3567L, 4798L, 2032L, 1699L, 3001L, 2329L, 3944L, 2568L, + 1699L, 4545L)> fitdistr(b, 'gamma')shape rate 6.4528939045 0.0021887943 (0.7722567310) (0.0001854559) HTH, Jorge On Sat, Aug 6, 2011 at 3:14 PM, 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 > > ______________________________**________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/**listinfo/r-help<https://stat.ethz.ch/mailman/listinfo/r-help> > PLEASE do read the posting guide http://www.R-project.org/** > posting-guide.html <http://www.R-project.org/posting-guide.html> > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]
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, > AlexStraightforward, 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