Skip to main content

credibility.hierarchical_credibility()

Bayesian hierarchical credibility, sampled with NUTS: Bühlmann–Straub’s

Usage

credibility.hierarchical_credibility(
    ratios,
    weights,
    levels=None,
    collective_mean=None,
    within_prior=None,
    between_priors=None,
    chains=4,
    tune=1000,
    draws=1000,
    seed=0
)

model, or Jewell’s hierarchy of it, as a normal random-effects model.

Group i in period j has ratio X_ij ~ N(theta_i, sigma**2 / w_ij); each group’s risk premium theta_i is normal about its node at the level above (levels), each node about its own parent, and the top about the collective mean mu. The means are integrated out exactly, so NUTS samples only the standard deviations; given them, each premium is the credibility formula Z * M + (1 - Z) * E[parent], and the Bayesian premium averages it over their posterior.

Parameters

ratios: list of list of float

One row per group, one column per period; NaN for a missing cell.

weights: list of list of float

The same shape, NaN in the same places.

levels: list of list of int = None

The hierarchy above the groups, outermost level first: levels[k][i] is group i’s node (from 0) at level k. Omitted for Bühlmann–Straub’s model.

collective_mean: (float, float) = None

(mean, sd) of a normal prior on mu; flat if omitted.

within_prior: (str, float) = None

("half_normal", scale) or ("half_cauchy", scale) on sigma; half-normal at five times the pooled within standard deviation if omitted.

between_priors: list of (str, float) = None

One per level, outermost first and the groups’ last; half-normal at five times each level’s spread if omitted.

chains: int = 4

NUTS settings.

tune: int = 4

NUTS settings.

draws: int = 4

NUTS settings.

seed: int = 4
NUTS settings.

Returns

HierarchicalCredibilityFit

Examples

>>> from prospicio.credibility import hierarchical_credibility
>>> x = [[1.0, 2.0, 3.0, 2.0], [4.0, 5.0, 6.0, 5.0], [2.0, 3.0, 4.0, 3.0]]
>>> fit = hierarchical_credibility(x, [[1.0] * 4] * 3, chains=2, tune=300, draws=300)
>>> fit.collective_mean < fit.premiums[1] < 5.0

True