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

Joint life tables (on first death) for now have a maximum age taken from the...

Joint life tables (on first death) for now have a maximum age taken from the first insured person (i.e. the first table).

The reason is a purely technical one: The ages of the insured are not part of the table, so the getOmega function does not know any ages. Only the deathProbabilities function gets the actual ages.

This makes it impossible to create tables, where e.g. the last value is repeated as needed. Instead, we will always cut off the table at the maximum age of the table for the first insured person.
parent f7a48c8c
No related branches found
No related tags found
No related merge requests found
...@@ -45,11 +45,19 @@ deathProbabilitiesIndividual = function(tables, YOB, ageDifferences) { ...@@ -45,11 +45,19 @@ deathProbabilitiesIndividual = function(tables, YOB, ageDifferences) {
# Find the required length to have all (shifted) death probabilities fit # Find the required length to have all (shifted) death probabilities fit
# last value will be repeated for shorter tables # last value will be repeated for shorter tables
qxlen = max(mapply( # FIXME: For now, wee cannot make the table longer than the first table, because
function(table, yob, difference) { # ages(...) will always just return a list of ages allowed for the first table.
getOmega(table) - difference # The reason is that the deathProbabilities function gets a list of ageDifferences
}, # influencing the possible length of the death probabilities, while the ages
tables, YOB, ageDifferences)) + 1; # function has only the mortalityTable.2Lives object without any further information,
# i.e. the age differences are not part of the mortality table definition,
# but ages(...) has only access to that definition and nothing else.
# qxlen = max(mapply(
# function(table, yob, difference) {
# getOmega(table) - difference
# },
# tables, YOB, ageDifferences)) + 1;
qxlen = getOmega(tables[[1]]) + 1;
qxMatrix = mapply( qxMatrix = mapply(
function(table, yob, difference) { function(table, yob, difference) {
qx = deathProbabilities(table, yob); qx = deathProbabilities(table, yob);
...@@ -77,11 +85,19 @@ periodDeathProbabilitiesIndividual = function(tables, period, ageDifferences) { ...@@ -77,11 +85,19 @@ periodDeathProbabilitiesIndividual = function(tables, period, ageDifferences) {
# Find the required length to have all (shifted) death probabilities fit # Find the required length to have all (shifted) death probabilities fit
# last value will be repeated for shorter tables # last value will be repeated for shorter tables
qxlen = max(mapply( # FIXME: For now, wee cannot make the table longer than the first table, because
function(table, difference) { # ages(...) will always just return a list of ages allowed for the first table.
getOmega(table) - difference # The reason is that the deathProbabilities function gets a list of ageDifferences
}, # influencing the possible length of the death probabilities, while the ages
tables, ageDifferences)) + 1; # function has only the mortalityTable.2Lives object without any further information,
# i.e. the age differences are not part of the mortality table definition,
# but ages(...) has only access to that definition and nothing else.
# qxlen = max(mapply(
# function(table, yob, difference) {
# getOmega(table) - difference
# },
# tables, YOB, ageDifferences)) + 1;
qxlen = getOmega(tables[[1]]) + 1;
qxMatrix = mapply( qxMatrix = mapply(
function(table, difference) { function(table, difference) {
qx = periodDeathProbabilities(table, Period = period); qx = periodDeathProbabilities(table, Period = period);
...@@ -104,19 +120,19 @@ periodDeathProbabilitiesIndividual = function(tables, period, ageDifferences) { ...@@ -104,19 +120,19 @@ periodDeathProbabilitiesIndividual = function(tables, period, ageDifferences) {
#' @describeIn ages Return the defined ages of the joint lives mortality table (returns the ages of the first table used for joint lives) #' @describeIn ages Return the defined ages of the joint lives mortality table (returns the ages of the first table used for joint lives)
setMethod("ages", "mortalityTable.jointLives", setMethod("ages", "mortalityTable.jointLives",
function(object, ...) { function(object, ...) {
ages(c(object@table)[1], ...); ages(c(object@table)[[1]], ...);
}) })
#' @describeIn baseTable Return the base table of the joint lives mortality table (returns the base table of the first table used for joint lives) #' @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("baseTable", "mortalityTable.jointLives", setMethod("baseTable", "mortalityTable.jointLives",
function(object, ...) { function(object, ...) {
baseTable(c(object@table)[1], ...) baseTable(c(object@table)[[1]], ...)
}) })
#' @describeIn baseYear Return the base year of the life table #' @describeIn baseYear Return the base year of the life table
setMethod("baseYear", "mortalityTable.jointLives", setMethod("baseYear", "mortalityTable.jointLives",
function(object, ...) { function(object, ...) {
baseYear(c(object@table)[1], ...) baseYear(c(object@table)[[1]], ...)
}) })
#' @describeIn deathProbabilities Return the (cohort) death probabilities of the #' @describeIn deathProbabilities Return the (cohort) death probabilities of the
...@@ -131,9 +147,9 @@ setMethod("deathProbabilities", "mortalityTable.jointLives", ...@@ -131,9 +147,9 @@ setMethod("deathProbabilities", "mortalityTable.jointLives",
}) })
#' @describeIn getOmega Return the maximum age of the joint lives mortality table (returns the maximum age of the first table used for joint lives, as the ages of the joint lives are now known to the function) #' @describeIn getOmega Return the maximum age of the joint lives mortality table (returns the maximum age of the first table used for joint lives, as the ages of the joint lives are now known to the function)
setMethod("getOmega", "mortalityTable.observed", setMethod("getOmega", "mortalityTable.jointLives",
function(object) { function(object) {
max(object@ages, na.rm = TRUE); getOmega(c(object@table)[[1]])
}) })
...@@ -145,6 +161,9 @@ setMethod("periodDeathProbabilities", "mortalityTable.jointLives", ...@@ -145,6 +161,9 @@ setMethod("periodDeathProbabilities", "mortalityTable.jointLives",
# First death probabilities are characterized as p_x1x2x3.. = \prod p_xi, i.e. # First death probabilities are characterized as p_x1x2x3.. = \prod p_xi, i.e.
# q_x1x2x3... = 1 - \prod (1 - p_xi) # q_x1x2x3... = 1 - \prod (1 - p_xi)
qx = 1 - apply(1 - qxMatrix, 1, prod) qx = 1 - apply(1 - qxMatrix, 1, prod)
# Cut to same length as ages:
ages = ages(object);
qx = qx[1:length(ages)];
object@modification(qx * (1 + object@loading)); object@modification(qx * (1 + object@loading));
}) })
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
\name{getOmega} \name{getOmega}
\alias{getOmega} \alias{getOmega}
\alias{getOmega,mortalityTable.joined-method} \alias{getOmega,mortalityTable.joined-method}
\alias{getOmega,mortalityTable.jointLives-method}
\alias{getOmega,mortalityTable.mixed-method} \alias{getOmega,mortalityTable.mixed-method}
\alias{getOmega,mortalityTable.observed-method} \alias{getOmega,mortalityTable.observed-method}
\alias{getOmega,mortalityTable.period-method} \alias{getOmega,mortalityTable.period-method}
...@@ -19,7 +20,7 @@ getOmega(object) ...@@ -19,7 +20,7 @@ getOmega(object)
\S4method{getOmega}{mortalityTable.observed}(object) \S4method{getOmega}{mortalityTable.observed}(object)
\S4method{getOmega}{mortalityTable.observed}(object) \S4method{getOmega}{mortalityTable.jointLives}(object)
} }
\arguments{ \arguments{
\item{object}{A life table object (instance of a \code{mortalityTable} class)} \item{object}{A life table object (instance of a \code{mortalityTable} class)}
...@@ -37,6 +38,6 @@ Return the maximum age of the life table ...@@ -37,6 +38,6 @@ Return the maximum age of the life table
\item \code{mortalityTable.observed}: Return the maximum age of the joined life table \item \code{mortalityTable.observed}: Return the maximum age of the joined life table
\item \code{mortalityTable.observed}: Return the maximum age of the joint lives mortality table (returns the maximum age of the first table used for joint lives, as the ages of the joint lives are now known to the function) \item \code{mortalityTable.jointLives}: Return the maximum age of the joint lives mortality table (returns the maximum age of the first table used for joint lives, as the ages of the joint lives are now known to the function)
}} }}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment