Solution (source code)

= Solution

<Bayes' theorem> updates a hypothesis using observed data. For mutually exclusive exhaustive hypotheses $H_j$ and data $D$ of nonzero <probability>,
$$
\boxed{P(H_j\mid D)=
\frac{P(D\mid H_j)P(H_j)}
{\sum_kP(D\mid H_k)P(H_k)}}.
$$
The prior $P(H_j)$ describes information before these data; the <likelihood> $P(D\mid H_j)$ describes the sampling model; the denominator is the evidence; and the posterior is the updated <probability>. <likelihood> and posterior are different conditional quantities. For a continuous parameter, sums become integrals and the posterior is a <probability density>.

Consider a counter registering independent events at unknown constant rate $\lambda$, observed for known exposure $T$ with negligible background and dead time. The observed count has a <Poisson distribution>:
$$
P(n\mid\lambda,T)=\frac{(\lambda T)^n e^{-\lambda T}}{n!}.
$$
Take a proper gamma prior in shape-rate convention,
$$
\pi(\lambda)=\frac{\beta^\alpha}{\Gamma(\alpha)}
\lambda^{\alpha-1}e^{-\beta\lambda},\qquad
\alpha,\beta>0.
$$
Multiplying by the <likelihood> adds the count to the shape and the exposure to the rate. Normalization therefore gives
$$
\boxed{\lambda\mid n,T\sim\operatorname{Gamma}(\alpha+n,\beta+T)},\qquad
\mathbb E(\lambda\mid n,T)=\frac{\alpha+n}{\beta+T},
\quad
\operatorname{Var}(\lambda\mid n,T)=\frac{\alpha+n}{(\beta+T)^2}.
$$
Here $\beta$ has exposure units. This is <Poisson-gamma conjugacy>. Successive independent counting runs update the same posterior by adding their counts and exposures, so the result agrees with analysing all the data together.

A <credible interval> contains a specified <posterior probability> for $\lambda$, conditional on the chosen prior and model. For low counts, the posterior can be asymmetric and sensitive to the prior, and a symmetric Gaussian error bar can be misleading. For large $n$ and an exposure dominating prior information, the mean approaches $n/T$ and its standard deviation approaches $\sqrt n/T$. Background, missed events or time-dependent rates require a richer <likelihood>; <Bayes' theorem> cannot compensate for an incorrect physical counting model. The prior must be specified independently of the same data being used in the <likelihood>, unless its estimation is explicitly included in a larger model.