Hierarchical Bayesian Bornhuetter-Ferguson over programs
hierarchical_bf_fit.Rdbayes_hierarchical_bf() fits several programs, one segment of a
triangle each, pooled under an industry hyperprior on the loss ratio,
with the development pattern partially pooled (decision 30 of
docs/design/reserving-bayes.md). Each origin's cumulative-value
increments are the over-dispersed Poisson of bayes_bf_normalised() with
mean U[c, w] * p[c, d], the origin's expected ultimate times the share
of it that falls at age d. The industry loss ratio L has a lognormal
prior with mean apriori and coefficient of variation level_cv (flat
on log L when level_cv is NULL, so the programs alone set the
level). Program c has loss ratio L * s[c] with log s[c] normal with
sd tau and E[s[c]] = 1, tau half-normal with scale tau_scale; its
origins' expected ultimates are gamma with mean L * s[c] * exposure and
coefficient of variation cv. The shared log pattern beta[d] is
normal with sd development_sd (or the pattern_prior), and each
program's own pattern departs from it by omega times a standard normal
per age, omega half-normal with scale omega_scale. A thin program's
young ages therefore move with its own data, its later ages follow the
shared pattern, and its loss ratio is shrunk towards L by as much as
the spread between the programs supports.
Usage
hierarchical_bf_fit(ptr)
bayes_hierarchical_bf(
triangle,
column,
exposure,
apriori = 1,
level_cv = NULL,
cv = 0.1,
development_sd = 10,
tau_scale = 0.3,
omega_scale = 0.5,
process = c("gamma", "none"),
chains = 4,
tune = 1000,
draws = 1000,
n_sims = 10000,
seed = 0,
target_accept = 0.99,
max_depth = 10,
pattern_prior = NULL
)Arguments
- ptr
A
HierarchicalBfFitpointer; used internally.- triangle
A cumulative triangle with a segment per program, all on the same ages, every origin observed from the first age up to its latest. A triangle with one segment is one program. Or a named list of triangles, one program each: every one a triangle with one segment, with the
columnand theexposureand the same grains and cumulative state. They are stacked into a triangle with a segment per program under the keyprogram(any keys they carry are dropped), and the fit equals, draw for draw, the fit of the same panel given as one triangle with that key. The names label the programs, which run in the sorted order of their names, as the segments of a triangle do, not in the list's order.- column
Name of the loss column to fit.
- exposure
Name of the exposure column; each origin's latest observed value is its exposure.
- apriori
Prior mean of the industry loss ratio
L.- level_cv
Coefficient of variation of the lognormal prior on
L, orNULLfor a prior flat onlog L.- cv
Coefficient of variation of each origin's expected ultimate about its program's level; fixed, finite and positive.
- development_sd
Standard deviation of the normal prior on each shared
beta[d], centred on 0; ignored with apattern_prior.- tau_scale
Scale of the half-normal prior on
tau, the spread of the programs' log loss ratios.- omega_scale
Scale of the half-normal prior on
omega, the spread of the programs' log share ratios.- process
Process error on each simulated future increment:
"gamma"or"none"for parameter error only.- chains, tune, draws
NUTS chains, warm-up draws per chain and kept draws per chain.
- n_sims
Number of predictive simulations; positive.
- seed
Seed of the chains and of the simulations, a non-negative whole number.
- target_accept
Target mean acceptance rate of the step-size adaptation (default 0.99).
- max_depth
Largest NUTS tree depth.
- pattern_prior
A
pattern_prior()on the triangle's ages for the shared pattern, orNULL.
Details
The scale is plugged in per unit of premium, pooled over the programs
(scale_per_premium), so a program of two origins, which has no degree
of freedom of its own, still has a scale; the panel together must have a
degree of freedom. Failed MCMC diagnostics (R-hat above 1.01, bulk or
tail ESS below 100 per chain, any divergent transition) do not fail the
fit: bayes_hierarchical_bf() raises one warning() listing them, and
they stay in the fit's diagnostics. One seed replays a fit exactly.
The one-year view is bayes_hierarchical_bf_one_year().
Properties of the fit: programs (a named list of
hierarchical_bf_program, in the triangle's segment order), ages,
scale_per_premium, reserves (the joint predictive_distribution by
program and origin, paired by posterior draw), diagnostics, summary
(every sampled parameter), hyperparameters (the posterior of level,
the industry loss ratio, tau, the spread of the programs' loss ratios,
and omega, the spread of their patterns) and draws.
as.data.frame() gives one row per program: program, origins,
exposure, latest, prior_ultimate and expected_ultimate (summed
over the origins), scale, loss_ratio, own_loss_ratio, shrinkage
and the mean and std_dev of the program's reserve.
Errors: as bayes_bf_normalised(); if the programs together have no
degree of freedom; if falling columns reach 1 / omega_scale in the
programs' scales, jointly over the programs, or a program's falling columns
exceed its first age, since such a panel has no posterior. For a list of
triangles: an empty list, an unnamed or duplicated name, an entry that is
not a triangle or has several segments or lacks a column, triangles of
different grains or cumulative state, or a column named program, which
is the key of the stacked triangle.
Examples
long <- data.frame(
program = c(rep("a", 6), rep("b", 3)),
year = c(2021, 2021, 2021, 2022, 2022, 2023, 2022, 2022, 2023),
age = c(12, 24, 36, 12, 24, 12, 12, 24, 12),
paid = c(100, 150, 170, 110, 172, 130, 55, 80, 60),
premium = c(250, 250, 250, 270, 270, 290, 120, 120, 130))
tri <- triangle(long, "year", "age", c("paid", "premium"), keys = "program")
fit <- bayes_hierarchical_bf(tri, "paid", "premium", apriori = 0.7, level_cv = 0.2,
chains = 2, tune = 200, draws = 200, n_sims = 500, seed = 1)
#> Warning: bayes_hierarchical_bf: the MCMC diagnostics failed; check them before relying on the fit: log_tau: R-hat 1.0586 is above 1.01; log_tau: bulk ESS 119 is below 200 (100 per chain); log_tau: tail ESS 120 is below 200 (100 per chain); z[1]: R-hat 1.0119 is above 1.01; z[2]: R-hat 1.0103 is above 1.01; alpha[2,2]: tail ESS 165 is below 200 (100 per chain); beta[2]: R-hat 1.0392 is above 1.01; beta[2]: bulk ESS 60 is below 200 (100 per chain); beta[2]: tail ESS 115 is below 200 (100 per chain); beta[3]: bulk ESS 148 is below 200 (100 per chain); beta[3]: tail ESS 135 is below 200 (100 per chain); log_omega: bulk ESS 74 is below 200 (100 per chain); log_omega: tail ESS 130 is below 200 (100 per chain); delta[1,2]: R-hat 1.0355 is above 1.01; delta[1,2]: bulk ESS 79 is below 200 (100 per chain); delta[1,2]: tail ESS 164 is below 200 (100 per chain); delta[2,2]: R-hat 1.0358 is above 1.01; delta[2,2]: bulk ESS 81 is below 200 (100 per chain); delta[2,2]: tail ESS 170 is below 200 (100 per chain); delta[2,3]: R-hat 1.0121 is above 1.01
names(fit@programs)
#> [1] "a" "b"
fit@hyperparameters
#> parameter mean sd q05 q50 q95 rhat
#> 1 level 0.7407332 0.0675501 0.651665962 0.73570021 0.8502795 1.003634
#> 2 tau 0.1128984 0.1128863 0.006437185 0.07310644 0.3484154 1.021065
#> 3 omega 0.2183717 0.1776151 0.031071768 0.16829187 0.5748735 1.007471
#> ess_bulk ess_tail
#> 1 240.05041 233.505
#> 2 119.12454 119.845
#> 3 74.07055 130.048
mean(fit@reserves)
#> [1] 164.9066