rmcelreath / rethinking

Statistical Rethinking course and book package
2.14k stars 603 forks source link

Gamma parameterisation #410

Open lukaseamus opened 1 year ago

lukaseamus commented 1 year ago

I am using a Gamma likelihood in ulam(), a distribution which is only briefly touched on in the book. I was surprised to find out by trial and error and repeated checking with stancode() that ulam() parameterises the Gamma likelihood as Gamma(mean, scale) rather than the Stan convention Gamma(shape, rate). stancode() showed me that this is internally reparameterised as Gamma(mean/scale, 1/scale) to work with Stan's convention, since shape = mean/scale and rate = 1/scale. Am I correct in my deductions? If yes, I am curious to know the reason behind this choice and why it is "hidden". Why not Gamma(shape, rate), Gamma(shape, scale) or Gamma(mean, sd)? Thanks in advance for your insight.

Edit: To generalise my previous questions, is it possible to reparameterise distributions such as Gamma or Beta in ulam() @rmcelreath? Say, in addition to the Gamma example above, I wanted to reparameterise the Beta distribution as Beta(mean, count) according to https://mc-stan.org/docs/2_21/stan-users-guide/reparameterizations.html#.