bayesplain.teach.precision_planning

bayesplain.teach.precision_planning(target_width, expected_rate=0.5, level=0.95, prior='uninformed', max_n=1000000)[source]

Find the sample size that makes an interval narrow enough to act on.

Computed exactly rather than through a normal approximation: for each candidate n the actual Beta posterior interval is measured, and the search stops at the first n that meets the target.

Parameters:
target_width : float

The widest interval you could still act on, on the rate’s own scale. 0.05 means five percentage points.

expected_rate : float, default 0.5

The rate to plan around. 0.5 is the conservative choice, since a rate near one half is the hardest to pin down; plan around a rate closer to what you expect if you have grounds for one.

level : float, default 0.95

Credible level.

prior : str, tuple, or BetaPrior, default 'uninformed'

Prior on the rate. Note that strength alone does not help: a prior centred near expected_rate reduces the data required, while an equally strong prior centred elsewhere increases it, since it pulls the posterior toward a region of higher variance. Making that distinction visible is much of the point of this method.

max_n : int, default 1_000_000

Give up beyond this, rather than searching forever for an unattainable precision.

Returns:

Call .summary().

Return type:

PrecisionPlan

Examples

>>> import bayesplain as bp
>>> plan = bp.teach.precision_planning(target_width=0.10, expected_rate=0.15)
>>> plan.required_n
195

What matters is not how strong the prior is but whether it agrees with what you expect to find. A prior centred on the rate you are planning around halves the data you need; one of similar strength centred somewhere else increases it, because it drags the posterior toward the middle where a rate is hardest to pin down:

>>> agrees = bp.priors.from_previous_study(successes=15, n=100)
>>> bp.teach.precision_planning(0.10, 0.15, prior=agrees).required_n
95
>>> bp.teach.precision_planning(0.10, 0.15, prior="skeptical").required_n
207