Stochastic loss reserving with GLMs: Taylor and McGuire reproduced
reserving-taylor-mcguire.RmdRendered from docs/guides/reserving-taylor-mcguire.qmd.
The code runs each time the site is built, so the output below is
current.
CAS Monograph 3 is Stochastic Loss Reserving Using Generalized Linear Models (Greg Taylor and Gráinne McGuire, 2016). It shows that the chain ladder is a generalized linear model (GLM), puts a prediction error on the reserve, checks the model with residuals and improves it with fewer parameters and some interactions, all on one triangle. This guide runs the examples in prospicio from R and shows the monograph’s numbers beside prospicio’s.
This is the R twin of the Python guide reserving-taylor-mcguire.md,
with the same sections, models and numbers. The R package calls the same
Rust code, and the designs below have the same columns in the same
order, so the estimates and the seeded simulations agree with the Python
guide to each printed digit.
Table and figure numbers are the monograph’s. The explanations are
new and the numbers are recomputed. Money is in thousands of dollars. To
choose a reserving method in general, read reserving-methods.md.
triangle(), chain_ladder(),
mack(), odp_bootstrap() and
odp_glm() work on the triangle. odp_glm() fits
the cross-classified model by default and gives the analytic prediction
error, simulated reserves and residual diagnostics. Its
formula argument takes any other design written on the
cells of odp_glm_cells(). Each model of chapter 7 is the
same call with another formula. glm_fit() fits the ODP Mack
model of section 2.
R/prospicio/tests/test-guides.R runs the chunks in order
and checks that each chunk prints the text below it. To render the page,
install the R package and run
quarto render docs/guides/reserving-taylor-mcguire.qmd.
library(prospicio)
# Thousands separators, as Python's {:,.0f}.
comma <- function(x, digits = 0) {
formatC(round(x, digits), format = "f", digits = digits, big.mark = ",")
}1. The data and the chain ladder
The monograph’s example (Table 1-1) is the incremental paid triangle of a New Jersey workers compensation insurer, accident years 1988 to 1997, from the database of Meyers and Shi (2011). Its age-to-age factors are almost constant down each column, so the chain ladder fits it well.
INCREMENTS <- list( # Table 1-1, accident years 1988 to 1997, development years 1 to 10
c(41821, 34729, 20147, 15965, 11285, 5924, 4775, 3742, 3435, 2958),
c(48167, 39495, 24444, 18178, 10840, 7379, 5683, 4758, 3959),
c(52058, 47459, 27359, 17916, 11448, 8846, 5869, 5391),
c(57251, 49510, 27036, 20871, 14304, 10552, 7742),
c(59213, 54129, 29566, 22484, 14114, 10000),
c(59475, 52076, 26836, 22332, 14756),
c(65607, 44648, 27062, 22655),
c(56748, 39315, 26748),
c(52212, 40030),
c(43962)
)
K <- length(INCREMENTS)
YEARS <- 1988:1997
cumulative <- lapply(INCREMENTS, cumsum)
long <- data.frame(
year = rep(YEARS, lengths(cumulative)),
age = unlist(lapply(lengths(cumulative), function(n) 12 * seq_len(n))),
paid = unlist(cumulative)
)
tri <- triangle(long, "year", "age", "paid")
cl <- chain_ladder(tri, "paid")
cat("factors ", sprintf("%.3f", cl@ldf), "\n")## factors 1.815 1.261 1.158 1.088 1.055 1.039 1.030 1.025 1.021
## reserves 3398 8155 14579 22645 31865 45753 60093 80983 105874
## total 373346
The volume-weighted factors are Table 3-1 and the reserves the last column of Table 3-2, to the unit.
2. The chain ladder as a GLM
Chapter 3 gives two models that reproduce the chain ladder’s
forecasts. The monograph uses the cross-classified ODP model
from then on. Each incremental payment Y[k, j] is
over-dispersed Poisson (ODP) with mean a[k] * b[j], a row
effect times a column effect, and variance phi times the
mean.
On the log scale this is a GLM with a log link and an indicator
column for each accident year and development year. The design drops one
column effect for full rank: the monograph sets
ln b[1] = 0, so the accident-year terms carry the
level.
odp_glm(tri, "paid") uses an intercept and factors
measured from the first level; the monograph uses one
ln a[k] per accident year and no intercept. To print that
coding, write it in the formula. odp_glm_cells() lists the
100 cells (55 observed, 45 to forecast) in the order the formula uses,
with 0-based accident and development indices. A formula finds variables
that are not in the cells in its own environment, so the code defines
the 1-based k and j once here:
library(gt)
cells <- odp_glm_cells(tri, "paid")
k <- cells$origin_index + 1 # accident year, 1 to 10
j <- cells$development_index + 1 # development year, 1 to 10
cc <- odp_glm(tri, "paid", formula = ~ 0 + factor(k) + factor(j))
est <- cc@coefficients
se <- cc@std_errors
ib <- (K + 1):(2 * K - 1) # the ln b coefficients, development years 2 to 10
table_5_1 <- data.frame(
index = as.character(1:K),
ln_a = est[1:K], se_a = se[1:K],
ln_b = c(0, est[ib]), se_b = c(NA, se[ib])
)
gt(table_5_1, rowname_col = "index") |>
tab_header("Table 5-1: the cross-classified model",
"Accident year k for ln a, development year j for ln b; ln b[1] = 0") |>
cols_label(ln_a = "ln a", se_a = "s.e.", ln_b = "ln b", se_b = "s.e.") |>
fmt_number(columns = c(ln_a, ln_b), decimals = 3) |>
fmt_number(columns = c(se_a, se_b), decimals = 4) |>
sub_missing(missing_text = "")| Table 5-1: the cross-classified model | ||||
| Accident year k for ln a, development year j for ln b; ln b[1] = 0 | ||||
| ln a | s.e. | ln b | s.e. | |
|---|---|---|---|---|
| 1 | 10.657 | 0.0316 | 0.000 | |
| 2 | 10.795 | 0.0299 | −0.205 | 0.0228 |
| 3 | 10.899 | 0.0289 | −0.747 | 0.0282 |
| 4 | 10.989 | 0.0281 | −1.017 | 0.0328 |
| 5 | 11.039 | 0.0278 | −1.452 | 0.0421 |
| 6 | 11.016 | 0.0285 | −1.833 | 0.0547 |
| 7 | 11.008 | 0.0295 | −2.140 | 0.0715 |
| 8 | 10.891 | 0.0327 | −2.348 | 0.0931 |
| 9 | 10.836 | 0.0367 | −2.513 | 0.1267 |
| 10 | 10.691 | 0.0510 | −2.664 | 0.1993 |
This is Table 5-1 and the first two columns of Table 3-5, digit for
digit. phi is the Pearson chi-square over the 55 - 19 = 36
residual degrees of freedom, as SAS GENMOD gives with
PSCALE: the monograph’s 114.5 (section 5.4.2).
cat(sprintf("phi %.1f on %.0f degrees of freedom\n", cc@dispersion, sum(cells$observed) - length(est)))## phi 114.5 on 36 degrees of freedom
Rescale the effects so that the b[j] add to 1 (Table
3-3): b[j] is the share of the ultimate paid in development
year j, and a[k] the ultimate of accident year
k. The reserve is the forecast of the future cells by
accident year:
a <- exp(est[1:K])
b <- exp(c(0, est[ib]))
gap <- max(abs(cc@reserves[-1] - cl@reserve[-1]))
table_3_3 <- data.frame(
index = as.character(1:K),
ultimate = a * sum(b), pattern = b / sum(b), reserve = cc@reserves
)
gt(table_3_3, rowname_col = "index") |>
tab_header("Table 3-3: ultimates and payment pattern",
"Ultimate and reserve by accident year k, pattern by development year j") |>
fmt_integer(columns = c(ultimate, reserve)) |>
fmt_number(columns = pattern, decimals = 3)| Table 3-3: ultimates and payment pattern | |||
| Ultimate and reserve by accident year k, pattern by development year j | |||
| ultimate | pattern | reserve | |
|---|---|---|---|
| 1 | 144,781 | 0.293 | 0 |
| 2 | 166,301 | 0.239 | 3,398 |
| 3 | 184,501 | 0.139 | 8,155 |
| 4 | 201,845 | 0.106 | 14,579 |
| 5 | 212,151 | 0.069 | 22,645 |
| 6 | 207,340 | 0.047 | 31,865 |
| 7 | 205,725 | 0.035 | 45,753 |
| 8 | 182,904 | 0.028 | 60,093 |
| 9 | 173,225 | 0.024 | 80,983 |
| 10 | 149,836 | 0.020 | 105,874 |
## GLM total reserve 373,346
cat("largest gap to the chain ladder below 1e-6:", gap < 1e-6, "\n")## largest gap to the chain ladder below 1e-6: TRUE
The table is Table 3-3. The last column of Table 3-5 differs by one unit in four places, because the monograph rounds. The GLM reserves equal the chain ladder’s because maximum likelihood under the ODP makes the fitted total equal the actual total in each row and column, as the chain ladder does (chapter 3).
The other model of chapter 3, ODP Mack, works on the
age-to-age factors. Each observed f[k, j] - 1 is ODP with
mean f[j] - 1 and weight the cumulative paid
X[k, j] at the start of the link. It is a GLM on the links,
not the increments, with one column per development year, a log link and
prior weights, so glm_fit() fits it
(dispersion = "pearson"):
links <- do.call(rbind, lapply(1:(K - 1), function(k) data.frame(k = k, j = seq_len(K - k))))
growth <- mapply(function(k, j) cumulative[[k]][j + 1] / cumulative[[k]][j] - 1, links$k, links$j)
weight <- mapply(function(k, j) cumulative[[k]][j], links$k, links$j)
md <- data.frame(growth = growth, j = factor(links$j))
odp_mack <- glm_fit(growth ~ 0 + j, md, family = "poisson", link = "log",
weights = weight, dispersion = "pearson")
cat("f - 1", sprintf("%.3f", exp(odp_mack@coefficients)), "\n")## f - 1 0.815 0.261 0.158 0.088 0.055 0.039 0.030 0.025 0.021
These are Table 3-4: the chain-ladder factors minus one. The two models give the same forecast but not the same prediction error, because their variance assumptions differ (section 4).
3. Prediction error by the delta method
Chapter 5 puts a prediction error on the reserve. The mean square error of prediction (MSEP) of future cells has two parts:
- Process error is the variance of the cells:
phitimes their mean under the ODP. - Parameter error comes from the estimated coefficients. To first
order (the delta method), a reserve
R = sum of exp(x' beta)moves byg' (beta_hat - beta), with gradientg = sum of mu * xover its cells. Its variance isg' Sigma g, whereSigmais the covariance of the coefficients from the GLM.
The fit’s prediction_error does this (equations 5-11 to
5-13) for each accident year and the total, for any design. The table
splits the RMSEP into its two parts beside Table 5-4:
pe <- cc@prediction_error[-1, ] # a row per accident year 1989 to 1997, then Total
TABLE_5_4 <- rbind( # forecast, RMSEP, CVP %
c(3398, 924, 27.2), c(8155, 1363, 16.7), c(14579, 1775, 12.2), c(22645, 2169, 9.6),
c(31865, 2523, 7.9), c(45753, 3036, 6.6), c(60093, 3577, 6.0), c(80983, 4538, 5.6),
c(105874, 6786, 6.4), c(373346, 14076, 3.8)
)
table_5_4 <- do.call(rbind, lapply(seq_len(nrow(pe)), function(i) {
data.frame(
year = c(pe$origin[i], paste0(pe$origin[i], ", book")),
forecast = c(pe$reserve[i], TABLE_5_4[i, 1]),
process_se = c(pe$process_se[i], NA), parameter_se = c(pe$parameter_se[i], NA),
rmsep = c(pe$rmsep[i], TABLE_5_4[i, 2]), cvp = c(100 * pe$cv[i], TABLE_5_4[i, 3])
)
}))
gt(table_5_4, rowname_col = "year") |>
tab_header("Table 5-4: reserve and prediction error by accident year",
"Money in the units of the triangle; CVP in percent") |>
cols_label(process_se = "process SE", parameter_se = "parameter SE", rmsep = "RMSEP",
cvp = "CVP %") |>
fmt_integer(columns = c(forecast, process_se, parameter_se, rmsep)) |>
fmt_number(columns = cvp, decimals = 1) |>
sub_missing(missing_text = "")| Table 5-4: reserve and prediction error by accident year | |||||
| Money in the units of the triangle; CVP in percent | |||||
| forecast | process SE | parameter SE | RMSEP | CVP % | |
|---|---|---|---|---|---|
| 1989 | 3,398 | 624 | 681 | 924 | 27.2 |
| 1989, book | 3,398 | 924 | 27.2 | ||
| 1990 | 8,155 | 966 | 961 | 1,363 | 16.7 |
| 1990, book | 8,155 | 1,363 | 16.7 | ||
| 1991 | 14,579 | 1,292 | 1,217 | 1,775 | 12.2 |
| 1991, book | 14,579 | 1,775 | 12.2 | ||
| 1992 | 22,645 | 1,610 | 1,453 | 2,169 | 9.6 |
| 1992, book | 22,645 | 2,169 | 9.6 | ||
| 1993 | 31,865 | 1,910 | 1,649 | 2,523 | 7.9 |
| 1993, book | 31,865 | 2,523 | 7.9 | ||
| 1994 | 45,753 | 2,289 | 1,994 | 3,036 | 6.6 |
| 1994, book | 45,753 | 3,036 | 6.6 | ||
| 1995 | 60,093 | 2,624 | 2,432 | 3,577 | 6.0 |
| 1995, book | 60,093 | 3,577 | 6.0 | ||
| 1996 | 80,983 | 3,046 | 3,364 | 4,538 | 5.6 |
| 1996, book | 80,983 | 4,538 | 5.6 | ||
| 1997 | 105,874 | 3,482 | 5,824 | 6,786 | 6.4 |
| 1997, book | 105,874 | 6,786 | 6.4 | ||
| Total | 373,346 | 6,539 | 12,465 | 14,076 | 3.8 |
| Total, book | 373,346 | 14,076 | 3.8 | ||
Table 5-4 agrees in every number. Parameter error is the larger part of the total’s RMSEP. Adding the years’ MSEPs as if they were independent gives:
by_year_msep <- pe$rmsep[-K]^2
cat(sprintf("total if the years were independent %s (book 10,275)\n", comma(sqrt(sum(by_year_msep)))))## total if the years were independent 10,275 (book 10,275)
This is lower than the total because the years are positively
correlated: they share the b[j], so an error in one moves
all years the same way.
4. Prediction error by simulation
Section 5.4.2 checks the delta method with a parametric bootstrap: draw the coefficients from their estimated normal distribution, forecast the future cells, add process error, and repeat 10,000 times.
predict_distribution() of an odp_glm() fit
does this. Its process error on each cell is
phi * Poisson(mu / phi); the monograph does not state its
process distribution. parameters = "normal" draws the
coefficients from a plain normal, as the monograph does. The columns of
the draws are the future cells of the fit’s future, which
the code adds by accident year.
by_year_draws <- function(fit, seed, n_sims = 10000) {
pd <- predict_distribution(fit, n_sims = n_sims, seed = seed, parameters = "normal")
m <- draw_matrix(pd) # one row per draw, one column per future cell
sapply(split(seq_len(ncol(m)), fit@future$origin), function(i) rowSums(m[, i, drop = FALSE]))
}
sim_table <- function(sims, book, title) {
sims <- cbind(sims, rowSums(sims))
mean_ <- unname(colMeans(sims))
sd_ <- unname(apply(sims, 2, stats::sd))
keys <- c(as.character(YEARS[-1]), "Total")
frame <- do.call(rbind, lapply(seq_along(keys), function(i) {
data.frame(year = c(keys[i], paste0(keys[i], ", book")),
mean = c(mean_[i], book[i, 1]), rmsep = c(sd_[i], book[i, 2]),
cvp = c(100 * sd_[i] / mean_[i], book[i, 3]))
}))
gt(frame, rowname_col = "year") |>
tab_header(title, "Money in the units of the triangle; CVP in percent") |>
cols_label(rmsep = "RMSEP", cvp = "CVP %") |>
fmt_integer(columns = c(mean, rmsep)) |>
fmt_number(columns = cvp, decimals = 1)
}
TABLE_5_5 <- rbind(
c(3476, 937, 27.0), c(8269, 1366, 16.5), c(14738, 1794, 12.2), c(22776, 2186, 9.6),
c(32043, 2525, 7.9), c(45963, 3057, 6.7), c(60273, 3608, 6.0), c(81249, 4589, 5.6),
c(106204, 6831, 6.4), c(374992, 14286, 3.8)
)
sim_table(by_year_draws(cc, seed = 1), TABLE_5_5, "Table 5-5: the parametric bootstrap, 10,000 draws")| Table 5-5: the parametric bootstrap, 10,000 draws | |||
| Money in the units of the triangle; CVP in percent | |||
| mean | RMSEP | CVP % | |
|---|---|---|---|
| 1989 | 3,467 | 943 | 27.2 |
| 1989, book | 3,476 | 937 | 27.0 |
| 1990 | 8,290 | 1,397 | 16.8 |
| 1990, book | 8,269 | 1,366 | 16.5 |
| 1991 | 14,725 | 1,792 | 12.2 |
| 1991, book | 14,738 | 1,794 | 12.2 |
| 1992 | 22,792 | 2,177 | 9.6 |
| 1992, book | 22,776 | 2,186 | 9.6 |
| 1993 | 32,037 | 2,528 | 7.9 |
| 1993, book | 32,043 | 2,525 | 7.9 |
| 1994 | 45,950 | 3,101 | 6.7 |
| 1994, book | 45,963 | 3,057 | 6.7 |
| 1995 | 60,313 | 3,593 | 6.0 |
| 1995, book | 60,273 | 3,608 | 6.0 |
| 1996 | 81,254 | 4,582 | 5.6 |
| 1996, book | 81,249 | 4,589 | 5.6 |
| 1997 | 106,056 | 6,849 | 6.5 |
| 1997, book | 106,204 | 6,831 | 6.4 |
| Total | 374,883 | 14,432 | 3.8 |
| Total, book | 374,992 | 14,286 | 3.8 |
Means and RMSEPs agree with Table 5-5 within simulation noise: with 10,000 draws a standard deviation has a relative error of about 0.7%. The total RMSEPs are 1.0% apart, which two seeds can also give. Both are slightly above the delta method.
Both sets of means are above the chain ladder’s forecasts
(374,992 in the monograph against 373,346). This is not noise: a cell
exp(x' beta) with beta drawn from a normal has
the mean mu * exp(v / 2), where v = x' Sigma x
is the variance of the linear predictor (the lognormal bias). The fit’s
future gives the simulation’s exact expectation for each
cell, as predictive_mean:
## chain ladder 373,346
cat(sprintf("E[simulated] %9s (book's bootstrap mean 374,992)\n", comma(sum(cc@future$predictive_mean))))## E[simulated] 374,994 (book's bootstrap mean 374,992)
The monograph puts the higher means down to sampling error, but the
bias explains all of the 1,646 difference, to two units. To simulate
around the chain ladder’s forecast, use
parameters = "mean_preserving". It moves each cell’s linear
predictor by -v / 2, so that the draws of the cell average
to its fitted mean.
Other methods for the same question. The ODP
bootstrap of England and Verrall (odp_bootstrap())
resamples the model’s adjusted Pearson residuals, draws no parameters
from a normal and adds gamma process error. Mack’s model is the
distribution-free counterpart of ODP Mack (section 2). The bootstrap’s
scale is the same Pearson phi:
ob <- odp_bootstrap(tri, "paid", n_sims = 10000, seed = 1)
boot <- draw_matrix(ob@reserves) # one row per draw, one column per accident year
boot_total <- rowSums(boot)
mk <- mack(tri, "paid")
cat(sprintf("ODP bootstrap scale %.1f\n", ob@scale))## ODP bootstrap scale 114.5
boot_years <- cbind(boot[, -1], boot_total)
vs_mack <- data.frame(
year = c(as.character(YEARS[-1]), "Total"),
boot_mean = unname(colMeans(boot_years)),
boot_sd = unname(apply(boot_years, 2, stats::sd)),
mack_reserve = c(mk@reserve[-1], mk@total_reserve),
mack_se = c(mk@standard_error[-1], mk@total_standard_error)
)
gt(vs_mack, rowname_col = "year") |>
tab_header("ODP bootstrap against Mack", "Money in the units of the triangle; 10,000 draws") |>
cols_label(boot_mean = "bootstrap mean", boot_sd = "bootstrap SD",
mack_reserve = "Mack reserve", mack_se = "Mack SE") |>
fmt_integer(columns = c(boot_mean, boot_sd, mack_reserve, mack_se))| ODP bootstrap against Mack | ||||
| Money in the units of the triangle; 10,000 draws | ||||
| bootstrap mean | bootstrap SD | Mack reserve | Mack SE | |
|---|---|---|---|---|
| 1989 | 3,383 | 926 | 3,398 | 39 |
| 1990 | 8,140 | 1,372 | 8,155 | 44 |
| 1991 | 14,545 | 1,769 | 14,579 | 410 |
| 1992 | 22,600 | 2,184 | 22,645 | 850 |
| 1993 | 31,822 | 2,549 | 31,865 | 1,364 |
| 1994 | 45,712 | 3,013 | 45,753 | 1,959 |
| 1995 | 60,075 | 3,624 | 60,093 | 2,308 |
| 1996 | 80,887 | 4,545 | 80,983 | 3,179 |
| 1997 | 105,942 | 6,839 | 105,874 | 9,192 |
| Total | 373,105 | 14,194 | 373,346 | 10,939 |
library(ggplot2, exclude = "layer") # keeps prospicio's layer()
grid <- data.frame(x = seq(280000, 470000, length.out = 300))
grid$mack <- stats::dnorm(grid$x, mk@total_reserve, mk@total_standard_error)
grid$glm <- stats::dnorm(grid$x, cc@total_reserve, pe$rmsep[K])
ggplot() +
geom_histogram(aes(x = boot_total, y = after_stat(density), fill = "ODP bootstrap draws"),
bins = 60) +
geom_line(aes(x, mack, colour = "normal, Mack SE"), data = grid) +
geom_line(aes(x, glm, colour = "normal, GLM RMSEP"), data = grid) +
scale_fill_manual(values = c("ODP bootstrap draws" = "grey75")) +
scale_x_continuous(labels = scales::comma) +
labs(x = "total reserve (units of the triangle)", y = "density", fill = NULL, colour = NULL,
title = "Total reserve: the bootstrap is wider than Mack's error")The bootstrap’s total RMSEP is near the parametric bootstrap’s.
Mack’s is about a quarter lower, and very small for the older years.
Mack’s variance comes from the scatter of the age-to-age factors, which
is little in the later columns; the ODP ties each payment’s variance to
its size through one phi. Two models with the same forecast
can have different prediction errors (monograph section 5.4.1), and here
the difference is large.
5. Residual diagnostics
Chapter 6 checks the fit with residuals. A cell’s standardized
deviance residual is its deviance residual over
sqrt(phi * (1 - h)), with h the leverage (the
hat-matrix diagonal). The fit’s residuals gives these for
each observed cell, with Pearson residuals, leverages and
actual-to-fitted ratios; residual_summary() groups them by
development, accident or calendar year:
dev <- residual_summary(cc, "development")
cal <- residual_summary(cc, "calendar")
cat("by development year 1 to 8, spread (sd) of the residuals\n")## by development year 1 to 8, spread (sd) of the residuals
## 1.42 1.68 0.94 0.67 0.91 0.86 0.75 0.49
cat("by calendar year 1988 to 1997, mean residual\n")## by calendar year 1988 to 1997, mean residual
## -0.38 -0.13 -0.40 +0.56 +0.42 -0.43 +0.23 -0.27 -0.26 +0.32
panels <- rbind(
data.frame(panel = "Spread by development year", x = 1:8, y = dev$sd[1:8]),
data.frame(panel = "Mean by calendar year", x = 1988:1997, y = cal$mean)
)
panels$panel <- factor(panels$panel, levels = unique(panels$panel))
ggplot(panels, aes(x, y)) +
geom_col(fill = "grey75") +
facet_wrap(~panel, scales = "free") +
scale_x_continuous(breaks = function(lim) seq(ceiling(lim[1]), floor(lim[2]), by = 2)) +
labs(x = "year (development, left; calendar, right)",
y = "standardized residual (sd, left; mean, right)",
title = "Standardized deviance residuals")The spreads use divisor n - 1. Two cells have leverage
one, the last of 1988 and the first of 1997. Each is the only
observation of its parameter, so its residual is undefined. Development
year 10 has no residual and year 9 has two, too few for a spread.
Development years 1 and 2 scatter more than later years (Figure 6-19),
and the calendar-year means change from negative to positive (Figure
6-20).
Actual and fitted totals agree on every row and column, so one-way comparisons show no problem. The ratio of actual to fitted for each cell can (Figure 6-22):
heat_map <- function(fit, title) {
r <- fit@residuals
columns <- as.character(1:K)
ratio <- matrix(NA_real_, K, K, dimnames = list(NULL, columns))
for (i in seq_len(K)) {
x <- 100 * r$actual_to_fitted[r$origin == YEARS[i]]
ratio[i, seq_along(x)] <- x
}
frame <- data.frame(year = as.character(YEARS), ratio, check.names = FALSE)
gt(frame, rowname_col = "year") |>
tab_header(title, "Actual over fitted in percent; columns are development years") |>
fmt_integer(columns = columns) |>
sub_missing(missing_text = "") |>
data_color(columns = columns, domain = c(80, 120), palette = c("firebrick", "white", "steelblue"),
na_color = "white")
}
heat_map(cc, "Figure 6-22: the cross-classified model")| Figure 6-22: the cross-classified model | ||||||||||
| Actual over fitted in percent; columns are development years | ||||||||||
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | |
|---|---|---|---|---|---|---|---|---|---|---|
| 1988 | 98 | 100 | 100 | 104 | 113 | 87 | 96 | 92 | 100 | 100 |
| 1989 | 99 | 99 | 106 | 103 | 95 | 95 | 99 | 102 | 100 | |
| 1990 | 96 | 108 | 107 | 91 | 90 | 102 | 92 | 104 | ||
| 1991 | 97 | 103 | 96 | 97 | 103 | 111 | 111 | |||
| 1992 | 95 | 107 | 100 | 100 | 97 | 100 | ||||
| 1993 | 98 | 105 | 93 | 101 | 104 | |||||
| 1994 | 109 | 91 | 95 | 104 | ||||||
| 1995 | 106 | 90 | 105 | |||||||
| 1996 | 103 | 97 | ||||||||
| 1997 | 100 | |||||||||
In development year 1 the early accident years are below 100% and the later ones above; development year 2 shows the opposite. The payment pattern changed over the accident years: an interaction of row and column, which the cross-classified model cannot represent. Chapter 7 adds it.
6. Fewer parameters
Chapter 7 starts from Figure 7-1: the ten ln a[k] of
section 2 follow a parabola in k. Model 7-2 replaces them
with a1 * k + a2 * k^2 and keeps all ten
ln b[j] free. It has 12 parameters instead of 19. In
prospicio it is the same odp_glm() call with another
formula:
quad <- odp_glm(tri, "paid", formula = ~ 0 + k + I(k^2) + factor(j))
q <- quad@coefficients
level <- q[[3]]
cat(sprintf("accident year effect %.3f + %.4f k %.4f k^2 (book 10.471 + 0.2001 k - 0.0179 k^2)\n",
level, q[[1]], q[[2]]))## accident year effect 10.471 + 0.2001 k -0.0179 k^2 (book 10.471 + 0.2001 k - 0.0179 k^2)
The development pattern is Table 7-1:
table_7_1 <- data.frame(
j = as.character(2:K),
prospicio = q[4:12] - level,
book = c(-0.206, -0.750, -1.015, -1.452, -1.830, -2.142, -2.353, -2.514, -2.661)
)
gt(table_7_1, rowname_col = "j") |>
tab_header("Table 7-1: ln b[j] - ln b[1] of model 7-2", "By development year j") |>
fmt_number(columns = c(prospicio, book), decimals = 3)| Table 7-1: ln b[j] - ln b[1] of model 7-2 | ||
| By development year j | ||
| prospicio | book | |
|---|---|---|
| 2 | −0.206 | −0.206 |
| 3 | −0.750 | −0.750 |
| 4 | −1.015 | −1.015 |
| 5 | −1.452 | −1.452 |
| 6 | −1.830 | −1.830 |
| 7 | −2.142 | −2.142 |
| 8 | −2.353 | −2.353 |
| 9 | −2.514 | −2.514 |
| 10 | −2.661 | −2.661 |
Model 7-10 (section 7.4, six parameters) replaces the development
effects with a straight line in j with a kink at 7.5 and
adds a term for development year 2. Model 7-14 (section 7.6, ten
parameters) adds the interactions that the heat map showed: a shift of
development years 1 and 2 for accident years 1 to 6, a trend in accident
year for development year 3 and a term for development year 4.
early <- as.numeric(k <= 6) # accident years 1 to 6
smooth <- odp_glm(tri, "paid", formula = ~ k + I(k^2) + I(j - 1) + I(pmax(0, j - 7.5)) + I(1 * (j == 2)))
interact <- odp_glm(tri, "paid", formula = ~ k + I(k^2) + I(j - 1) + I(pmax(0, j - 7.5)) + I(1 * (j == 2)) +
I(1 * (j == 4)) + I((j == 1) * early) + I((j == 2) * early) + I((j == 3) * k))
missing <- rep(NA_real_, 4) # model 7-10 has no c2 and d1 to d3
table_7_5 <- data.frame(
coefficient = c("a0", "a1", "a2", "b1", "b2", "c1", "c2", "d1", "d2", "d3"),
m710 = c(smooth@coefficients, missing),
t73 = c(10.469, 0.200, -0.018, -0.358, 0.236, 0.155, missing),
m714 = interact@coefficients,
t75 = c(10.4900, 0.2066, -0.0183, -0.3685, 0.2720, 0.0375, 0.0528, -0.0671, 0.1273, -0.0113)
)
gt(table_7_5, rowname_col = "coefficient") |>
tab_header("Models 7-10 and 7-14 against Tables 7-3 and 7-5", "Model 7-10's c is c1 of model 7-14") |>
cols_label(m710 = "model 7-10", t73 = "Table 7-3", m714 = "model 7-14", t75 = "Table 7-5") |>
fmt_number(columns = c(m710, m714, t75), decimals = 4) |>
fmt_number(columns = t73, decimals = 3) |>
sub_missing(missing_text = "")| Models 7-10 and 7-14 against Tables 7-3 and 7-5 | ||||
| Model 7-10's c is c1 of model 7-14 | ||||
| model 7-10 | Table 7-3 | model 7-14 | Table 7-5 | |
|---|---|---|---|---|
| a0 | 10.4687 | 10.469 | 10.4904 | 10.4900 |
| a1 | 0.2001 | 0.200 | 0.2066 | 0.2066 |
| a2 | −0.0179 | −0.018 | −0.0183 | −0.0183 |
| b1 | −0.3577 | −0.358 | −0.3685 | −0.3685 |
| b2 | 0.2356 | 0.236 | 0.2720 | 0.2720 |
| c1 | 0.1545 | 0.155 | 0.0375 | 0.0375 |
| c2 | 0.0528 | 0.0528 | ||
| d1 | −0.0671 | −0.0671 | ||
| d2 | 0.1273 | 0.1273 | ||
| d3 | −0.0113 | −0.0113 | ||
cat(sprintf("phi: 7-2 %.1f, 7-10 %.1f, 7-14 %.1f\n", quad@dispersion, smooth@dispersion, interact@dispersion))## phi: 7-2 102.6, 7-10 107.3, 7-14 53.9
Both fits agree with the tables. Model 7-10’s c1 is
0.1544995, which rounds to 0.154 where Table 7-3 prints 0.155 (SAS
differs in the seventh decimal). Table 7-5 prints 10.490 for
a0 with an added trailing zero. Model 7-14’s
c1 is for development year 2 and c2 for year
4, then d1 to d3, the monograph’s order.
phi falls from 114.5 to about 54 with the interactions, the
main reason for their lower prediction error.
The heat map of the six-parameter model (Figure 7-5) shows the pattern that the interactions correct:
heat_map(smooth, "Figure 7-5: the six-parameter model")| Figure 7-5: the six-parameter model | ||||||||||
| Actual over fitted in percent; columns are development years | ||||||||||
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | |
|---|---|---|---|---|---|---|---|---|---|---|
| 1988 | 99 | 101 | 98 | 111 | 112 | 84 | 97 | 96 | 100 | 97 |
| 1989 | 99 | 99 | 102 | 109 | 93 | 90 | 99 | 106 | 99 | |
| 1990 | 95 | 107 | 102 | 96 | 88 | 97 | 92 | 107 | ||
| 1991 | 97 | 103 | 94 | 104 | 102 | 107 | 113 | |||
| 1992 | 97 | 108 | 99 | 108 | 97 | 98 | ||||
| 1993 | 97 | 104 | 89 | 106 | 101 | |||||
| 1994 | 110 | 92 | 93 | 112 | ||||||
| 1995 | 102 | 87 | 99 | |||||||
| 1996 | 105 | 98 | ||||||||
| 1997 | 101 | |||||||||
7. Forecasts and prediction error of the smaller models
Tables 7-2, 7-4 and 7-6 give the monograph’s parametric bootstrap of
each model, run as in section 4. The table adds the delta method of
section 3 (the Total row of prediction_error),
which applies to every design and has no simulation noise:
BOOK <- list("7-2 quadratic" = c(373641, 13086), "7-10 smooth" = c(373403, 13248),
"7-14 interactions" = c(371559, 10907))
models <- list(quad, smooth, interact)
totals <- do.call(rbind, lapply(seq_along(BOOK), function(i) {
fit <- models[[i]]
delta <- fit@prediction_error[K + 1, ] # the Total row
total <- rowSums(by_year_draws(fit, seed = 1))
data.frame(model = names(BOOK)[i], delta_forecast = delta$reserve, delta_rmsep = delta$rmsep,
boot_mean = mean(total), boot_rmsep = stats::sd(total),
book_mean = BOOK[[i]][1], book_rmsep = BOOK[[i]][2])
}))
gt(totals, rowname_col = "model") |>
tab_header("Total reserve of the smaller models", "Money in the units of the triangle") |>
cols_label(delta_forecast = "delta forecast", delta_rmsep = "delta RMSEP", boot_mean = "bootstrap mean",
boot_rmsep = "bootstrap RMSEP", book_mean = "book mean", book_rmsep = "book RMSEP") |>
fmt_integer(columns = c(delta_forecast, delta_rmsep, boot_mean, boot_rmsep, book_mean, book_rmsep))| Total reserve of the smaller models | ||||||
| Money in the units of the triangle | ||||||
| delta forecast | delta RMSEP | bootstrap mean | bootstrap RMSEP | book mean | book RMSEP | |
|---|---|---|---|---|---|---|
| 7-2 quadratic | 372,532 | 13,030 | 373,866 | 13,131 | 373,641 | 13,086 |
| 7-10 smooth | 373,006 | 13,215 | 373,675 | 13,392 | 373,403 | 13,248 |
| 7-14 interactions | 370,493 | 11,021 | 370,965 | 11,135 | 371,559 | 10,907 |
The bootstrap totals are within simulation noise of the monograph, with the lognormal bias of section 4. As in the monograph, the quadratic accident-year effect lowers the total RMSEP from about 14,100 to 13,000 with little change in the forecast, and the smooth development pattern raises it a little. The interactions lower it to about 11,000 (CV near 3%) because they model the change in the payment pattern, which the chain ladder treats as noise.
By year, the interaction model (Table 7-6):
TABLE_7_6 <- rbind(
c(3630, 569, 15.7), c(8557, 935, 10.9), c(14563, 1203, 8.3), c(22193, 1418, 6.4),
c(32505, 1677, 5.2), c(45771, 2018, 4.4), c(62998, 2459, 3.9), c(79601, 3079, 3.9),
c(101742, 4094, 4.0), c(371559, 10907, 2.9)
)
sim_table(by_year_draws(interact, seed = 1), TABLE_7_6, "Table 7-6: model 7-14, parametric bootstrap")| Table 7-6: model 7-14, parametric bootstrap | |||
| Money in the units of the triangle; CVP in percent | |||
| mean | RMSEP | CVP % | |
|---|---|---|---|
| 1989 | 3,635 | 560 | 15.4 |
| 1989, book | 3,630 | 569 | 15.7 |
| 1990 | 8,573 | 937 | 10.9 |
| 1990, book | 8,557 | 935 | 10.9 |
| 1991 | 14,576 | 1,204 | 8.3 |
| 1991, book | 14,563 | 1,203 | 8.3 |
| 1992 | 22,218 | 1,418 | 6.4 |
| 1992, book | 22,193 | 1,418 | 6.4 |
| 1993 | 32,521 | 1,694 | 5.2 |
| 1993, book | 32,505 | 1,677 | 5.2 |
| 1994 | 45,714 | 1,992 | 4.4 |
| 1994, book | 45,771 | 2,018 | 4.4 |
| 1995 | 63,015 | 2,423 | 3.8 |
| 1995, book | 62,998 | 2,459 | 3.9 |
| 1996 | 79,385 | 3,143 | 4.0 |
| 1996, book | 79,601 | 3,079 | 3.9 |
| 1997 | 101,327 | 4,191 | 4.1 |
| 1997, book | 101,742 | 4,094 | 4.0 |
| Total | 370,965 | 11,135 | 3.0 |
| Total, book | 371,559 | 10,907 | 2.9 |
Each year agrees within noise. The forecast for 1997, whose only payment is in development year 1, where the pattern changed, falls from 105,874 to about 101,300 (101,742 in Table 7-6).
8. Choosing between the models
Table 7-7 compares the four models by AIC, BIC and generalized
cross-validation (GCV). The monograph’s log-likelihood is the Poisson
kernel sum(y log(mu) - mu) / phi, with phi
held at the interaction model’s value for all models, so the comparison
measures fit, not a change of scale. GCV (section 4.4) is
n * RSS / (n - p)^2, with RSS the plain sum of
squared differences between actual and fitted.
y <- cc@residuals$actual # the 55 observed increments
n <- length(y)
phi_fixed <- interact@dispersion
TABLE_7_7 <- rbind(c(-509392, -509354, 6685428), c(-509400, -509376, 5075351),
c(-509397, -509385, 4311874), c(-509441, -509421, 1733202))
labels <- c("chain ladder", "7-2 quadratic", "7-10 smooth", "7-14 interactions")
fits <- list(cc, quad, smooth, interact)
criteria <- do.call(rbind, lapply(1:4, function(i) {
mu <- fits[[i]]@residuals$fitted
p <- length(fits[[i]]@coefficients)
loglik <- sum(y * log(mu) - mu) / phi_fixed
aic <- -2 * loglik + 2 * p
bic <- -2 * loglik + p * log(n)
gcv <- n * sum((y - mu)^2) / (n - p)^2
data.frame(model = c(labels[i], paste0(labels[i], ", book")),
aic = c(aic, TABLE_7_7[i, 1]), bic = c(bic, TABLE_7_7[i, 2]), gcv = c(gcv, TABLE_7_7[i, 3]))
}))
gt(criteria, rowname_col = "model") |>
tab_header("Table 7-7: AIC, BIC and GCV", "Lower is better") |>
cols_label(aic = "AIC", bic = "BIC", gcv = "GCV") |>
fmt_integer(columns = c(aic, bic, gcv))| Table 7-7: AIC, BIC and GCV | |||
| Lower is better | |||
| AIC | BIC | GCV | |
|---|---|---|---|
| chain ladder | −509,391 | −509,353 | 6,685,459 |
| chain ladder, book | −509,392 | −509,354 | 6,685,428 |
| 7-2 quadratic | −509,399 | −509,375 | 5,075,358 |
| 7-2 quadratic, book | −509,400 | −509,376 | 5,075,351 |
| 7-10 smooth | −509,396 | −509,384 | 4,311,876 |
| 7-10 smooth, book | −509,397 | −509,385 | 4,311,874 |
| 7-14 interactions | −509,440 | −509,420 | 1,733,200 |
| 7-14 interactions, book | −509,441 | −509,421 | 1,733,202 |
GCV agrees to five significant figures. AIC and BIC are 0.7 to 1.4 above the monograph’s, a difference of level only: differences between models agree within the printed rounding, and every criterion ranks the models as the monograph does, with the interaction model best.
The level is sensitive: the log-likelihood is about 254,700 in these
units, so a relative difference of 2e-6 in
phi, or a looser convergence test elsewhere, moves the AIC
by one. The code uses each fit’s fitted values and coefficients because
the monograph defines its own criteria; a GLM’s usual Poisson AIC
answers a different question.
9. A gamma cross-classified model
Chapter 2 of the monograph puts the ODP in the Tweedie family.
Section 6.5 gives a gamma error (variance proportional to the mean
squared) as the alternative to try when the residual spread grows with
the fitted value. The monograph prints no gamma results for this
triangle. In prospicio the fit needs one argument,
family = "gamma" (or "tweedie" with a
power between 1 and 2). This uses the default
cross-classified design:
## gamma phi 0.0047
by_gamma <- data.frame(
year = c(as.character(YEARS[-1]), "Total"),
chain_ladder = c(cc@reserves[-1], cc@total_reserve),
gamma = c(gamma@reserves[-1], gamma@total_reserve)
)
gt(by_gamma, rowname_col = "year") |>
tab_header("Reserves of the cross-classified model", "Poisson (the chain ladder) against gamma") |>
cols_label(chain_ladder = "chain ladder") |>
fmt_integer(columns = c(chain_ladder, gamma))| Reserves of the cross-classified model | ||
| Poisson (the chain ladder) against gamma | ||
| chain ladder | gamma | |
|---|---|---|
| 1989 | 3,398 | 3,423 |
| 1990 | 8,155 | 8,134 |
| 1991 | 14,579 | 15,086 |
| 1992 | 22,645 | 22,667 |
| 1993 | 31,865 | 31,820 |
| 1994 | 45,753 | 45,434 |
| 1995 | 60,093 | 60,216 |
| 1996 | 80,983 | 80,829 |
| 1997 | 105,874 | 105,857 |
| Total | 373,346 | 373,466 |
The gamma fit weights each cell’s relative error equally and does not
keep the row and column totals, so its forecasts differ slightly from
the chain ladder’s. The fit’s prediction_error applies the
delta method of section 3 with process variance
phi * mu^2.
10. What matched
Every table and figure above agrees with the monograph to the printed digits, apart from these known differences:
- The parametric bootstraps (Tables 5-5, 7-2, 7-4 and 7-6) differ by simulation noise and by the process distribution, which the monograph does not state. Their means have the lognormal bias.
- The AIC and BIC of Table 7-7 differ by about one unit in 509,000,
from
phior convergence. GCV agrees to five figures. - Three renormalised ultimates of Table 3-5 are one unit different from Table 3-3, because the monograph rounds.