bayesplain.compare_groups

bayesplain.compare_groups(data, by=None, labels=None, pool=False, threshold=0.0, unit='', n_draws=None, seed='unset', values=None)[source]

Compare the averages of three or more groups.

Parameters:
data : mapping, sequence of array_like, or array_like

The observations. Accepts a {name: values} mapping, a sequence of arrays (one per group), or a flat array of values paired with by. A pandas Series or DataFrame column works with by as well.

by : array_like or str, optional

Group label for each observation, when data is a flat array; or, when data is a data frame, the name of the column holding the labels.

labels : sequence of str, optional

Group names, when they cannot be read from data.

pool : bool, default False

Partially pool the group estimates, pulling each toward the overall average in proportion to how noisy it is. Small groups get pulled the furthest, which stops the smallest site from winning the ranking on noise alone.

threshold : float, default 0.0

The spread the reported probability is measured against.

unit : str, optional

Display unit.

n_draws : int, optional

Number of draws. Defaults to the package setting.

seed : int or None, optional

Seed for the draws.

values : str, optional

With a data frame as data, the column holding the observations: compare_groups(df, by="district", values="rent").

Returns:

The headline quantity is the spread between the highest and lowest group average. Call .pairwise() for the comparison table that this analysis is really about, and .plot(kind='forest') to see the groups ranked with their uncertainty.

Return type:

Result

Examples

>>> import numpy as np, bayesplain as bp
>>> rng = np.random.default_rng(0)
>>> data = {
...     "North": rng.normal(12, 3, 40),
...     "South": rng.normal(15, 3, 38),
...     "East": rng.normal(12.5, 3, 45),
... }
>>> res = bp.compare_groups(data, unit="days")
>>> len(res.components)
3
>>> print(res.pairwise())