bayesplain.mean

bayesplain.mean(x, prior='conventional', reference=None, label='', unit='', log=False, n_draws=None, seed='unset', data=None)[source]

Estimate one unknown average from a sample.

The posterior is exact: with the reference prior, the mean of a normal sample has a scaled Student-t posterior with n - 1 degrees of freedom. No sampling, nothing to converge.

Parameters:
x : array_like or str

Observations, or the name of a column in data. Non-finite values are dropped, and the summary says how many.

prior : str, float, or EffectSizePrior, default 'conventional'

Cauchy prior on standardised effect size. Affects the Bayes factor only; the posterior and credible interval do not depend on it.

reference : float, optional

The value to compare against: the null for the t-test, the threshold for the reported probability, and the point null for the Bayes factor. Defaults to 0. With log=True it is required, on the original scale, since zero has no logarithm.

label : str, optional

What the quantity is, for output, e.g. "commute time".

unit : str, optional

Display unit, e.g. "minutes".

log : bool, default False

Work on the log scale and report the typical (geometric-mean) value on the original scale. For skewed, strictly positive data – prices, incomes – where the arithmetic mean is dragged around by a few large values. reference stays on the original scale.

n_draws : int, optional

Number of draws for derived quantities. Defaults to the package setting.

seed : int or None, optional

Seed for those draws.

data : data frame, optional

Where to look x up when it is a column name. The column name becomes the label unless label is given.

Returns:

Call .summary() for the full report, and .predict() for a forecast of the next observation.

Return type:

Result

Examples

>>> import numpy as np, bayesplain as bp
>>> commutes = np.array([28, 35, 42, 31, 25, 38, 45, 33, 29, 40.0])
>>> res = bp.mean(commutes, reference=30, label="commute time", unit="minutes")
>>> round(res.point("mean"), 2)
34.6
>>> res.exact
True