# Prior Gamma distribution: Select appropriate alpha given beta and median

I am trying to programatically select a prior distribution from the Gamma family of distributions. The primary criteria that I need to satisfy is that the median of the distribution should be a given value $X$ (i.e. such that it's equally probable to have a parameter value above $X$ or below $X$)

Additionally, because I'm using the distribution as a conjugate prior for a Poisson distribution's lambda, and I know how much relative weight I want to give to the prior relative to the subsequent observations, I think I know what an appropriate $\beta$ parameter is (though I could be wrong on this point, feel free to make comments if I'm thinking about that incorrectly).

So essentially my problem becomes how to select an appropriate $\alpha$ such that the median is $X$. The way I've considered this seems to work well to get a good prior distribution when constraining the mean (or even mode), but technically, I should be constraining the median. Is this possible formulaicly, or would I need to resort to some kind of computational search to find the right value?

• Which form of the gamma are you discussing (is $\beta$ the scale or the rate?) – Glen_b -Reinstate Monica Mar 11 '14 at 22:39
• Just for reference... I believe rate. The one mentioned in "$\alpha$ total occurrences in $\beta$ intervals" as interpretation of hyperparameters for the Poisson distribution – Fabio Beltramini Mar 12 '14 at 22:36
• I may be misunderstanding the phrasing but that looks like scale to me. What's the mean - $\alpha\beta$ or $\alpha/\beta$? (alternatively see the explicit functional forms below) – Glen_b -Reinstate Monica Mar 12 '14 at 22:41
• In the parameterization I'm using, the mean of the gamma distribution would be $\alpha$/$\beta$ – Fabio Beltramini Mar 12 '14 at 23:02
• Okay, that's definitely the rate-form. Sorry to be dense. – Glen_b -Reinstate Monica Mar 12 '14 at 23:09

Much about your question is unclear, but I can talk about the median in the gamma distribution and you may be able to resolve the problem from that.

The gamma distribution is typically written either in the rate form or the scale form (I'll avoid using $\beta$ here, since your intention isn't clear):

Rate form:

$$f(x;\alpha,\phi) = \frac{\phi^\alpha}{\Gamma(\alpha)} x^{\alpha-1}e^{-\phi x} \quad \text{ for } x > 0 \text{ and } \alpha, \phi > 0$$

Scale form:

$$f(x;\alpha,\theta) = \frac{x^{\alpha-1}e^{-\frac{x}{\theta}}}{\theta^\alpha\Gamma(\alpha)} \quad \text{ for } x > 0 \text{ and } \alpha, \theta > 0$$

It's sometimes also written in the mean form (especially for GLMs):

$$f(x;\alpha,\mu) = \frac{\alpha^\alpha}{\mu^\alpha\Gamma(\alpha)}x^{\alpha-1}e^{-\frac{x\alpha}{\mu}} \quad \text{ for } x > 0 \text{ and } \alpha, \mu > 0$$

--

The mean is $\alpha\theta = \alpha/\phi=\mu$.

The median doesn't have a simple closed form, but for larger $\alpha$, it can be approximated.

For $\beta=1$, for large $\alpha$, the median is approximately the mean $-\frac{1}{3}$. This works well for $\alpha$ around 10 and higher.

More accurately, the median is approximately $\frac{3 \alpha - 0.8}{3 \alpha + 0.2}$ times the mean (as long as $\alpha$ is not too small, say no less than somewhere around 1-2, it works okay):

Another way to approach the median is via the Wilson-Hilferty transformation; since the cube root of a gamma is approximately normal, one can approximate the relationship between the mean and the median via that relationship (the median directly transforms both directions, but the mean is more complicated - one can use Taylor expansions to approximate the mean). (Examination of this approximation suggests it's actually pretty poor. The Wikipedia page uses it to approximate the median for the chi-square distribution, but frankly it looks like it's not nearly as good as even the "$-\frac{1}{3}$" rule I mentioned earlier, let alone the other one.)

For more accuracy, if one specifies the median and one specifies the scale or rate parameter, one can use the gamma cdf or the inverse gamma cdf (the gamma quantile function) to iteratively solve for the required alpha.

If $F$ is the gamma cdf and $F^{-1}$ is its inverse, you use root finding to solve $F_{\alpha,\beta}(m) - \frac{1}{2}=0$ for $\alpha$, or to solve $m - F^{-1}_{\alpha,\beta}(\frac{1}{2})=0$

A good starting point would be from one of the previously mentioned approximations.

I think I know what an appropriate β parameter is (though I could be wrong on this point, feel free to make comments if I'm thinking about that incorrectly)

It's a bit hard to comment about whether you have a misconception here if you aren't explicit about what you actually think and why.

• To hopefully clarify my intentions... My logic was based on the Gamma distribution being a conjugate prior for the Poisson distribution. In that context, I read that the hyperparameters should be interpreted as "$\alpha$ total occurrences in $\beta$ intervals". So if I want my prior to have the "weight"/"effect" of half an observation on my posterior, I know a good value for $\beta$... 0.5 . And, I want my prior to have 50% probability on either side of an initial hypothesis, in other words specifying the median. Hence, I wanted to find a suitable $\alpha$ given the median and "this" $\beta$ – Fabio Beltramini Mar 12 '14 at 22:48

Based on testing a large number of possible medians $X$, and the formula I was using to select beta as $\beta = 1/X$, it seems that alpha is constant: $\alpha \approx 1.314250$ . I still don't know the formula for this result, but for my programmatic needs, it's sufficient.