Skip to content
Snippets Groups Projects
Commit 447a5e01 authored by Reinhold Kainhofer's avatar Reinhold Kainhofer
Browse files

EttlPagler and AVÖ 2018-P pension tables as loadable tables (using options to...

EttlPagler and AVÖ 2018-P pension tables as loadable tables (using options to point to the data file)
parent b71f386c
No related branches found
No related tags found
No related merge requests found
Showing with 108 additions and 66 deletions
File added
File added
File added
File added
File added
File added
File added
#' @import MortalityTables
NULL
stopifnot(require(methods), require(utils), require(MortalityTables), require(dplyr)) # MortalityTable classes; new; Excel reader
stopifnot(require(methods), require(utils), require(MortalityTables), require(dplyr), require(readxl)) # MortalityTable classes; new; Excel reader
############################################################################### #
# ICSLT - International Civil Servants Life Table ----
......@@ -24,7 +24,7 @@ readICSLT = function(filename, name = "ICSLT 2018", year = 2018, coloffset = 0)
years = as.numeric(head[1,which(head[2,] == "qx_Male")]),
ages = qx[,1, drop = TRUE],
data = list(
dim = list(sex = "m", collar = "ICSLT", type = name, data = "official", year = year)
dim = list(sex = "m", collar = "ICSLT", table = name, type = name, data = "official", year = year)
)
)
ICSLT$w = mortalityTable.observed(
......@@ -33,7 +33,7 @@ readICSLT = function(filename, name = "ICSLT 2018", year = 2018, coloffset = 0)
years = as.numeric(head[1,which(head[2,] == "qx_Female")]),
ages = qx[,1, drop = TRUE],
data = list(
dim = list(sex = "f", collar = "ICSLT", type = name, data = "official", year = year)
dim = list(sex = "f", collar = "ICSLT", table = name, type = name, data = "official", year = year)
)
)
ICSLT
......@@ -50,11 +50,11 @@ if (!is.null(getOption("MortalityTables.ICSLT2013"))) {
} else {
message("Path to the ICSLT©2013.xlsx data file (option 'MortalityTables.ICSLT2013' not set, ICSLT2013 will not be available!")
}
if (!is.null(getOption("MortalityTables.ICSLT2008"))) {
ICSLT2008 = readICSLT(getOption("MortalityTables.ICSLT2008"), name = "ICSLT 2008", year = 2008)
} else {
message("Path to the ICSLT©2008.xlsx data file (option 'MortalityTables.ICSLT2008' not set, ICSLT2008 will not be available!")
}
# if (!is.null(getOption("MortalityTables.ICSLT2008"))) {
# ICSLT2008 = readICSLT(getOption("MortalityTables.ICSLT2008"), name = "ICSLT 2008", year = 2008)
# } else {
# message("Path to the ICSLT©2008.xlsx data file (option 'MortalityTables.ICSLT2008' not set, ICSLT2008 will not be available!")
# }
# options(MortalityTables.ICSLT2013 = "/home/reinhold/R/Tables-Private/ICSLT/ICSLT©2013.xlsx")
# options(MortalityTables.ICSLT2018 = "/home/reinhold/R/Tables-Private/ICSLT/ICSLT©2018.xlsx")
......
......@@ -9,26 +9,15 @@ stopifnot(require(methods), require(utils), require(MortalityTables), require(dp
# Pension Table AVÖ 2018-P ----
############################################################################### #
AVOe2018P = array(
data = c(mortalityTable.NA),
dim = c(3, 2, 2),
dimnames = list(Geschlecht = c("m", "w", "u"), Bestand = c("Angestellte", "Mischbestand"), Invalidisierung = c("IP", "IPRG"))
)
{
AVOe2018P.file.Ang = getOption("MortalityTables.AVOe2018PAng")
AVOe2018P.file.Misch = getOption("MortalityTables.AVOe2018PMisch")
if (is.null(AVOe2018P.file.Ang)) {
warning("The pension table AVOe2018P requires the Excel file 'AVOe2018P_Pensionstafeln_Angestellte.xlsx'. Please set the paths to it with options(\"MortalityTables.AVOe2018PAng\" = \"/path/to/AVOe2018P_Pensionstafeln_Angestellte.xlsx\"")
}
if (is.null(AVOe2018P.file.Misch)) {
warning("The pension table AVOe2018P requires the Excel file 'AVOe2018P_Pensionstafeln_Mischbestand.xlsx'. Please set the paths to it with options(\"MortalityTables.AVOe2018PMisch\" = \"/path/to/AVOe2018P_Pensionstafeln_Mischbestand.xlsx\"")
}
if (!is.null(AVOe2018P.file.Ang) && !is.null(AVOe2018P.file.Misch)) {
if (is.null(getOption("MortalityTables.AVOe2018PAng")) && is.null(getOption("MortalityTables.AVOe2018PMisch"))) {
message("The pension table AVOe2018P requires the Excel files 'AVOe2018P_Pensionstafeln_Angestellte.xlsx' or 'AVOe2018P_Pensionstafeln_Mischbestand.xlsx'. Please set the paths to them with options(\"MortalityTables.AVOe2018PAng\" = \"/path/to/AVOe2018P_Pensionstafeln_Angestellte.xlsx\") and options(\"MortalityTables.AVOe2018PMisch\" = \"..\").")
} else {
AVOe2018P = array(
data = c(mortalityTable.NA),
dim = c(3, 2, 2),
dimnames = list(Geschlecht = c("m", "w", "u"), Bestand = c("Angestellte", "Mischbestand"), Invalidisierung = c("IP", "IPRG"))
)
#------------------------------------------------------------------------------- -
# Functions to load the tables (raw base tables and trend) and the additional info ----
......@@ -44,17 +33,20 @@ AVOe2018P = array(
loadAVOe2018P.data = function(file, sex = "M", collar = "Angestellte", IPtype = "IP") {
if (is.null(file)) {
return()
}
if (!sex %in% c("M", "F", "U")) {
warning("Invalid sex given in call to loadAVOe2018P.table: ", sex, "; Allowed values are M, F and U.")
return
return()
}
if (!collar %in% c("Angestellte", "Mischbestand")) {
warning("Invalid collar given in call to loadAVOe2018P.table: ", collar, "; Allowed values are Angestellte and Mischbestand.")
return
return()
}
if (!IPtype %in% c("IP", "IPRG")) {
warning("Invalid type given in call to loadAVOe2018P.table: ", IPtype, "; Allowed values are IP and IPRG.")
return
return()
}
sheet = recode(sex, "M" = "Männer", "F" = "Frauen", "U" = "Unisex")
......@@ -212,11 +204,17 @@ AVOe2018P = array(
for (sex in dimnames(AVOe2018P)$Geschlecht) {
for (collar in dimnames(AVOe2018P)$Bestand) {
for (IPtype in dimnames(AVOe2018P)$Invalidisierung) {
fl = if(collar == "Mischbestand") AVOe2018P.file.Misch else AVOe2018P.file.Ang
AVOe2018P[[sex, collar, IPtype]] = loadAVOe2018P.data(file = fl, sex = recode(sex, "m" = "M", "w" = "F", "u" = "U"), collar = collar, IPtype = IPtype)
AVOe2018P[[sex, collar, IPtype]] = loadAVOe2018P.data(
file = if(collar == "Mischbestand")
getOption("MortalityTables.AVOe2018PMisch")
else
getOption("MortalityTables.AVOe2018PAng"),
sex = recode(sex, "m" = "M", "w" = "F", "u" = "U"),
collar = collar,
IPtype = IPtype)
}
}
}
}
rm(loadAVOe2018P.data)
}
#' @import MortalityTables
NULL
stopifnot(require(methods), require(utils), require(MortalityTables)) # MortalityTable classes; new; Excel reader
stopifnot(require(methods), require(utils), require(MortalityTables), require(readxl)) # MortalityTable classes; new; Excel reader
############################################################################### #
# Pension Table AVÖ 2018-P ----
############################################################################### #
if (is.null(getOption("MortalityTables.EttlPagler"))) {
message("The pension table EttlPagler requires the Excel file 'Austria_Pensions_EttlPagler.xlsx'. Please set its path with options(\"MortalityTables.EttlPagler\" = \"/path/to/Austria_Pensions_EttlPagler.xlsx\").")
} else {
###############################################################################
# Ettl/Pagler Male
###############################################################################
EttlPagler.data.M = utils::read.csv(
system.file(
"extdata",
"Austria_Pensions_EttlPagler_M.csv",
package = "MortalityTablesPrivate"),
EttlPagler.data.M = read_excel(
getOption("MortalityTables.EttlPagler"),
skip = 5,
header = FALSE,
col.names = c("age", "qaax", "ix", "qix", "qgx", "qpx", "qwy", "hx", "yx", "x1")
col_names = c("age", "qaax", "ix", "qix", "qgx", "qpx", "qwy", "hx", "yx", "x1")
);
EttlPaglerAges = EttlPagler.data.M[["age"]];
......@@ -27,7 +31,7 @@ EttlPagler.male = pensionTable(
ages = EttlPaglerAges,
deathProbs = EttlPagler.data.M[["qaax"]],
data = list(
dim = list(sex = "m", collar = "Gesamtbestand", type = "Pensionstafel Österreich", data = "official", year = "Ettl/Pagler 1989", risk = "Tod")
dim = list(sex = "m", collar = "Gesamtbestand", table = "Ettl/Pagler 1989", type = "Pensionstafel Österreich", data = "official", year = "Ettl/Pagler 1989", risk = "Tod")
)
),
ix = mortalityTable.period(
......@@ -35,7 +39,7 @@ EttlPagler.male = pensionTable(
ages = EttlPaglerAges,
deathProbs = EttlPagler.data.M[["ix"]],
data = list(
dim = list(sex = "m", collar = "Gesamtbestand", type = "Pensionstafel Österreich", data = "official", year = "Ettl/Pagler 1989", risk = "Invalidisierung")
dim = list(sex = "m", collar = "Gesamtbestand", table = "Ettl/Pagler 1989", type = "Pensionstafel Österreich", data = "official", year = "Ettl/Pagler 1989", risk = "Invalidisierung")
)
),
qgx = mortalityTable.period(
......@@ -43,7 +47,7 @@ EttlPagler.male = pensionTable(
ages = EttlPaglerAges,
deathProbs = EttlPagler.data.M[["qgx"]],
data = list(
dim = list(sex = "m", collar = "Gesamtbestand", type = "Pensionstafel Österreich", data = "official", year = "Ettl/Pagler 1989", risk = "Tod")
dim = list(sex = "m", collar = "Gesamtbestand", table = "Ettl/Pagler 1989", type = "Pensionstafel Österreich", data = "official", year = "Ettl/Pagler 1989", risk = "Tod")
)
),
qix = mortalityTable.period(
......@@ -51,7 +55,7 @@ EttlPagler.male = pensionTable(
ages = EttlPaglerAges,
deathProbs = EttlPagler.data.M[["qix"]],
data = list(
dim = list(sex = "m", collar = "Gesamtbestand", type = "Pensionstafel Österreich", data = "official", year = "Ettl/Pagler 1989", risk = "Tod")
dim = list(sex = "m", collar = "Gesamtbestand", table = "Ettl/Pagler 1989", type = "Pensionstafel Österreich", data = "official", year = "Ettl/Pagler 1989", risk = "Tod")
)
),
rx = mortalityTable.zeroes(name = "No reactivation", ages = EttlPaglerAges),
......@@ -61,7 +65,7 @@ EttlPagler.male = pensionTable(
ages = EttlPaglerAges,
deathProbs = EttlPagler.data.M[["qpx"]],
data = list(
dim = list(sex = "m", collar = "Gesamtbestand", type = "Pensionstafel Österreich", data = "official", year = "Ettl/Pagler 1989", risk = "Tod")
dim = list(sex = "m", collar = "Gesamtbestand", table = "Ettl/Pagler 1989", type = "Pensionstafel Österreich", data = "official", year = "Ettl/Pagler 1989", risk = "Tod")
)
),
hx = mortalityTable.period(
......@@ -69,7 +73,7 @@ EttlPagler.male = pensionTable(
ages = EttlPaglerAges,
deathProbs = EttlPagler.data.M[["hx"]],
data = list(
dim = list(sex = "m", collar = "Gesamtbestand", type = "Pensionstafel Österreich", data = "official", year = "Ettl/Pagler 1989", risk = "Partnerwahrscheinlichkeit im Tod")
dim = list(sex = "m", collar = "Gesamtbestand", table = "Ettl/Pagler 1989", type = "Pensionstafel Österreich", data = "official", year = "Ettl/Pagler 1989", risk = "Partnerwahrscheinlichkeit im Tod")
)
),
qwy = mortalityTable.period(
......@@ -77,7 +81,7 @@ EttlPagler.male = pensionTable(
ages = EttlPaglerAges,
deathProbs = EttlPagler.data.M[["qwy"]],
data = list(
dim = list(sex = "m", collar = "Gesamtbestand", type = "Pensionstafel Österreich", data = "official", year = "Ettl/Pagler 1989", risk = "Tod")
dim = list(sex = "m", collar = "Gesamtbestand", table = "Ettl/Pagler 1989", type = "Pensionstafel Österreich", data = "official", year = "Ettl/Pagler 1989", risk = "Tod")
)
),
yx = mortalityTable.period(
......@@ -85,14 +89,15 @@ EttlPagler.male = pensionTable(
ages = EttlPaglerAges,
deathProbs = EttlPagler.data.M[["yx"]],
data = list(
dim = list(sex = "m", collar = "Gesamtbestand", type = "Pensionstafel Österreich", data = "official", year = "Ettl/Pagler 1989", risk = "Mittl. Hinterbliebenenalter")
dim = list(sex = "m", collar = "Gesamtbestand", table = "Ettl/Pagler 1989", type = "Pensionstafel Österreich", data = "official", year = "Ettl/Pagler 1989", risk = "Mittl. Hinterbliebenenalter")
)
),
invalids.retire = TRUE,
data = list(
Geschlecht = "Männer",
Bestand = "Angestellte",
Invalidisierung = "Invaliditätspension"
Invalidisierung = "Invaliditätspension",
dim = list(sex = "m", collar = "Gesamtbestand", table = "Ettl/Pagler 1989", type = "Pensionstafel Österreich", data = "official", year = "Ettl/Pagler 1989")
)
)
......@@ -100,14 +105,11 @@ EttlPagler.male = pensionTable(
# Ettl/Pagler Female
###############################################################################
EttlPagler.data.F = utils::read.csv(
system.file(
"extdata",
"Austria_Pensions_EttlPagler_F.csv",
package = "MortalityTablesPrivate"),
EttlPagler.data.F = read_excel(
getOption("MortalityTables.EttlPagler"),
sheet = 2,
skip = 5,
header = FALSE,
col.names = c("age", "qaay", "iy", "qiy", "qgy", "qpy", "qwx", "hy", "xy", "y1")
col_names = c("age", "qaay", "iy", "qiy", "qgy", "qpy", "qwx", "hy", "xy", "y1")
);
EttlPaglerAges = EttlPagler.data.F[["age"]];
......@@ -119,7 +121,7 @@ EttlPagler.female = pensionTable(
ages = EttlPaglerAges,
deathProbs = EttlPagler.data.F[["qaay"]],
data = list(
dim = list(sex = "w", collar = "Gesamtbestand", type = "Pensionstafel Österreich", data = "official", year = "Ettl/Pagler 1989", risk = "Tod")
dim = list(sex = "w", collar = "Gesamtbestand", table = "Ettl/Pagler 1989", type = "Pensionstafel Österreich", data = "official", year = "Ettl/Pagler 1989", risk = "Tod")
)
),
ix = mortalityTable.period(
......@@ -127,7 +129,7 @@ EttlPagler.female = pensionTable(
ages = EttlPaglerAges,
deathProbs = EttlPagler.data.F[["iy"]],
data = list(
dim = list(sex = "w", collar = "Gesamtbestand", type = "Pensionstafel Österreich", data = "official", year = "Ettl/Pagler 1989", risk = "Invalidisierung")
dim = list(sex = "w", collar = "Gesamtbestand", table = "Ettl/Pagler 1989", type = "Pensionstafel Österreich", data = "official", year = "Ettl/Pagler 1989", risk = "Invalidisierung")
)
),
qgx = mortalityTable.period(
......@@ -135,7 +137,7 @@ EttlPagler.female = pensionTable(
ages = EttlPaglerAges,
deathProbs = EttlPagler.data.F[["qgy"]],
data = list(
dim = list(sex = "w", collar = "Gesamtbestand", type = "Pensionstafel Österreich", data = "official", year = "Ettl/Pagler 1989", risk = "Tod")
dim = list(sex = "w", collar = "Gesamtbestand", table = "Ettl/Pagler 1989", type = "Pensionstafel Österreich", data = "official", year = "Ettl/Pagler 1989", risk = "Tod")
)
),
qix = mortalityTable.period(
......@@ -143,7 +145,7 @@ EttlPagler.female = pensionTable(
ages = EttlPaglerAges,
deathProbs = EttlPagler.data.F[["qiy"]],
data = list(
dim = list(sex = "w", collar = "Gesamtbestand", type = "Pensionstafel Österreich", data = "official", year = "Ettl/Pagler 1989", risk = "Tod")
dim = list(sex = "w", collar = "Gesamtbestand", table = "Ettl/Pagler 1989", type = "Pensionstafel Österreich", data = "official", year = "Ettl/Pagler 1989", risk = "Tod")
)
),
rx = mortalityTable.zeroes(name = "No reactivation", ages = EttlPaglerAges),
......@@ -153,7 +155,7 @@ EttlPagler.female = pensionTable(
ages = EttlPaglerAges,
deathProbs = EttlPagler.data.F[["qpy"]],
data = list(
dim = list(sex = "w", collar = "Gesamtbestand", type = "Pensionstafel Österreich", data = "official", year = "Ettl/Pagler 1989", risk = "Tod")
dim = list(sex = "w", collar = "Gesamtbestand", table = "Ettl/Pagler 1989", type = "Pensionstafel Österreich", data = "official", year = "Ettl/Pagler 1989", risk = "Tod")
)
),
hx = mortalityTable.period(
......@@ -161,7 +163,7 @@ EttlPagler.female = pensionTable(
ages = EttlPaglerAges,
deathProbs = EttlPagler.data.F[["hy"]],
data = list(
dim = list(sex = "w", collar = "Gesamtbestand", type = "Pensionstafel Österreich", data = "official", year = "Ettl/Pagler 1989", risk = "Partnerwahrscheinlichkeit im Tod")
dim = list(sex = "w", collar = "Gesamtbestand", table = "Ettl/Pagler 1989", type = "Pensionstafel Österreich", data = "official", year = "Ettl/Pagler 1989", risk = "Partnerwahrscheinlichkeit im Tod")
)
),
qwy = mortalityTable.period(
......@@ -169,7 +171,7 @@ EttlPagler.female = pensionTable(
ages = EttlPaglerAges,
deathProbs = EttlPagler.data.F[["qwx"]],
data = list(
dim = list(sex = "w", collar = "Gesamtbestand", type = "Pensionstafel Österreich", data = "official", year = "Ettl/Pagler 1989", risk = "Tod")
dim = list(sex = "w", collar = "Gesamtbestand", table = "Ettl/Pagler 1989", type = "Pensionstafel Österreich", data = "official", year = "Ettl/Pagler 1989", risk = "Tod")
)
),
yx = mortalityTable.period(
......@@ -177,17 +179,22 @@ EttlPagler.female = pensionTable(
ages = EttlPaglerAges,
deathProbs = EttlPagler.data.F[["xy"]],
data = list(
dim = list(sex = "w", collar = "Gesamtbestand", type = "Pensionstafel Österreich", data = "official", year = "Ettl/Pagler 1989", risk = "Tod")
dim = list(sex = "w", collar = "Gesamtbestand", table = "Ettl/Pagler 1989", type = "Pensionstafel Österreich", data = "official", year = "Ettl/Pagler 1989", risk = "Tod")
)
),
invalids.retire = TRUE,
data = list(
Geschlecht = "Männer",
Bestand = "Angestellte",
Invalidisierung = "Invaliditätspension"
Invalidisierung = "Invaliditätspension",
dim = list(sex = "w", collar = "Gesamtbestand", table = "Ettl/Pagler 1989", type = "Pensionstafel Österreich", data = "official", year = "Ettl/Pagler 1989")
)
)
EttlPagler = c(m = EttlPagler.male, w = EttlPagler.female)
rm(EttlPagler.data.F, EttlPagler.data.M, EttlPaglerAges)
}
......@@ -88,6 +88,43 @@ Source: https://www.sirp-isrp.org/index.php?option=com_content&view=article&id=1
* ICSLT 2013
* ICSLT 2018
* gender-specific cohort tables (yearly $q_x$ tabulated for a period of 25 years)
* male+female, ages 16-125
* target population:
* Target collective: International Organisations whose staff are located in Europe
* Publisher: iSRP (OECD), https://www.sirp-isrp.org/index.php?option=com_content&view=article&id=1057&lang=en
* Usage with the `MortalityTables` package:
```{r AVOe2005R, results="hide"}
mortalityTables.load("ICSLT")
ICSLT2013
ICSLT2018
```
### Comparisons
```{r ICSLT.Comparison}
plotMortalityTables(ICSLT2013, ICSLT2018,
aes = aes(color = table, linetype = sex), Period = 2035, title = "ICSLT tables, Period 2035",
legend.position = "right"
)
plotMortalityTrend(ICSLT2013, ICSLT2018,
aes = aes(color = table, linetype = sex), Period = 2020, title = "ICSLT tables, Period 2020",
legend.position = "right", ages = 20:120
)
plotMortalityTrend(ICSLT2013, ICSLT2018,
aes = aes(color = table, linetype = sex), Period = 2040, title = "ICSLT tables, Period 2040",
legend.position = "right", ages = 20:120
)
plotMortalityTrend(ICSLT2013, ICSLT2018,
aes = aes(color = table, linetype = sex), YOB = 2000, title = "ICSLT mortality improvement, YOB 2020",
legend.position = "right", ages = 20:40
)
```
## EU Civil Servant Life Table
* EU Life Table 2016
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment