Statistics & decisions

Beta Binomial Learning Lab

Learns a hidden chance of success from observations under a Beta(a0, b0) prior: the conjugate Beta posterior in closed form after a seeded stream of up to 100 observations (the posterior after every one, 10 density snapshots) or after typed counts of up to 100000 trials; the posterior mean, mode and standard deviation, the prior's weight, an equal-tailed credible interval at 80, 90, 95 or 99 percent, the chance that p exceeds a reference point, the beta-binomial predictive of the successes in the next 1 to 20 trials by exact term ratios, 20 repeat streams with the count of intervals that contain the true chance, a zoomed final posterior, and five scored challenges.

Last updated

Calculator overview

Inputs and outputs

This summary comes from the calculator's published input and output contract.

Inputs

Seed (required)
About this input

The seed of the generator, a whole number from 1 to 2147483646; the same seed always gives the same stream and the same 20 repeat streams.

Default 2026 Range 1 to 2147483646
Prior b (required)
About this input

b0 of the Beta(a0, b0) prior, from 0.5 to 50 in steps of 0.5; roughly the prior failures. A larger a0 + b0 is a more confident prior.

Default 1 Range 0.5 to 50
Prior a (required)
About this input

a0 of the Beta(a0, b0) prior, from 0.5 to 50 in steps of 0.5; roughly the prior successes. Beta(1, 1) is uniform, Beta(0.5, 0.5) the Jeffreys prior.

Default 1 Range 0.5 to 50
Reference point (in thousandths) (required)
About this input

R, the reference point r = R/1000 in whole thousandths from 1 to 999; the results give the posterior chance that p exceeds it. Drag its line along the p axis.

Unit thousandths Default 500 Range 1 to 999
Typed trials (required)
About this input

n, the trials you type in counts mode, a whole number from 1 to 100000. Checked in both modes.

Unit trials Default 10 Range 1 to 100000
Typed successes (required)
About this input

S, the successes you type in counts mode, a whole number from 0 up to the typed trials. Checked in both modes.

Unit successes Default 7 Range 0 to 100000
True chance (in thousandths) (required)
About this input

P, the hidden true chance p = P/1000 in whole thousandths from 1 to 999; drag its marker along the p axis (stream mode). Hidden in challenge 3.

Unit thousandths Default 300 Range 1 to 999
Next trials m (required)
About this input

m, the number of future trials whose successes are predicted, a whole number from 1 to 20.

Unit trials Default 10 Range 1 to 20
Your interval, high end (required)
About this input

The high end of the interval you read off the curve, from 0 to 1 (challenge 3).

Default 1 Range 0 to 1
Credible level (required)
About this input

The level of the equal-tailed credible interval: 80, 90, 95 or 99 percent.

Default 95 percent Allowed 80 percent, 90 percent, 95 percent, 99 percent
Challenge number (required)
About this input

0 for none, or 1 to 5 to load a challenge: its settings replace yours except the input it leaves to you.

Default 0 Range 0 to 5
Your interval, low end (required)
About this input

The low end of the interval you read off the curve, from 0 to 1 (challenge 3).

Default 0 Range 0 to 1
Observations from (required)
About this input

Where the observations come from: Seeded stream (a hidden true chance and a seeded generator draw up to 100 observations) or Typed counts (the successes and trials you type). Chosen with the tabs over the canvas.

Default Seeded stream Allowed Seeded stream, Typed counts
Observations N (required)
About this input

N, the observations in the stream and in each repeat stream, a whole number from 1 to 100. A larger N extends the stream and keeps its first draws.

Unit observations Default 100 Range 1 to 100
Your guess (required)
About this input

Your single-number answer from 0 to 1: the posterior mean after one more success (challenge 1) or the chance of at least one success in the next 5 trials (challenge 5).

Default 0.5 Range 0 to 1

Outputs

Prior a used
About this output

a0 used (challenge 4 leaves it to you; other challenges fix it).

No unit declared
The posterior predictive: the chance of each number of successes in the next m trials, and the cumulative chance
About this output

The posterior predictive (beta-binomial) chance of each number of successes j in the next m trials, and the cumulative chance of at most j. Hidden in challenge 5 until met.

No unit declared
Prior b used
About this output

b0 used.

No unit declared
Weight of the prior in the posterior mean
About this output

(a0 + b0)/(a0 + b0 + n), the weight of the prior mean in the posterior mean; the data share gets the rest.

No unit declared
Prior mean
About this output

a0/(a0 + b0), the prior mean of the chance.

No unit declared
Next trials m used
About this output

m used.

Unit trials
Posterior b
About this output

b = b0 + F, the second shape of the Beta posterior.

No unit declared
Posterior a
About this output

a = a0 + S, the first shape of the Beta posterior.

No unit declared
Posterior mean
About this output

a/(a + b), the posterior mean of the chance; also the chance that the next observation is a success.

No unit declared
Posterior standard deviation
About this output

The posterior standard deviation, sqrt(ab/((a + b)^2 (a + b + 1))).

No unit declared
Posterior mode
About this output

(a - 1)/(a + b - 2), the most likely chance, shown when a and b both exceed 1 (otherwise the density peaks at 0 or 1, or is flat).

No unit declared
True chance used (in thousandths)
About this output

The true chance used, in thousandths (a challenge may fix it). Hidden in challenge 3.

Unit thousandths
Interval contains the true chance
About this output

Yes when the credible interval contains the true chance, else No (stream mode). Hidden in challenge 3.

No unit declared
Typed successes used
About this output

The typed successes used.

Unit successes
The final posterior on a window of 5 standard deviations around its mean
About this output

The final posterior density on 60 points of a window of 5 standard deviations around its mean, clipped to 0 and 1.

No unit declared
Typed trials used
About this output

The typed trials used.

Unit trials
The snapshots: the step each frame shows and its posterior shapes
About this output

For each snapshot: the observation it shows and the posterior shapes then. Stream mode uses the steps 1, 2, 3, 5, 10, 20, 30, 50, 75, 100 below N, then N; counts mode one snapshot.

No unit declared
Reference point used (in thousandths)
About this output

The reference point used, in thousandths.

Unit thousandths
Chance that p exceeds the reference point
About this output

The posterior chance that the true chance exceeds the reference point r.

No unit declared
Twenty repeat streams with the same settings: successes, credible interval and whether it contains the true chance
About this output

Twenty more streams with the same settings: each one's successes, credible interval and whether it contains the true chance (1 or 0). Stream mode; the contains column is hidden in challenge 3.

No unit declared
Seed used
About this output

The seed used.

No unit declared
The posterior after every observation of the stream: the outcome, the successes so far, the posterior mean, the credible interval and the success share
About this output

The posterior after every observation of the stream (step 0 is the prior): the outcome (1 success, 0 failure), the successes so far, the posterior mean, the credible interval ends and the success share. Blank past N and in counts mode; the interval ends are hidden in challenge 3.

No unit declared
Repeat intervals expected to contain it
About this output

20 x the credible level: the count expected on average (16, 18, 19 or 19.8; stream mode).

No unit declared
Repeat intervals containing the true chance
About this output

How many of the 20 repeat streams' credible intervals contain the true chance (stream mode). Twenty streams are far too few to measure the rate. Hidden in challenge 3.

No unit declared
Credible interval, high end
About this output

The high end of the equal-tailed credible interval. Hidden in challenge 3.

No unit declared
Credible interval, low end
About this output

The low end of the equal-tailed credible interval (the posterior quantile at the lower tail). Hidden in challenge 3.

No unit declared
Credible level used
About this output

The credible level used, as a number (0.8, 0.9, 0.95 or 0.99).

No unit declared
Challenge result
About this output

No challenge selected, MET or NOT MET.

No unit declared
Challenge feedback
About this output

What the result means, or a hint when the challenge is not met yet.

No unit declared
Chance of at least one success in the next m trials
About this output

The posterior predictive chance of at least one success in the next m trials, 1 - P(no success). Hidden in challenge 5 until met.

No unit declared
Challenge goal
About this output

The goal of the selected challenge.

No unit declared
Challenge score
About this output

100 when the selected challenge is met, else 0.

No unit declared
Challenge: the value scored
About this output

The value the challenge scores: the truth once met (challenges 1 and 5), the interval width (2), your interval width (3) or the coverage count (4).

No unit declared
Observations from, used
About this output

The source used (a challenge may fix it).

No unit declared
Observations N used
About this output

N used.

Unit observations
Observations used
About this output

n, the observations behind the posterior: N in stream mode, the typed trials in counts mode.

Unit observations
Successes
About this output

S, the successes among them.

Unit successes
Failures
About this output

F = n - S, the failures among them.

Unit failures
Formula module versions
About this output

The formula modules the model is built from, with their versions.

No unit declared
Success share of the data
About this output

S/n, the plain success share of the data.

No unit declared
Credible interval width
About this output

The width of the credible interval, high end minus low end. Hidden in challenge 3.

No unit declared
The prior, the posterior at each snapshot and the scaled likelihood on 80 points of the chance p
About this output

On 80 points of the chance p: the prior density, the posterior density at each of up to 10 snapshots (blank when a snapshot is not used) and the likelihood of all the data scaled to area 1.

No unit declared
Model version
About this output

The model version.

No unit declared
Model Status
About this output

OK, CHECK (the true chance lies within 10^-8 of an end of a credible interval, so whether that interval contains it can differ between calculators) or NOT VALID with the input to fix.

No unit declared
This page is provided by LogicCommons for informational purposes only. Results are analysis outputs computed from the inputs you supply and are not professional advice. Verify all inputs and results independently.

LogicCommons is in beta. If a result, label, or reference looks wrong, tell us here; we read every message.

Methodology

Purpose and model boundary

This lab learns an unknown chance of success p, between 0 and 1, from observations that are each a success or a failure. Belief about p starts as a Beta(a0, b0) prior. After S successes and F failures it is the Beta(a0 + S, b0 + F) posterior, in closed form, because the beta prior is conjugate to these observations. The observations come either from a seeded stream of up to 100 draws with a hidden true chance, followed one at a time, or from counts you type (up to 100,000 trials). For the posterior the model returns its mean, mode and standard deviation, an equal-tailed credible interval, the chance that p exceeds a reference point, the beta-binomial prediction of the successes in the next 1 to 20 trials, and the prior's weight in the posterior mean. In stream mode it also shows how the posterior narrows step by step and how many of 20 repeat streams give an interval that contains the true chance. Five scored challenges use the same model.

It is a lab for learning how a prior and data combine: why the posterior mean sits between the prior mean and the data share, why an interval narrows roughly as one over the square root of the data, how a confident prior in the wrong place misleads, and why a prediction averages over every chance the posterior allows. It is not a tool for estimating a real rate for a decision. The repeat streams are far too few to measure how often such intervals contain the truth.

The model is the calculation authority. The page sends the values you set to the model and draws only what it returns: the prior, the posterior snapshots and the likelihood, the ribbon of means and intervals, the zoomed posterior, the predictive bars and the repeat intervals. Nothing on the page draws a random number or computes a probability.

Inputs and units

Probabilities are numbers from 0 to 1. The true chance and the reference point are set in whole thousandths.

Input Meaning and unit
Observations from Seeded stream (default) or Typed counts: where the observations come from.
True chance A whole number of thousandths from 1 to 999 (default 300, a chance of 0.3): the hidden chance p of the seeded stream. Stream mode only.
Reference point A whole number of thousandths from 1 to 999 (default 500, a point of 0.5): r for the chance that p exceeds r.
Seed A whole number from 1 to 2,147,483,646 (default 2026): the start of the random sequence. The same seed always gives the same stream.
Observations N A whole number from 1 to 100 (default 100): the observations in the stream and in each repeat stream.
Prior a, Prior b Each from 0.5 to 50 in steps of 0.5 (defaults 1 and 1, the uniform prior): the shapes a0 and b0 of the Beta prior.
Credible level 80, 90, 95 (default) or 99 percent.
Typed successes, Typed trials Whole numbers: trials from 1 to 100,000 and successes from 0 up to the trials (defaults 7 and 10). Typed counts mode only.
Next trials m A whole number from 1 to 20 (default 10): the trials to predict.
Challenge number 0 for free exploration, or 1 to 5 to load a challenge.
Your guess From 0 to 1 (default 0.5): your single-number prediction in challenges 1 and 5.
Your interval, low end and high end Each from 0 to 1 (defaults 0 and 1): your interval in challenge 3.

Every input is checked on its entered value, whether or not the selected source or challenge uses it.

Where each input is set:

  • On the canvas only: the observation source, the true chance and the reference point.
  • Draggable on the canvas: the true chance and the reference point, as handles on the p axis, in steps of 0.001.
  • In the input panel: the seed and the number of observations, then the prior shapes, credible level, typed counts, next trials, challenge number and the guesses.

Governing relationships

The generator. The seeded stream uses Park and Miller's minimal standard generator (MINSTD) with the multiplier 48271: starting from s₀ = the seed, each state is

sₜ = MOD(48271 · sₜ₋₁, 2³¹ - 1).

Every product stays below 2⁴⁷, so the integer sequence is exact. The first two outputs are discarded, so the first draw used is s₃: observation k of the main stream uses s_(k+2), and repeat stream j (j = 1 to 20) uses the next block of 100 draws, from s_(100j+3). Each stream reserves 100 draws whatever N is.

The success test (exact). With p = P/1000 and M = 2³¹ - 1, observation t is a success when sₜ ≤ INT(P x M / 1000). This is exactly the test sₜ / M < p, with no rounding and no tie.

The conjugate update. With S successes in n trials and F = n - S,

posterior = Beta(a, b) with a = a0 + S and b = b0 + F.

The posterior mean, mode and standard deviation are

mean = a / (a + b), mode = (a - 1) / (a + b - 2) when a > 1 and b > 1, sd = √(a·b / ((a + b)² (a + b + 1))).

The mode is left blank when a or b is 1 or less: the density then peaks at 0 or 1, or is flat. The chance that the next observation is a success equals the posterior mean.

The prior's weight. With w = (a0 + b0) / (a0 + b0 + n), the posterior mean is exactly

mean = w x (prior mean a0/(a0 + b0)) + (1 - w) x (data share S/n),

so a prior acts like a0 + b0 earlier observations.

The credible interval. The equal-tailed interval at level L cuts off the same chance in each tail: its ends are the inverse Beta distribution at (1 - L)/2 and (1 + L)/2, that is at 0.1 and 0.9, 0.05 and 0.95, 0.025 and 0.975, or 0.005 and 0.995. For a skewed posterior it is not the shortest interval with that chance.

The chance above the reference point. P(p > r) = 1 - I_r(a, b) = I_(1-r)(b, a), where I is the regularised incomplete beta function (the Beta distribution function). The mirrored form keeps a small upper tail accurate.

The posterior predictive (beta-binomial). The number of successes J in the next m trials has

P(J = j) = C(m, j) B(a + j, b + m - j) / B(a, b),

where B is the beta function. The model computes it without any gamma function: P(J = 0) is the product of (b + i) / (a + b + i) for i = 0 to m - 1, and each next term follows from the ratio P(J = j + 1) / P(J = j) = (m - j)(a + j) / ((j + 1)(b + m - j - 1)). The chance of at least one success is 1 - P(J = 0). This averages over every chance the posterior allows, which is not the same as putting one estimate of p into 1 - (1 - p)^m.

The repeat streams. Each of the 20 repeat streams draws N observations of the same true chance, updates the same prior, and gives its own interval. The model counts how many contain the true chance, against the expected 20 x L (16, 18, 19 or 19.8).

Density snapshots. The prior, the posterior at up to 10 snapshot steps (1, 2, 3, 5, 10, 20, 30, 50, 75 and 100, the steps below N and then N itself), and the likelihood of the final data are evaluated at 80 evenly spaced midpoints of (0, 1). The final posterior is also drawn on a zoomed grid of 60 points over the mean plus or minus 5 standard deviations, clipped to (0, 1).

Calculation sequence

  1. Check the inputs in the order of the status list under Errors and warnings. In a challenge, take the challenge's fixed values, except the inputs it leaves to you.
  2. Run the generator and test each draw against the true chance.
  3. Follow the main stream step by step: the successes so far, the posterior shapes, mean and interval.
  4. Take the final counts from the stream (its first N observations) or from the typed counts, and form the final posterior.
  5. Find its mean, mode, standard deviation, prior weight, credible interval and the chance above the reference point.
  6. Compute the beta-binomial prediction for the next m trials.
  7. In stream mode, update the prior with each of the 20 repeat streams and count the intervals that contain the true chance.
  8. Evaluate the densities for the snapshots and the zoomed posterior.
  9. Set the status and, in a challenge, score it.

Outputs and interpretation

  • Observations used, successes and failures, and the data share S/n.
  • Prior mean and prior weight in the posterior mean.
  • Posterior a and b, and the posterior mean, mode and standard deviation.
  • Credible interval low end, high end and width.
  • Chance that p exceeds the reference point.
  • Chance of at least one success in the next m trials.
  • Stream mode: whether the interval contains the true chance (Yes or No), and the repeat intervals that contain it of 20, against the expected number.
  • Settings used: every model input in effect, the credible level as a number.
  • Tables: the ribbon (each step's outcome, successes so far, posterior mean, interval ends and success share); the density frames and the snapshot steps; the zoomed posterior; the predictive probabilities and their running totals for 0 to m successes; and the repeat streams (each stream's successes, interval and whether it contains the true chance).

Reading the canvas: play the snapshots to see the posterior narrow and move toward the data. A strong prior is slow to move. On the ribbon, four times the data roughly halves the band's width. Typed counts draw only the final posterior: the observation tokens, the ribbon and the repeat streams need the seeded stream.

Challenges

Each challenge fixes its own source, seed, true chance, prior, level and counts, except the inputs it leaves to you; your guesses are always yours. The model scores each one MET (100) or NOT MET (0) and gives a one-line hint while it is not met.

  1. One more success. After 3 successes in 8 trials with a Beta(2, 2) prior, predict the posterior mean if the next trial is a success, to within 0.005. It is met when your guess is within 0.005 of (a + 1) / (a + b + 1).
  2. Narrow enough. Find the smallest number of observations after which the 95% credible interval is at most 0.25 wide. It is met when N equals the first step of the fixed stream whose interval is at most 0.25 wide.
  3. The hidden chance. The true chance is hidden. Read a 90% interval for it off the curve: at most 0.25 wide, and it must contain the true chance.
  4. A prior that misleads. Choose a prior with a + b at most 40 that makes at most 14 of the 20 repeat intervals contain the true chance.
  5. At least one. After 1 success in 30 trials with a uniform prior, predict the chance of at least one success in the next 5 trials, to within 0.01.

Two challenges hold results back. In challenge 3 (met or not) the credible interval, whether it contains the true chance, the coverage count, the true chance used, the ribbon's interval columns and the repeat streams' intervals are blank, and the canvas hides the true-chance marker: you read the interval off the density curve. In challenge 5, until it is met, the chance of at least one success and the predictive table are blank; they appear once your guess is within 0.01.

Every "at most" test of a challenge has a relative band of 1×10⁻⁹.

What to take from the lab: the posterior is a compromise between the prior and the data, weighted by their sizes; more data narrows the interval, but slowly; a confident wrong prior keeps intervals narrow and away from the truth; and a prediction should average over the whole posterior.

Validation and status logic

The status reads the first match in the list under Errors and warnings. Items 1 to 9 are checked on the values you entered, inside a challenge too. The one CHECK item applies in stream mode only, and every result is shown under it. Typed counts are a mode, not a warning: they read OK.

Assumptions and limitations

  • The observations are independent successes or failures with one fixed chance p.
  • The prior is a Beta distribution with shapes from 0.5 to 50 in steps of 0.5; no other prior family is offered.
  • The credible interval is equal-tailed, not the highest-density interval.
  • The generator is meant for repeatable classroom streams, not for cryptography or production simulation.
  • Twenty repeat streams show "most, but not all" intervals containing the truth; they are too few to measure coverage.
  • The density grids are coarse for a very narrow posterior from large typed counts: the 80-point grid shows a spike, and the zoomed grid draws it smoothly. Densities far from a narrow posterior can underflow to 0.
  • An interval end within 1×10⁻⁸ of the true chance is flagged, because whether the interval contains it can then depend on the last digits of the interval end.

Restrictions and non-computing states

Under NOT VALID every result and every table is blank, apart from the model version, the challenge status (No challenge selected, or NOT MET when a challenge is selected), a score of 0, and the goal and hint of a selected challenge.

In typed counts mode the ribbon, the repeat streams, the interval-contains result and the coverage counts are blank, and only the final posterior is drawn. The mode is blank when a or b is 1 or less. Ribbon rows beyond N and predictive rows beyond m are blank.

In challenges 3 and 5, results are held back as described under Challenges.

Errors and warnings

The status messages, first match wins:

  • NOT VALID: choose where the observations come from: Seeded stream or Typed counts
  • NOT VALID: the seed must be a whole number from 1 to 2147483646
  • NOT VALID: the true chance and the reference point must be whole numbers of thousandths from 1 to 999
  • NOT VALID: the number of observations must be a whole number from 1 to 100
  • NOT VALID: the prior's a and b must each be from 0.5 to 50, in steps of 0.5
  • NOT VALID: choose a credible level from the list
  • NOT VALID: the typed counts need a whole number of trials from 1 to 100000 and a whole number of successes from 0 up to the number of trials
  • NOT VALID: the prediction horizon must be a whole number of trials from 1 to 20
  • NOT VALID: the challenge number must be a whole number from 0 to 5, and each guess a number from 0 to 1
  • CHECK: the true chance lies within 0.00000001 of an end of a credible interval, so whether that interval contains it can differ between calculators: stream mode, the final interval or any repeat interval.
  • OK

References

This laboratory is an educational model of conjugate Bayesian updating for a chance of success. A Beta prior combined with success-or-failure observations gives a Beta posterior whose shapes simply add the successes and the failures, so its mean, mode, standard deviation and equal-tailed credible interval follow in closed form, and the prediction of the successes in the next few trials is the beta-binomial distribution. Its seeded streams come from the Park-Miller minimal standard (MINSTD) generator, a multiplicative linear congruential generator with modulus 2^31 - 1 and the multiplier 48271, so every stream is exact and repeatable from its seed.

Sources and further reading

  • The Beta distribution: its density, mean and standard deviation: NIST/SEMATECH, e-Handbook of Statistical Methods, section 1.3.6.6.17, Beta Distribution. NIST
  • The binomial model with a beta prior, the posterior as a compromise between the prior and the data, posterior intervals and the posterior predictive distribution: A. Gelman, J. B. Carlin, H. S. Stern, D. B. Dunson, A. Vehtari and D. B. Rubin, Bayesian Data Analysis, 3rd edition, CRC Press, 2013, chapter 2, Single-parameter models. Authors' page
  • The beta-binomial distribution, its probabilities and mean, and its role in the Bayesian estimation of a success chance: Wikipedia, Beta-binomial distribution. Wikipedia
  • The minimal standard generator: S. K. Park and K. W. Miller, "Random number generators: good ones are hard to find", Communications of the ACM 31(10), 1988, pages 1192-1201, and the multiplier 48271 in S. K. Park, K. W. Miller and P. K. Stockmeyer, "Technical correspondence", Communications of the ACM 36(7), 1993.

No table or text from any of these publications is reproduced, and none of their authors or publishers has reviewed or endorses this laboratory.

This laboratory is for learning. Its results hold only within its stated ranges; twenty repeat streams are far too few to measure how often its intervals contain the true chance.

Links were current at build time. If one moves, search the document's title rather than reporting a broken link as a defect.

Results are informational and not professional advice. See our Terms of Use. Powered by SpreadsheetWeb · About · Privacy · Terms