bayesplain.Prediction

class bayesplain.Prediction(*, what, dist, plug_in=None, frequentist_interval=None, frequentist_method='', unit='', decimals=0, discrete=False, transform=None, inverse=None)[source]

A forecast of the next observation, with the parameter uncertainty in it.

What Result.predict() returns. The posterior answers “what is the rate?”; this answers “what will next year’s count be?”, which is the question a budget or a staffing plan actually turns on. It averages the ordinary sampling variation over every value of the parameter the posterior still allows, so it is always wider than the interval you would get by plugging in a single best estimate – and the gap between the two is exactly the uncertainty the plug-in pretends away.

Parameters:
what : str

What is being forecast, e.g. "successes in the next 100 cases".

dist : scipy frozen distribution

The posterior predictive distribution, discrete or continuous.

plug_in : scipy frozen distribution, optional

The same forecast with the parameter fixed at its best estimate.

frequentist_interval : tuple of float, optional

The textbook frequentist prediction interval, where one exists.

frequentist_method : str

What that interval is called.

unit : str

Display unit.

decimals : int, default 0

Decimal places for display. Counts use 0.

discrete : bool, default False

Whether the forecast is a count.

transform : callable, optional

A monotone increasing map applied to the draws of dist and its inverse, for forecasts computed on a log scale and reported on the original one. Quantiles and tail probabilities survive a monotone map exactly, so nothing is approximated.

inverse : callable, optional

A monotone increasing map applied to the draws of dist and its inverse, for forecasts computed on a log scale and reported on the original one. Quantiles and tail probabilities survive a monotone map exactly, so nothing is approximated.

Methods

interval([level])

Equal-tailed forecast interval.

point()

Median of the forecast.

probability([op, value])

Probability the next observation satisfies a comparison.

summary([level])

Report the forecast next to the plug-in forecast it improves on.

interval(level=0.95)[source]

Equal-tailed forecast interval.

Parameters:
level : float, default 0.95

Probability the next observation lands inside. For a count the coverage is at least level, since a count cannot be split.

Returns:

Lower and upper bounds.

Return type:

tuple of float

point()[source]

Median of the forecast.

probability(op='>', value=0.0)[source]

Probability the next observation satisfies a comparison.

Parameters:
op : {'>', '>=', '<', '<='}, default '>'

Comparison to evaluate.

value : float

Threshold, on the reported scale.

Returns:

Exact predictive probability.

Return type:

float

Examples

>>> import bayesplain as bp
>>> fc = bp.proportion(34, 220).predict(n=100)
>>> round(fc.probability(">=", 20), 3)
0.193
summary(level=0.95)[source]

Report the forecast next to the plug-in forecast it improves on.

Parameters:
level : float, default 0.95

Forecast level.

Returns:

Printable text.

Return type:

_Report