Gesmann and Morris' compartmental model over segments
compartmental_fits.Rdcompartmental() fitted to every segment of a triangle, each segment
with its own posterior (the same model and settings, sampled
independently) and its premium from its own premium column as
compartmental() reads it, into joint posterior predictive
distributions of the reserves and of the future paid and outstanding
cells, the segments depending on each other as dependence says.
Segment k (in index order) takes seeds derived from seed and k for
its chains and its simulations, so independent segments share no random
numbers, and a segment's draws differ from compartmental() of that
segment alone. Under dependence = "rank_correlation" each segment's
reserves, future paid cells and future outstanding cells are reordered
together (one Iman-Conover reorder, ranked on the segments' total
reserves), so every simulation's reserve is still its paid at the
square's last age less the latest paid. Failed MCMC diagnostics and rate
swaps raise one warning() listing every segment's messages, each
prefixed with its segment's label.
Usage
compartmental_fits(ptr)
compartmental_segments(
triangle,
paid,
premium,
priors,
outstanding = NULL,
incurred = NULL,
likelihood = c("normal", "lognormal"),
scale = c("amount", "loss_ratio"),
paid_response = c("cumulative", "incremental"),
fitted = c("paid_and_outstanding", "paid_and_incurred", "paid_only", "incurred_only"),
rate_order = c("free", "ordered"),
development_levels = c("per_age", "by_year"),
start = c("data", "prior_centre"),
chains = 4,
tune = 1000,
draws = 2000,
n_sims = 10000,
seed = 0,
target_accept = 0.99,
max_depth = 10,
dependence = c("independent", "rank_correlation", "synchronized"),
spearman = NULL
)Arguments
- ptr
A
CompartmentalFitspointer; used internally.- triangle
A cumulative triangle with any number of segments.
- paid
Name of the column of cumulative paid amounts.
Name of the column with each origin's premium (its latest value); the fit's origins are this column's.
- priors
A compartmental_priors list; required.
- outstanding
Name of a column of outstanding amounts.
- incurred
Name of a column of incurred amounts: outstanding is incurred less paid, cell by cell (the papers' outstanding on company 337 is incurred with bulk and IBNR less paid). Give exactly one of
outstandingandincurred, or neither underfitted = "paid_only".- likelihood
"normal"(model 1) or"lognormal"(model 2).- scale
The response scale:
"amount"(model 1) or"loss_ratio", amounts over the origin's premium (model 2).- paid_response
"cumulative"(model 1) or"incremental"(model 2).- fitted
"paid_and_outstanding","paid_and_incurred"(incurred replaces outstanding as the second response, as above),"paid_only"or"incurred_only"(one response alone, withrate_order = "ordered").- rate_order
"free"or"ordered", as above.- development_levels
The width of a development level, for priors with development effects (model 2):
"per_age"(the default), one level for each age, or"by_year", one for each development year (counted from the origin's start: ages 1 to 12 months, 13 to 24 and so on). Choose withbayes_loo(); see "Fitting sub-annual data" incompartmental(). The same fit at annual grain. An error for"by_year"with priors that have no development effects (model 1).- start
Where the pilot run starts:
"data", a least-squares fit of the population curve (the prior centre if that fit fails, and under one response if its log posterior is below the prior centre's), or"prior_centre".- 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 (the paper's
adapt_delta, 0.99).- max_depth
Largest NUTS tree depth.
- dependence
How the segments depend on each other:
"independent", each segment's own posterior and simulations; or"rank_correlation", the segments' simulations reordered as whole rows to the Spearman matrixspearman."synchronized"is accepted asodp_bootstrap()takes it, and is an error here.- spearman
With
dependence = "rank_correlation"only: Spearman's rho between the segments' total reserves, asodp_bootstrap()'s.
Details
Properties of the fit: origins, premium and latest_paid (each
segment's origins in turn), reserves, paid and outstanding
(predictive_distributions with the triangle's keys first among their
dimensions, so aggregate(fit@reserves, keep = "lob") keeps the
dependence between segments), rate_swaps (one count per segment) and
diagnostics (a data.frame with one row per segment: the key columns,
max_rhat, min_ess_bulk, min_ess_tail, divergences and
warnings, the segment's messages joined by "; "). summary, draws,
bayes_loo() and paid_table and outstanding_table (one row per
segment and future cell) are those of compartmental_fit and need a
single-segment fit for the first three: with several segments use
segment(). as.data.frame(), totals_frame() and segment() work as
for compartmental(). The one-year view of several segments is
compartmental_one_year_segments().
Errors: as compartmental() for any segment (the message names the
segment); dependence = "synchronized", before any sampling, since a
posterior has no residuals to share; or a spearman matrix that does not
fit the segments.
Examples
one <- data.frame(year = rep(1988:1992, 5:1),
age = unlist(lapply(5:1, function(k) 12 * seq_len(k))),
paid = c(9.6, 22.8, 33.3, 40.3, 45.1, 7.9, 19.5, 29.6, 36.8,
8.7, 24.3, 35.4, 13.3, 33.0, 11.4),
incurred = c(62.7, 64.0, 65.6, 65.3, 62.3, 62.1, 56.7, 56.6, 56.8,
64.0, 61.5, 63.2, 73.9, 75.1, 77.1),
premium = rep(c(104.4, 88.9, 86.0, 99.3, 104.9), 5:1))
two <- one
two[c("paid", "incurred", "premium")] <- 2 * two[c("paid", "incurred", "premium")]
long <- rbind(cbind(lob = "auto", one), cbind(lob = "home", two))
tri <- triangle(long, "year", "age", c("paid", "incurred", "premium"), keys = "lob")
# Short chains may miss a diagnostic threshold.
fits <- suppressWarnings(compartmental_segments(tri, "paid", "premium",
gesmann_morris_priors(),
incurred = "incurred", chains = 2,
tune = 150, draws = 150,
target_accept = 0.9, n_sims = 500))
fits@reserves@keys
#> lob origin
#> 1 auto 1988
#> 2 auto 1989
#> 3 auto 1990
#> 4 auto 1991
#> 5 auto 1992
#> 6 home 1988
#> 7 home 1989
#> 8 home 1990
#> 9 home 1991
#> 10 home 1992
fits@diagnostics
#> lob max_rhat min_ess_bulk min_ess_tail divergences
#> 1 auto 1.042351 93.05235 20.35070 1
#> 2 home 1.021082 132.57916 66.93919 0
#> warnings
#> 1 k_er: tail ESS 171 is below 200 (100 per chain); k_p: R-hat 1.0411 is above 1.01; k_p: bulk ESS 100 is below 200 (100 per chain); k_p: tail ESS 33 is below 200 (100 per chain); RLR: R-hat 1.0249 is above 1.01; RLR: bulk ESS 93 is below 200 (100 per chain); RLR: tail ESS 37 is below 200 (100 per chain); RRF: tail ESS 179 is below 200 (100 per chain); sigma_os: R-hat 1.0154 is above 1.01; sigma_os: bulk ESS 114 is below 200 (100 per chain); sigma_os: tail ESS 20 is below 200 (100 per chain); sigma_pd: R-hat 1.0221 is above 1.01; RLR[1988]: R-hat 1.0222 is above 1.01; RLR[1988]: bulk ESS 99 is below 200 (100 per chain); RLR[1988]: tail ESS 45 is below 200 (100 per chain); RLR[1989]: R-hat 1.0226 is above 1.01; RLR[1989]: bulk ESS 99 is below 200 (100 per chain); RLR[1989]: tail ESS 39 is below 200 (100 per chain); RLR[1990]: R-hat 1.0207 is above 1.01; RLR[1990]: bulk ESS 107 is below 200 (100 per chain); RLR[1990]: tail ESS 57 is below 200 (100 per chain); RLR[1991]: R-hat 1.0218 is above 1.01; RLR[1991]: bulk ESS 104 is below 200 (100 per chain); RLR[1991]: tail ESS 44 is below 200 (100 per chain); RLR[1992]: R-hat 1.0272 is above 1.01; RLR[1992]: bulk ESS 100 is below 200 (100 per chain); RLR[1992]: tail ESS 39 is below 200 (100 per chain); RRF[1988]: R-hat 1.0112 is above 1.01; RRF[1988]: tail ESS 179 is below 200 (100 per chain); RRF[1989]: tail ESS 191 is below 200 (100 per chain); RRF[1990]: tail ESS 122 is below 200 (100 per chain); RRF[1991]: R-hat 1.0108 is above 1.01; RRF[1991]: tail ESS 136 is below 200 (100 per chain); RRF[1992]: tail ESS 179 is below 200 (100 per chain); b_ker: tail ESS 171 is below 200 (100 per chain); b_kp: R-hat 1.0424 is above 1.01; b_kp: bulk ESS 100 is below 200 (100 per chain); b_kp: tail ESS 33 is below 200 (100 per chain); b_RLR: R-hat 1.0249 is above 1.01; b_RLR: bulk ESS 93 is below 200 (100 per chain); b_RLR: tail ESS 37 is below 200 (100 per chain); b_RRF: tail ESS 179 is below 200 (100 per chain); tau_RLR: R-hat 1.0123 is above 1.01; tau_RLR: tail ESS 185 is below 200 (100 per chain); tau_RRF: tail ESS 158 is below 200 (100 per chain); rho: R-hat 1.0127 is above 1.01; log_sigma_os: R-hat 1.0154 is above 1.01; log_sigma_os: bulk ESS 114 is below 200 (100 per chain); log_sigma_os: tail ESS 20 is below 200 (100 per chain); log_sigma_pd: R-hat 1.0249 is above 1.01; 1 divergent transitions among the kept draws
#> 2 k_er: R-hat 1.0211 is above 1.01; k_er: tail ESS 186 is below 200 (100 per chain); RRF: R-hat 1.0103 is above 1.01; RRF[1988]: R-hat 1.0139 is above 1.01; RRF[1989]: R-hat 1.0125 is above 1.01; RRF[1990]: R-hat 1.0129 is above 1.01; RRF[1991]: R-hat 1.0114 is above 1.01; RRF[1992]: R-hat 1.0124 is above 1.01; b_ker: R-hat 1.0196 is above 1.01; b_ker: tail ESS 186 is below 200 (100 per chain); b_RRF: R-hat 1.0100 is above 1.01; tau_RLR: bulk ESS 133 is below 200 (100 per chain); tau_RLR: tail ESS 67 is below 200 (100 per chain); tau_RRF: tail ESS 107 is below 200 (100 per chain); rho: tail ESS 182 is below 200 (100 per chain)
segment(fits, lob = "home")@premium
#> [1] 208.8 177.8 172.0 198.6 209.8