Commit 18b4f8ab authored by Reinhold Kainhofer's avatar Reinhold Kainhofer

Add function generateAgeShift

parent a0edf0e6
......@@ -2,6 +2,7 @@
S3method(plot,mortalityTable)
export(deathProbabilitiesIndividual)
export(generateAgeShift)
export(makeQxDataFrame)
export(mortalityComparisonTable)
export(mortalityTable)
......
......@@ -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))
}
......@@ -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)
% 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))
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment