bayesplain.categories¶
-
bayesplain.categories(data, expected=
None, prior='uninformed', labels=None, threshold=None, n_draws=None, seed='unset')[source]¶ Compare how one categorical variable splits against expected shares.
- Parameters:¶
- data : array_like, mapping, or pandas Series¶
Either the counts in each category – a list of numbers, a
{category: count}mapping, or the output ofSeries.value_counts()– or the raw observations themselves, one label per case, which are tallied for you.- expected : array_like or mapping, optional¶
The shares each category should hold. Defaults to equal shares. Given as shares or as counts (it is normalised), in the same order as the categories, or as a
{category: share}mapping.- prior : str, float, or ConcentrationPrior, default 'uninformed'¶
Dirichlet concentration over the category shares, centred on the expected shares:
'uninformed'is worth one observation per category, spread in the expected proportions. Seebayesplain.priors.describe().- labels : sequence of str, optional¶
Category names, when they cannot be read from
data.- threshold : float, optional¶
The value of Cohen’s w the reported probability is measured against. Defaults to the larger of Cohen’s “small” bar, 0.1, and the noise floor: the w that data matching the expected shares exactly would still produce at this sample size. Without the floor, a modest sample spread over many categories reports a confident departure from pure noise, because w adds up the uncertainty in every share and nothing cancels.
- n_draws : int, optional¶
Number of draws. Defaults to the package setting.
- seed : int or None, optional¶
Seed for the draws.
- Returns:¶
The headline is Cohen’s w, the overall size of the departure. Call
.shares()for the table this analysis is really about: each category’s share, with an interval, against what was expected.- Return type:¶
Examples
Collisions by day of the week, against an even split:
>>> import bayesplain as bp >>> days = {"Mon": 31, "Tue": 28, "Wed": 30, "Thu": 33, ... "Fri": 45, "Sat": 38, "Sun": 25} >>> res = bp.categories(days) >>> res.frequentist.pvalue < 0.05 False >>> round(res.shares_table["Fri"]["probability_above_expected"], 2) 0.98The omnibus test sees nothing, but one category clearly stands out – which is what
.shares()is for.