I have plotted the the PDF for a Gamma Distribution with various parameters (e.g. 3 and 5) using Manipulate:

  Plot[PDF[GammaDistribution[α, β], x], {x, -1, 20}], 
  { α, -1, 8}, { β, -1, 6}]

However, the plots that I get are quite different to what I get using R and which I know to be correct. For example the PDF with $\Gamma(3,5)$ should have a peak in the curve at 0.4. The plot that Mathematica produces gives me a peak that is more like 11.

Does anybody have any ideas what I am doing wrong here?


closed as off-topic by user9660, MarcoB, RunnyKine, LLlAMnYP, m_goldberg May 3 '16 at 14:13

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Community, MarcoB, RunnyKine, LLlAMnYP, m_goldberg
If this question can be reworded to fit the rules in the help center, please edit the question.

  • $\begingroup$ Any reason why you are not using the built-in GammaDistribution ? $\endgroup$ – Sektor Feb 24 '14 at 13:50
  • 4
    $\begingroup$ You're using a shape/scale parametrization (and getting the correct result). Most likely R is using a shape/rate parametrization. Try alpha = 3, beta = 1/5 to get the PDF you are looking for. $\endgroup$ – Simon Woods Feb 24 '14 at 14:13
  • $\begingroup$ As Simon said, you should verify R's implementations of Gamma and make sure that the arguments are same. There's an example where the implementation differed between MATLAB and Mathematica, so it's not uncommon. $\endgroup$ – rm -rf Feb 24 '14 at 14:22
  • $\begingroup$ Are you by any chance the same person who asked this question? If not, take a look at the answers there. $\endgroup$ – Szabolcs Feb 24 '14 at 14:24

In Mathematica, the PDF of a GammaDistribution[a,b] is proportional to $$x^{a-1} e^{-\frac{x}{b}},$$ as described in the documentation.

In R, dgamma(x, shape=a, rate=r) is a PDF proportional to

$$x^{a-1} e^{-r x},$$

again as described in the documentation.

R's rate $r$ is the same as Mathematica's $1/b$. Just make sure you use these parameters correctly. Or use the scale parameter of R, as in dgamma(x, shape=a, scale=b).

For many such functions there's no universal agreement on what is the meaning of the first, second, etc. parameters. Always be sure to look up the notational conventions used by the book you are reading or the software you are using.


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