Commit 8b0a6edd authored by Reinhold Kainhofer's avatar Reinhold Kainhofer

Add class to handle pension tables (first attempt, not finished yet)

parent 872a5d32
......@@ -22,8 +22,8 @@ Description: Classes to implement and plot cohort life tables
as well as period life table, cohort life tables using an age shift, and
merged life tables.
License: GPL (>= 2)
RoxygenNote: 5.0.1
Collate:
RoxygenNote: 6.0.1
Collate:
'mortalityTable.R'
'mortalityTable.period.R'
'mortalityTable.ageShift.R'
......@@ -47,6 +47,7 @@ Collate:
'mortalityTable.jointLives.R'
'mortalityTables.list.R'
'mortalityTables.load.R'
'pensionTable.R'
'plot.mortalityTable.R'
'plotMortalityTableComparisons.R'
'plotMortalityTables.R'
......
......@@ -16,6 +16,7 @@ export(mortalityTable.period)
export(mortalityTable.trendProjection)
export(mortalityTables.list)
export(mortalityTables.load)
export(pensionTable)
export(plotMortalityTableComparisons)
export(plotMortalityTables)
exportClasses(mortalityTable)
......@@ -27,6 +28,7 @@ exportClasses(mortalityTable.mixed)
exportClasses(mortalityTable.observed)
exportClasses(mortalityTable.period)
exportClasses(mortalityTable.trendProjection)
exportClasses(pensionTable)
exportMethods(ageShift)
exportMethods(ages)
exportMethods(baseTable)
......
#' @include mortalityTable.R
NULL
#' Class pensionTable
#'
#' Class \code{pensionTable} is the (virtual) base class for all pensions
#' tables. It contains the name and some general values applying to all
#' types of tables. In particular, it holds individual tables for each of the
#' transition probabilities. Possible states are:
#' * active: healty, no pension, typically paying some kin of premium
#' * incapacity: disablity pension, in most cases permanent, not working, early pension
#' * retirement: old age pension, usually starting with a fixed age
#' * dead
#' * Widow/widower pension
#'
#' Correspondingly, the following transition probabilities can be given:
#' * qxaa: death probability of actives (active -> dead)
#' * ix: invalidity probability (active -> incapacity)
#' * qix: death probability of invalid (invalid -> dead)
#' * rx: reactivation probability (incapacity -> active)
#' * apx: retirement probability (active -> retirement), typically 1 for a fixed age
#' * apx: retirement probability of invalids (invalid -> retirement), typically 0 or 1 for a fixed age
#' * qpx: death probability of retired (retired -> dead)
#' * hx: probability of a widow at moment of death (dead -> widow), y(x) age differene
#' * qxw: death probability of widows/widowers
#' * qgx: death probability of total group (irrespective of state)
#'
#' @slot qx Death probability table of actives (derived from mortalityTable)
#' @slot ix Invalidity probability of actives (derived from mortalityTable)
#' @slot qxi Death probability table of invalids (derived from mortalityTable)
#' @slot rx Reactivation probability of invalids (derived from mortalityTable)
#' @slot apx Retirement probability of actives (derived from mortalityTable)
#' @slot apix Retirement probability of invalids (derived from mortalityTable)
#' @slot qpx Death probability of old age pensioners (derived from mortalityTable)
#' @slot hx Probability of a widow at the moment of death (derived from mortalityTable)
#' @slot qwy Death probability of widow(er)s (derived from mortality Table)
#' @slot yx Age difference of the widow to the deceased
#' @slot qgx Death probability of whole group (derived from mortalityTable), irrespective of state
#'
#' @export pensionTable
#' @exportClass pensionTable
pensionTable = setClass(
"pensionTable",
slots = list(
qx = "mortalityTable",
ix = "mortalityTable",
qix = "mortalityTable",
rx = "mortalityTable",
apx = "mortalityTable",
apix = "mortalityTable",
qpx = "mortalityTable",
hx = "mortalityTable",
qwy = "mortalityTable",
yx = "mortalityTable",
qgx = "mortalityTable"
),
contains = "mortalityTable"
)
#' @describeIn baseTable Return the base table of the joint lives mortality table (returns the base table of the first table used for joint lives)
setMethod("transitionProbabilities", "pensionTable",
function(object, ..., YOB = 1982) {
x = ages(object@qx);
q = deathProbabilities(object@qx, ..., YOB = YOB);
i = deathProbabilities(object@ix, ..., YOB = YOB);
data.frame(x, q, i)
})
......@@ -8,4 +8,14 @@
\description{
Provide life table classes for life insurance purposes
}
\seealso{
Useful links:
\itemize{
\item \url{https://gitlab.open-tools.net/R/r-mortality-tables}
}
}
\author{
\strong{Maintainer}: Reinhold Kainhofer \email{reinhold@kainhofer.com}
}
......@@ -25,6 +25,7 @@ Return the age shift of the age-shifted life table given the birth year
\item \code{mortalityTable.ageShift}: Return the age shift of the age-shifted life table
given the birth year
}}
\examples{
mortalityTables.load("Austria_Annuities")
ageShift(AVOe2005R.male.av, YOB=1910)
......@@ -32,4 +33,3 @@ ageShift(AVOe2005R.male.av, YOB=1955)
ageShift(AVOe2005R.male.av, YOB=2010)
}
......@@ -3,11 +3,11 @@
\docType{methods}
\name{ages}
\alias{ages}
\alias{ages,mortalityTable.joined-method}
\alias{ages,mortalityTable.jointLives-method}
\alias{ages,mortalityTable.period-method}
\alias{ages,mortalityTable.mixed-method}
\alias{ages,mortalityTable.joined-method}
\alias{ages,mortalityTable.observed-method}
\alias{ages,mortalityTable.period-method}
\alias{ages,mortalityTable.jointLives-method}
\title{Return the defined ages of the life table}
\usage{
ages(object, ...)
......@@ -42,6 +42,7 @@ Return the defined ages of the life table
\item \code{mortalityTable.jointLives}: Return the defined ages of the joint lives mortality table (returns the ages of the first table used for joint lives)
}}
\examples{
mortalityTables.load("Austria_*", wildcard=TRUE)
ages(AVOe2005R.male)
......@@ -49,4 +50,3 @@ ages(AVOe1996R.male)
ages(mort.AT.census.2011.male)
}
......@@ -4,8 +4,8 @@
\name{baseTable}
\alias{baseTable}
\alias{baseTable,mortalityTable-method}
\alias{baseTable,mortalityTable.jointLives-method}
\alias{baseTable,mortalityTable.period-method}
\alias{baseTable,mortalityTable.jointLives-method}
\title{Return the base table of the life table}
\usage{
baseTable(object, ...)
......@@ -32,9 +32,9 @@ Return the base table of the life table
\item \code{mortalityTable.jointLives}: Return the base table of the joint lives mortality table (returns the base table of the first table used for joint lives)
}}
\examples{
mortalityTables.load("Austria_Annuities")
baseTable(AVOe2005R.male)
}
......@@ -4,8 +4,8 @@
\name{baseYear}
\alias{baseYear}
\alias{baseYear,mortalityTable-method}
\alias{baseYear,mortalityTable.jointLives-method}
\alias{baseYear,mortalityTable.mixed-method}
\alias{baseYear,mortalityTable.jointLives-method}
\title{Return the base year of the life table}
\usage{
baseYear(object, ...)
......@@ -32,9 +32,9 @@ Return the base year of the life table
\item \code{mortalityTable.jointLives}: Return the base year of the life table
}}
\examples{
mortalityTables.load("Austria_Annuities")
baseYear(AVOe2005R.male)
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/deathProbabilities.R, R/mortalityTable.jointLives.R
% Please edit documentation in R/deathProbabilities.R,
% R/mortalityTable.jointLives.R
\docType{methods}
\name{deathProbabilities}
\alias{deathProbabilities}
\alias{deathProbabilities,mortalityTable.period-method}
\alias{deathProbabilities,mortalityTable.ageShift-method}
\alias{deathProbabilities,mortalityTable.trendProjection-method}
\alias{deathProbabilities,mortalityTable.improvementFactors-method}
\alias{deathProbabilities,mortalityTable.jointLives-method}
\alias{deathProbabilities,mortalityTable.mixed-method}
\alias{deathProbabilities,mortalityTable.period-method}
\alias{deathProbabilities,mortalityTable.trendProjection-method}
\alias{deathProbabilities,mortalityTable.jointLives-method}
\title{Return the (cohort) death probabilities of the life table given the birth year (if needed)}
\usage{
deathProbabilities(object, ..., YOB = 1975)
......
......@@ -20,4 +20,3 @@ class.
\examples{
generateAgeShift(1, YOBs = c(1922, 1944, 1958, 1973, 1989, 2006, 2023, 2041, 2056))
}
......@@ -3,11 +3,11 @@
\docType{methods}
\name{getOmega}
\alias{getOmega}
\alias{getOmega,mortalityTable.joined-method}
\alias{getOmega,mortalityTable.jointLives-method}
\alias{getOmega,mortalityTable.period-method}
\alias{getOmega,mortalityTable.mixed-method}
\alias{getOmega,mortalityTable.joined-method}
\alias{getOmega,mortalityTable.observed-method}
\alias{getOmega,mortalityTable.period-method}
\alias{getOmega,mortalityTable.jointLives-method}
\title{Return the maximum age of the life table}
\usage{
getOmega(object)
......
......@@ -24,4 +24,3 @@ It is not required to call this function manually, \code{plotMortalityTables}
will automatically do it if object derived from class \code{mortalityTable}
are passed.
}
......@@ -37,4 +37,3 @@ mortalityComparisonTable(
}
......@@ -2,8 +2,8 @@
% Please edit documentation in R/mortalityTable.R
\docType{class}
\name{mortalityTable-class}
\alias{mortalityTable}
\alias{mortalityTable-class}
\alias{mortalityTable}
\title{Class mortalityTable}
\description{
Class \code{mortalityTable} is the (virtual) base class for all mortality
......
......@@ -2,8 +2,8 @@
% Please edit documentation in R/mortalityTable.ageShift.R
\docType{class}
\name{mortalityTable.ageShift-class}
\alias{mortalityTable.ageShift}
\alias{mortalityTable.ageShift-class}
\alias{mortalityTable.ageShift}
\title{Class mortalityTable.ageShift - Cohort life tables generated by age-shift}
\description{
A cohort life table, obtained by age-shifting from a given base table (death probabilities
......
......@@ -2,8 +2,8 @@
% Please edit documentation in R/mortalityTable.improvementFactors.R
\docType{class}
\name{mortalityTable.improvementFactors-class}
\alias{mortalityTable.improvementFactors}
\alias{mortalityTable.improvementFactors-class}
\alias{mortalityTable.improvementFactors}
\title{Class mortalityTable.improvementFactors - Cohort life table with improvement
factors}
\description{
......
......@@ -2,8 +2,8 @@
% Please edit documentation in R/mortalityTable.joined.R
\docType{class}
\name{mortalityTable.joined-class}
\alias{mortalityTable.joined}
\alias{mortalityTable.joined-class}
\alias{mortalityTable.joined}
\title{Class mortalityTable.joined - Life table created by joining two life tables}
\description{
A cohort life table obtained by joining two cohort life tables, each of which
......
......@@ -2,8 +2,8 @@
% Please edit documentation in R/mortalityTable.jointLives.R
\docType{class}
\name{mortalityTable.jointLives-class}
\alias{mortalityTable.jointLives}
\alias{mortalityTable.jointLives-class}
\alias{mortalityTable.jointLives}
\title{Class mortalityTable.jointLives - Life table for multiple joint lives}
\description{
A cohort life table obtained by calculating joint death probabilities for
......
......@@ -2,8 +2,8 @@
% Please edit documentation in R/mortalityTable.mixed.R
\docType{class}
\name{mortalityTable.mixed-class}
\alias{mortalityTable.mixed}
\alias{mortalityTable.mixed-class}
\alias{mortalityTable.mixed}
\title{Class mortalityTable.mixed - Life table as a mix of two life tables}
\description{
A cohort life table obtained by mixing two life tables with the given weights
......
......@@ -2,8 +2,8 @@
% Please edit documentation in R/mortalityTable.observed.R
\docType{class}
\name{mortalityTable.observed-class}
\alias{mortalityTable.observed}
\alias{mortalityTable.observed-class}
\alias{mortalityTable.observed}
\title{Class mortalityTable.observed - Life table from actual observations}
\description{
A cohort life table described by actual observations (data frame of PODs
......
......@@ -2,8 +2,8 @@
% Please edit documentation in R/mortalityTable.period.R
\docType{class}
\name{mortalityTable.period-class}
\alias{mortalityTable.period}
\alias{mortalityTable.period-class}
\alias{mortalityTable.period}
\title{Class mortalityTable.period - Period life tables}
\description{
A period life table, giving death probabilities for each age, up to
......
......@@ -2,8 +2,8 @@
% Please edit documentation in R/mortalityTable.trendProjection.R
\docType{class}
\name{mortalityTable.trendProjection-class}
\alias{mortalityTable.trendProjection}
\alias{mortalityTable.trendProjection-class}
\alias{mortalityTable.trendProjection}
\title{Class mortalityTable.trendProjection - Cohort mortality table with age-specific trend}
\description{
A cohort mortality table, obtained by a trend projection from a given base table
......
......@@ -17,4 +17,3 @@ directory. Defaults to the "MortalityTables" package.}
List all available sets of life tables provided by the \link[MortalityTables]{MortalityTables-package} package
An existing life table can then be loaded with \link{mortalityTables.load}.
}
......@@ -19,4 +19,3 @@ directory. Defaults to the "MortalityTables" package.}
\description{
Load a named set of mortality tables provided by the \link{MortalityTables} package
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/pensionTable.R
\docType{class}
\name{pensionTable-class}
\alias{pensionTable-class}
\alias{pensionTable}
\title{Class pensionTable}
\description{
Class \code{pensionTable} is the (virtual) base class for all pensions
tables. It contains the name and some general values applying to all
types of tables. In particular, it holds individual tables for each of the
transition probabilities. Possible states are:
* active: healty, no pension, typically paying some kin of premium
* incapacity: disablity pension, in most cases permanent, not working, early pension
* retirement: old age pension, usually starting with a fixed age
* dead
* Widow/widower pension
}
\details{
Correspondingly, the following transition probabilities can be given:
* qxaa: death probability of actives (active -> dead)
* ix: invalidity probability (active -> incapacity)
* qxi: death probability of invaid (invalid -> dead)
* rx: reactivation probability (incapacity -> active)
* apx: retirement probability (active -> retirement), typically 1 for a fixed age
* apx: retirement probability of invalids (invalid -> retirement), typically 0 or 1 for a fixed age
* qxApm: death probability of retired (retired -> dead)
* hx: probability of a widow at moment of death (dead -> widow), y(x) age differene
* qxw: death probability of widows/widowers
}
\section{Slots}{
\describe{
\item{\code{qx}}{Death probability table of actives (derived from mortalityTable)}
\item{\code{ix}}{Invalidity probability of actives (derived from mortalityTable)}
\item{\code{qxi}}{Death probability table of invalids (derived from mortalityTable)}
\item{\code{rx}}{Reactivation probability of invalids (derived from mortalityTable)}
\item{\code{apx}}{Retirement probability of actives (derived from mortalityTable)}
\item{\code{apxi}}{Retirement probability of invalids (derived from mortalityTable)}
\item{\code{qxApm}}{Death probability of old age pensioners (derived from mortalityTable)}
\item{\code{hx}}{Probability of a widow at the moment of death (derived from mortalityTable)}
\item{\code{qxw}}{Death probability of widow(er)s (derived from mortality Table)}
\item{\code{xy}}{Age difference of the widow to the deceased}
}}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/periodDeathProbabilities.R, R/mortalityTable.jointLives.R
% Please edit documentation in R/periodDeathProbabilities.R,
% R/mortalityTable.jointLives.R
\docType{methods}
\name{periodDeathProbabilities}
\alias{periodDeathProbabilities}
\alias{periodDeathProbabilities,mortalityTable.period-method}
\alias{periodDeathProbabilities,mortalityTable.ageShift-method}
\alias{periodDeathProbabilities,mortalityTable.trendProjection-method}
\alias{periodDeathProbabilities,mortalityTable.improvementFactors-method}
\alias{periodDeathProbabilities,mortalityTable.jointLives-method}
\alias{periodDeathProbabilities,mortalityTable.mixed-method}
\alias{periodDeathProbabilities,mortalityTable.period-method}
\alias{periodDeathProbabilities,mortalityTable.trendProjection-method}
\alias{periodDeathProbabilities,mortalityTable.jointLives-method}
\title{Return the (period) death probabilities of the life table for a given
observation year}
\usage{
......
......@@ -65,4 +65,3 @@ plot(mort.AT.census.1869.male, mort.AT.census.1869.female,
\seealso{
\code{\link{plotMortalityTables}} and \code{\link{plotMortalityTableComparisons}}
}
......@@ -32,4 +32,3 @@ plotMortalityTableComparisons(data, ..., xlim = NULL, ylim = NULL,
\description{
\code{plotMortalityTableComparisons} prints multiple life tables (objects of child classes of \code{mortalityTable}) in one plot and scales each by the given reference table, so that the relative mortality can be easily seen. A legend is added showing the names of the tables.
}
......@@ -30,4 +30,3 @@ plotMortalityTables(data, ..., xlim = NULL, ylim = NULL, xlab = NULL,
\description{
\code{plotMortalityTables} prints multiple life tables (objects of child classes of \code{mortalityTable}) in one log-linear plot, with a legend showing the names of the tables.
}
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