bayesplain.teach.precision_planning_mean

bayesplain.teach.precision_planning_mean(target_width, sd, groups=1, level=0.95, unit='', max_n=10000000)[source]

Find the sample size that pins down an average, or a difference.

Exact under the reference prior used by bayesplain.mean() and bayesplain.compare_means(): the credible interval for a mean is mean +/- t * sd / sqrt(n) with n - 1 degrees of freedom, so its width at any n can be written down, given the standard deviation you expect to see. For two groups the plan assumes equal sizes and equal spreads, which is the design that makes the difference most precise.

Parameters:
target_width : float

The widest interval you could still act on, in the data’s own units. 4 with unit="minutes" means an interval four minutes wide, i.e. plus or minus two.

sd : float

The standard deviation you expect in the data – from a pilot, an earlier study, or a published figure.

groups : {1, 2}, default 1

Plan for one average, or for the difference between two.

level : float, default 0.95

Credible level.

unit : str, optional

Display unit.

max_n : int, default 10_000_000

Give up beyond this.

Returns:

required_n is per group when groups=2. Call .summary().

Return type:

PrecisionPlan

Examples

Commute times vary with a standard deviation of about 12 minutes. To know the average to within plus or minus two minutes:

>>> import bayesplain as bp
>>> bp.teach.precision_planning_mean(target_width=4, sd=12).required_n
141

Comparing two routes to the same precision takes more than twice as many observations in total, because both averages are uncertain:

>>> bp.teach.precision_planning_mean(target_width=4, sd=12, groups=2).required_n
278