GARETH GRANTTECHNOLOGY · DATA · INNOVATION
Explore

18 / Inference

Bayesian updating: beta-binomial learning about a rate

Beta-binomial updating represents uncertainty about an unknown binary-outcome probability. A disclosed beta prior is updated with new successes and failures to produce a posterior distribution for the rate.

IntermediateLive exploration + Python

The business question

How should prior knowledge and a new small sample combine when estimating a business rate?

  • Update an uncertain conversion or defect rate as new comparable observations arrive.
  • Express a probability that a rate exceeds a practical business threshold under stated prior assumptions.
  • Explore how sensitive an early decision is to the amount of prior information used.

How the method works

A binomial calculation with a supplied p treats that probability as fixed and known. Bayesian inference instead places a distribution over plausible p values. A Beta(a,b) prior is flexible on 0–1: its mean is a/(a+b), and its concentration a+b expresses how strongly it is concentrated in the conjugate model. Choose it before viewing the new data and explain why its shape is relevant.

Observe x successes from n independent comparable trials. The binomial likelihood contributes a factor p^x(1−p)^(n−x). Multiplying this by the beta prior yields another beta distribution with updated parameters a+x and b+n−x. Its mean is a weighted compromise between the prior mean and observed rate. With more relevant data, the likelihood has greater influence.

A posterior credible interval describes a stated amount of posterior probability for p, conditional on the prior and likelihood model. It is different from the repeated-sampling coverage interpretation of a confidence interval. Predictions for a future success count should integrate over uncertainty in p, using a beta-binomial predictive distribution, rather than automatically substituting the posterior mean into a fixed-p binomial model.

The calculation

Prior p ~ Beta(a,b); posterior p | x,n ~ Beta(a+x,b+n−x); posterior mean = (a+x)/(a+b+n)
Read the symbols
SymbolMeaning
a,bPositive prior shape parameters; their relevance and strength must be justified.
x,nNew successes and eligible trials, counted once and using the same outcome definition.
pUnknown underlying success probability.
credible intervalAn interval containing a stated posterior probability under the chosen model.

A worked business example

ILLUSTRATIVE SCENARIO

Illustrative service firm begins a new booking channel with a modest Beta(2,8) prior on conversion. It then observes ten conversions among thirty comparable enquiries. The business threshold under discussion is a 25% conversion rate.

Inputs

  • Prior Beta(2,8), with prior mean 2/10 = 20%.
  • New observations: x = 10 conversions; n = 30 enquiries.
  • Posterior interval: equal-tailed 95%; practical threshold p > 0.25.

Work through the numbers

  1. Update the success parameter: a + x = 2 + 10 = 12. Update the other parameter: b + n − x = 8 + 30 − 10 = 28.
  2. The posterior is Beta(12,28), with mean 12/(12+28) = 30.00%. The observed rate alone is 10/30 = 33.33%.
  3. The 2.5th and 97.5th posterior percentiles are approximately 0.1701959 and 0.4487363.
  4. The posterior probability that p exceeds 0.25 is 0.7468608. A future ten-enquiry count has posterior predictive mean 10 × 0.30 = 3 conversions.
Posterior mean 30.00%; 95% credible interval about 17.02%–44.87%; posterior probability above 25% about 74.69%.

The new data raise the rate estimate, but substantial uncertainty remains. A 74.69% model-based probability is a decision input, not a universally sufficient reason to expand the channel.

Explore the decision

Learn a binary rate from new data. The live explorer has its own example inputs; it is separate from the worked calculation above.

Enable JavaScript to use this calculator. The worked example and executable Python remain available.

Apply it at work

  1. Define the rate, comparable trials and the practical threshold or loss function.
  2. Specify and document a prior before using the new data; compare weak and stronger defensible alternatives.
  3. Update with new successes and failures once, then report posterior summaries and predictions.
  4. Evaluate the action under costs, uncertainty and prior sensitivity; recheck the model when the channel or population changes.

Check these assumptions

  • The likelihood uses conditionally independent Bernoulli trials sharing a relevant p.
  • Prior and new data address the same rate or any differences are explicitly modelled.
  • Prior parameters are fixed before the new evidence is used, with their strength disclosed.
  • The posterior probability is conditional on the model and does not remove sampling bias or misclassification.

Common mistakes and how to avoid them

  • Choosing a convenient prior after seeing results can make a decision look more certain than justified.
  • Using the same observations in both a prior summary and the new likelihood double-counts evidence.
  • A posterior interval for p is not an interval for the next observed batch proportion; predictive variation is different.

How this can help the business

  • Early decisions can combine relevant history with new evidence while showing how much confidence each contributes.
  • A manager can evaluate whether another batch of observations is likely to change a threshold-based decision before committing to a full rollout.
A decision rule to adapt

Select an action using a pre-agreed practical threshold or expected loss, and show whether the decision survives defensible alternative priors.

When to use another approach

Use a Wilson confidence interval for a frequentist rate estimate, or a hierarchical model when sites or customer groups have related but different rates.

Reproduce the worked example in Python

The code is self-contained for this example. Dependencies and run instructions are included with the downloadable notebook.

Show executable code and recorded output
from scipy.stats import beta, betabinom
a, b = 2, 8
successes, trials = 10, 30
post_a, post_b = a+successes, b+trials-successes
low, high = beta.ppf([0.025,0.975],post_a,post_b)
print(f'Posterior mean rate: {beta.mean(post_a,post_b):.2%}')
print(f'95% credible interval: {low:.2%} to {high:.2%}')
print(f'P(rate above 25%): {beta.sf(0.25,post_a,post_b):.2%}')
print(f'Predictive mean successes in 10 trials: {betabinom.mean(10,post_a,post_b):.2f}')

Recorded output

Posterior mean rate: 30.00%
95% credible interval: 17.02% to 44.87%
P(rate above 25%): 74.69%
Predictive mean successes in 10 trials: 3.00
Download all worked examples

Sources and further reading

Concepts are linked to primary teaching or technical sources. The business examples are illustrative applications, not reported client results.