bayesplain.core.hierarchical.shrink

bayesplain.core.hierarchical.shrink(means, standard_errors)[source]

Pull group means toward the overall average, in proportion to noise.

Parameters:
means : array_like

Observed group means.

standard_errors : array_like

Standard error of each group mean.

Returns:

With keys 'means' and 'standard_errors' for the shrunk estimates, 'weights' for each group’s \(w_i\) (1 means no shrinkage, 0 means full pooling), 'tau2' for the estimated between-group variance, and 'grand_mean'.

Return type:

dict

Examples

A tiny district with an extreme average gets pulled the furthest:

>>> out = shrink([10.0, 12.0, 25.0], [1.0, 1.0, 8.0])
>>> bool(out["weights"][2] < out["weights"][0])
True
>>> bool(out["means"][2] < 25.0)
True