# How can I find the posterior distribution for gammadistributed data and prior?

I am working on a project where I believe Bayesian statistics should be useful. However, my knowledge about Bayesian statistics are very scarce. Suppose I got data following a Gamma distribution with a known shape-parameters of $$\alpha = 11.26$$ and the estimated parameters for the prior are, $$a=1.08$$ and $$b=13.7$$ (a being shape and b being rate).

For the prior I got a Gamma distribution: $$f(\theta) = \frac{b^{a}}{Γ(a)} \theta^{a-1} \exp(-b\theta)$$

And the likelihood: $$L(x|\theta) = \prod_{i=1}^{n}\frac{\beta^{\alpha}}{\Gamma(\alpha)}\theta^{\alpha} \exp(-\theta x_i) = \frac{\beta^{\alpha n}}{\Gamma(\alpha)}\theta^{\alpha n}\exp\left(-\theta \sum_{i=1}^{n}x_i\right)$$

Thus the posterior is: $$f(\theta|x) ∝ \theta^{a-1} \exp(-b\theta) * \theta^{\alpha} \exp(-\theta \sum_{i=1}^{n}x_i) = \theta^{a+\alpha n - 1} \exp(-\theta(b + \sum_{i=1}^{n}x_i)$$

This will then be a $$Ga(a+\alpha n, b + \sum_{i=1}^{n}x_i)$$ am I right?

However, when I plug in the values for $$(a+\alpha n, b + \sum_{i=1}^{n}x_i)$$, I get a distribution that is not possible/true. The posterior distribution will be $$Ga(1250.94, 17.39)$$,the plotted distribution moves very far away from both the data and prior, the distribution should be closer to the data rather than be further away?

Is the posterior parameters not the distribution or have I misunderstood something? Or is it possible that it is not at all a probability density function I am plotting?

• The likelihood is a function of the parameter given the data: $L(\theta|x)$. Is the likelihood gamma as well? Then you got the formula wrong. Take a look at Wikipedia as well. Commented Jul 15, 2022 at 23:32
• The posterior you're looking at is a distribution for $\theta$, not $x$. Commented Apr 10 at 0:22

If $$X_i|\theta\sim\mathcal G(\alpha,\theta)$$ for $$1\le i\le n$$, and $$\theta$$ is the rate parameter of the Gamma, the likelihood is $$L(\theta|\mathbf x)=\prod_{i=1}^n x_i^{\alpha-1}\Gamma(\alpha)^{-n}\theta^{\alpha n}\exp\{-\theta n\bar x_n\}\propto \theta^{\alpha n}\exp\{-\theta n\bar x_n\}$$ and the associated posterior is indeed $$\theta|\mathbf x \sim \mathcal G(a+\alpha n,b+n\bar x_n)$$ with mean $$\mathbb E[\theta|\mathbf x]=\dfrac{a+\alpha n}{b+n\bar x_n}$$ It is difficult to understand what you mean by