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()andbayesplain.compare_means(): the credible interval for a mean ismean +/- t * sd / sqrt(n)withn - 1degrees of freedom, so its width at anyncan 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.
4withunit="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_nis per group whengroups=2. Call.summary().- Return type:¶
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 141Comparing 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