Skip to contents

compartmental()'s model as a model of diagonal_backtest(). Unlike the other model specs it holds the data it reads, the triangle and its paid, outstanding (or incurred) and premium columns, since its outstanding and premium are not in the backtest's table of paid increments. Put it in the models of diagonal_backtest(), on the same triangle with paid as the column, to score the paid increments of the held-out diagonals beside the other models, and call compartmental_outstanding_backtest() for a second table, the held-out outstanding of the same diagonals. Both tables use the same fits: the candidate keeps the fit of each split (one run of the sampler), whichever table is asked for first.

Usage

compartmental_backtest_model(ptr)

compartmental_candidate(
  triangle,
  paid,
  premium,
  priors,
  outstanding = NULL,
  incurred = NULL,
  likelihood = c("normal", "lognormal"),
  scale = c("amount", "loss_ratio"),
  paid_response = c("cumulative", "incremental"),
  rate_order = c("free", "ordered"),
  development_levels = c("per_age", "by_year"),
  start = c("data", "prior_centre"),
  chains = 4,
  tune = 1000,
  draws = 2000,
  target_accept = 0.99,
  max_depth = 10
)

compartmental_model_2_candidate(
  triangle,
  paid,
  premium,
  priors,
  outstanding = NULL,
  incurred = NULL,
  rate_order = c("free", "ordered"),
  development_levels = c("per_age", "by_year"),
  start = c("data", "prior_centre"),
  chains = 4,
  tune = 2000,
  draws = 8000,
  target_accept = 0.999,
  max_depth = 10
)

Arguments

ptr

A CompartmentalBacktestModel pointer; used internally.

triangle

A cumulative triangle with one segment.

paid

Name of the column of cumulative paid amounts.

premium

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 outstanding and incurred, or neither under fitted = "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).

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 with bayes_loo(); see "Fitting sub-annual data" in compartmental(). 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.

target_accept

Target mean acceptance rate (the paper's adapt_delta, 0.99).

max_depth

Largest NUTS tree depth.

name

The candidate's name in the backtest.

Value

A compartmental_backtest_model object for the models of diagonal_backtest() and compartmental_outstanding_backtest(), with properties name, paid and premium.

Details

The settings are compartmental()'s, except that the backtest's n_sims and seed replace the candidate's, and the sampler runs once per split (the whole chains by draws posterior), so size it for the number of diagonals. The held-out diagonal's outstanding and paid never reach the fit. The candidate's name in the results is "compartmental_gm1" for model 1, "compartmental_gm2" for model 2 (the log-normal likelihood, loss ratios and incremental paid of compartmental_model_2()) and "compartmental" for other settings.

Examples

long <- 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))
tri <- triangle(long, "year", "age", c("paid", "incurred", "premium"))
cand <- compartmental_candidate(tri, "paid", "premium", gesmann_morris_priors(),
                                incurred = "incurred", chains = 2, tune = 150,
                                draws = 150, target_accept = 0.9)
cand
#> <compartmental_candidate> compartmental_gm1, paid column "paid", premium column "premium"
# \donttest{
paid <- diagonal_backtest(tri, "paid", list(cand), n_diagonals = 1, n_sims = 200)
paid@mean
#>               model     crps  coverage actual_vs_expected total_crps
#> 1 compartmental_gm1 4.582174 0.6666667           2.194068    15.8817
#>   mean_log_density total_percentile
#> 1        -3.709613            0.985
compartmental_outstanding_backtest(cand, n_diagonals = 1, n_sims = 200)@mean
#>                           model     crps coverage actual_vs_expected total_crps
#> 1 compartmental_gm1_outstanding 13.26822        1           3.655501   40.56332
#>   mean_log_density total_percentile
#> 1        -4.611852            0.925
# }