I have a dataset (vector) to which I would like to fit a gamma distribution (x), which given the shape seems reasonable. The charts below show the histograms of the two dataset: vector and x.

enter image description here

The left is my sample set, the right is a random generated set. I did this as following; first:

    shape     rate  
  4.84279   0.07493 
 (0.21693) (0.00354)

Then I generated the gamma distribution (right chart) as following:

hist(rgamma(10000, shape=4.84279, rate=0.07493),breaks=251)

I would like to change the shape in such a way that the peak gets slimmer, but I can not figure out how to do this. I have tried to modify the shape and rate, but neither of the two put me in the right direction. Does anybody have an advise on how to do this?

  • 2
    $\begingroup$ Your data do not follow a Gamma distribution. At a minimum, you would need a third parameter to shift it. To produce a peaked version, consult the Wikipedia reference and note that the kurtosis ("peakedness") is inversely proportional to the shape parameter. Choosing a value slightly greater than $1$ will do the trick. But why do you need to fit a Gamma distribution to these data in the first place? $\endgroup$
    – whuber
    May 21, 2013 at 14:17
  • $\begingroup$ Your big problem is that the apparent lower limit of your data is much higher than the lower limit of a Gamma random variable (0); this means that a gamma can't fit the observed mean and variance as well as match the peak. As whuber suggests, a third parameter (gamma with location shift) might be sufficient, but you might have to leave the gamma model behind and do something else. $\endgroup$
    – Glen_b
    May 21, 2013 at 23:05

1 Answer 1


The results don't necessarily show that a gamma distribution is a good fit. You might as well as assume that a normal distribution must fit well because you have estimated a mean and a standard deviation.

Your graphical assessment is already showing that a good (if not necessarily the best) gamma shape for these data is systematically different from your data, and tweaking the parameters will at best tweak that, not solve the problem.

I guess you need to explore other distributions. It is difficult to suggest precisely which, but my eyeballing from your graphs is that the gamma is not matching either the skewness or the kurtosis of your data. I would try lognormal.

On graphical technique: I would rather look at a quantile-quantile plot than a histogram. Even with a histogram, simulating from the distribution is not as simple as just superimposing the density function, with parameter estimates plugged in, on the histogram.

A footnote: What is going on near zero? You have a small spike there. Is there a substantive explanation?

(LATER) Picking up a point made by @whuber: the left tail does seem to need more explanation. Perhaps you have a mixture here, a few values near zero, most values about above 25, and there's a story that perhaps should be matched by the analysis. Perhaps that gap is just sampling variation. If you know more, please tell us.

  • $\begingroup$ As this is a distribution of travel time between two points, the value near the zero are (physically) impossible. Thus, the spike near zero must be incorrect data. $\endgroup$
    – Jochem
    May 21, 2013 at 17:52
  • 1
    $\begingroup$ That comment makes a two-parameter gamma seem qualitatively as well as quantitatively inappropriate. See again the comment of @whuber on three-parameter relatives. $\endgroup$
    – Nick Cox
    May 21, 2013 at 18:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.