do.BackTesting: Perform Out-of-Sample Testing of Mortality Forecasts Over One...

Description Usage Arguments See Also Examples

View source: R/do_BackTesting.R

Description

Perform Out-of-Sample Testing of Mortality Forecasts Over One Time Period

Usage

1
2
3
do.BackTesting(data, data.B = NULL, x, y.fit, y.for, data.in = c("qx",
  "mx", "dx", "lx"), models, level = 95, jumpchoice = c("actual",
  "fit"), verbose = FALSE, ...)

Arguments

data

A data.frame or a matrix containing mortality data with ages x as row and time y as column. This object should contain the data to be used in fitting (training) and validation process as well.

data.B

A data.frame or a matrix containing mortality data for the benchmark population. This dataset is needed only in the coherent mortality models (e.g. LiLee, OeppenC). Must be the same format as in data;

x

Numerical vector indicating the ages in input data. Optional. Default: NULL.

y.fit

Years to be considered in fitting.

y.for

Years to be forecast.

data.in

Specify the type of input data. Various life table indices are accepted: "qx", "mx", "dx", "lx".

models

One or several mortality models to be estimated. The following options are available:

  • "MRW" – The Multivariate Random-Walk (w/o Drift);

  • "MRWD" – The Multivariate Random-Walk with Drift;

  • "LeeCarter" – The Lee-Carter Mortality Model;

  • "LiLee" – The Li-Lee Mortality Model;

  • "HyndmanUllah" – The Hyndman-Ullah Mortality Model;

  • "RenshawHaberman" – The Renshaw-Haberman Mortality Model;

  • "Oeppen" – The Oeppen Mortality Model;

  • "OeppenC" – The Coherent Oeppen Mortality Model;

  • "MEM2" – The Maximum Entropy Mortality Model of order 2;

  • "MEM3" – The Maximum Entropy Mortality Model of order 3;

  • "MEM4" – The Maximum Entropy Mortality Model of order 4;

  • "MEM5" – The Maximum Entropy Mortality Model of order 5;

  • "MEM6" – The Maximum Entropy Mortality Model of order 6;

  • "MEM7" – The Maximum Entropy Mortality Model of order 7;

level

Significance level of the confidence interval.

jumpchoice

Method used for computation of jumpchoice. Possibilities: "actual" (use actual rates from final year) and "fit" (use fitted rates).

verbose

A logical value. Set verbose = FALSE to silent the process that take place inside the function and avoid progress messages.

...

Arguments to be passed to or from other methods.

See Also

do.BBackTesting evalAccuracy.BackTesting

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
library(magrittr)

x  <- 0:100            # Ages
y1 <- 1980:2000        # Training period
y2 <- 2001:2016        # Validation period
y  <- c(y1, y2)        # entire period
K <- "GBRTENW"         # Country to be analysed

# Mortality data for country: K
mx.country <- HMD_male$mx[[K]][paste(x), paste(y)] %>% replace.zeros

# Create a mortality data for a benchmark population
# to be used in "LiLee" and "OeppenC" models
average_mx <- function(w) prod(w, na.rm = TRUE)^(1/(length(w)))

Mx <- HMD_male$mx %>% 
  lapply(as.matrix) %>% 
  lapply(replace.zeros) %>% 
  simplify2array() %>% 
  apply(., 1:2, FUN = average_mx) %>% 
  as.data.frame()

mx.benchmark <- Mx[paste(x), paste(y)]

# Select various mortality models
MM <- c("MRWD", "LeeCarter", "LiLee", "HyndmanUllah", 
        "Oeppen", "OeppenC", "MEM5", "MEM6")
# Fit & Forecast the models 
B <- do.BackTesting(data = mx.country,
                    data.B = mx.benchmark,
                    x = x,
                    y.fit = y1, 
                    y.for = y2,
                    data.in = "mx",
                    models = MM)

# Compute accuracy measures for resulted life exectancies
A <- evalAccuracy(B, data.out = "ex")
A
# Rank the model's performance.
R <- do.Ranking(A)
R
R[, c(1:3, 20)]

# Visualize the results
plot(B, data.out = "ex", facet = "x", 
     which = c(0, 20, 40, 60, 75, 90))
plot(B, data.out = "mx", facet = "y", which = 2016) 

mpascariu/MortalityForecast documentation built on Sept. 28, 2020, 2:40 p.m.