diff --git a/NAMESPACE b/NAMESPACE index 821a3ff52efe1af200a9df302a75425b397b3f5c..db08addcdceaace162ca9819219269300fbdd8e5 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -2,6 +2,7 @@ S3method(plot,mortalityTable) export(deathProbabilitiesIndividual) +export(generateAgeShift) export(makeQxDataFrame) export(mortalityComparisonTable) export(mortalityTable) diff --git a/R/mortalityTable.ageShift.R b/R/mortalityTable.ageShift.R index d7bfc69c13bd83a9713d9d6a946957d3a9efb5af..8caa4df78b0e9801a79f1e3fbd4d4e49248a404f 100644 --- a/R/mortalityTable.ageShift.R +++ b/R/mortalityTable.ageShift.R @@ -20,3 +20,21 @@ mortalityTable.ageShift = setClass( ), contains = "mortalityTable.period" ) + +#' Generate data.frame containing age shifts for each birth year +#' +#' Generate a dataframe suitable to be passed to the mortalityTable.ageShift +#' class. +#' +#' @param initial Age shift for the first birth year given in the \code{YOBs} vector +#' @param YOBs Vector of birth years in which the age shift changes by \code{step}. The last entry gives the first birth year that does not have any shift defined any more. +#' @param step How much the age shift changes in each year given in the \code{YOBs} vector +#' +#' @examples generateAgeShift(1, YOBs = c(1922, 1944, 1958, 1973, 1989, 2006, 2023, 2041, 2056)) +#' @export +generateAgeShift = function(initial = 0, YOBs = c(1900, 2100), step = -1) { + lns = diff(YOBs) + shifts = unlist(mapply(rep, initial + step * 0:(length(lns)-1), lns, SIMPLIFY = TRUE)) + data.frame(shifts = shifts, row.names = YOBs[1]:(tail(YOBs, 1)-1)) +} + diff --git a/inst/extdata/MortalityTables_Austria_Annuities_AVOe1996R.R b/inst/extdata/MortalityTables_Austria_Annuities_AVOe1996R.R index 6aaa166b82b2caa42fdbef51a1dd0f8cfadda428..973338d3080e771a9bff57ec1d993967ab980965 100644 --- a/inst/extdata/MortalityTables_Austria_Annuities_AVOe1996R.R +++ b/inst/extdata/MortalityTables_Austria_Annuities_AVOe1996R.R @@ -61,5 +61,18 @@ AVOe1996R.female.group = mortalityTable.trendProjection( dampingFunction = AVOe1996R.trend.switching ); +AVOe1996R.male.av325 = mortalityTable.ageShift( + name = "AVÖ 1996R M mit Altersverschiebung (3,25%)", + ages = AVOe1996R.male, + deathProbs = deathProbabilities(AVOe1996R.male, YOB = 1950), + ageShifts = generateAgeShift(initial = 1, YOBs = c(1922, 1944, 1958, 1973, 1989, 2006, 2023, 2041, 2056)) +) +AVOe1996R.female.av325 = mortalityTable.ageShift( + name = "AVÖ 1996R F mit Altersverschiebung (3,25%)", + ages = AVOe1996R.female, + deathProbs = deathProbabilities(AVOe1996R.female, YOB = 1950), + ageShifts = generateAgeShift(initial = 2, YOBs = c(1922, 1932, 1945, 1956, 1968, 1980, 1993, 2007, 2021, 2036, 2051, 2056)) +) + rm(AVOe1996R.exakt.data) diff --git a/man/generateAgeShift.Rd b/man/generateAgeShift.Rd new file mode 100644 index 0000000000000000000000000000000000000000..7a7415dabc851753ebf32f9e4f17063171d5e687 --- /dev/null +++ b/man/generateAgeShift.Rd @@ -0,0 +1,23 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/mortalityTable.ageShift.R +\name{generateAgeShift} +\alias{generateAgeShift} +\title{Generate data.frame containing age shifts for each birth year} +\usage{ +generateAgeShift(initial = 0, YOBs = c(1900, 2100), step = -1) +} +\arguments{ +\item{initial}{Age shift for the first birth year given in the \code{YOBs} vector} + +\item{YOBs}{Vector of birth years in which the age shift changes by \code{step}. The last entry gives the first birth year that does not have any shift defined any more.} + +\item{step}{How much the age shift changes in each year given in the \code{YOBs} vector} +} +\description{ +Generate a dataframe suitable to be passed to the mortalityTable.ageShift +class. +} +\examples{ +generateAgeShift(1, YOBs = c(1922, 1944, 1958, 1973, 1989, 2006, 2023, 2041, 2056)) +} +