bayesplain.core.hierarchical.shrink_proportions

bayesplain.core.hierarchical.shrink_proportions(successes, n)[source]

Pull group rates toward the typical rate, by empirical-Bayes beta-binomial.

Parameters:
successes : array_like

Success count in each group.

n : array_like

Trial count in each group.

Returns:

With keys 'alpha' and 'beta' for each group’s posterior Beta parameters, 'weights' for each group’s \(w_i\) (1 means no shrinkage, 0 means full pooling), 'kappa' for the estimated concentration, 'grand_mean' for the typical rate \(\mu\), and 'full' for whether the groups collapsed onto one shared rate.

Return type:

dict

Examples

A small group with an extreme rate is pulled the furthest:

>>> out = shrink_proportions([10, 45, 80, 9], [100, 100, 100, 12])
>>> bool(out["weights"][3] < out["weights"][0])
True
>>> bool(out["alpha"][3] / (out["alpha"][3] + out["beta"][3]) < 9 / 12)
True