From 75f23c1df0c0efe4630f23b90c65b1429dbd7f38 Mon Sep 17 00:00:00 2001 From: Reinhold Kainhofer <reinhold@kainhofer.com> Date: Fri, 26 Aug 2016 23:44:37 +0200 Subject: [PATCH] Split code over multiple files (one per class/function), fix documentation --- .Rbuildignore | 2 + DESCRIPTION | 26 +- NAMESPACE | 32 +- R/ValuationTables.R | 501 ------------------ R/ageShift.R | 32 ++ R/ages.R | 35 ++ R/baseTable.R | 22 + R/baseYear.R | 22 + R/deathProbabilities.R | 74 +++ R/getCohortTable.R | 23 + R/getOmega.R | 33 ++ R/getPeriodTable.R | 27 + R/lifeTable.R | 22 + R/makeQxDataFrame.R | 76 +++ R/periodDeathProbabilities.R | 69 +++ R/plotValuationTableComparisons.R | 71 +++ R/plotValuationTables.R | 135 +---- R/setLoading.R | 17 + R/undampenTrend.R | 17 + R/valuationTable.R | 40 ++ R/valuationTable.ageShift.R | 22 + R/valuationTable.improvementFactors.R | 27 + R/valuationTable.joined.R | 26 + R/valuationTable.mixed.R | 31 ++ R/valuationTable.observed.R | 28 + R/valuationTable.period.R | 25 + R/valuationTable.trendProjection.R | 42 ++ Read-and-delete-me | 8 - ValuationTables.Rproj | 2 +- man/ValuationTables-package.Rd | 2 +- man/ageShift.Rd | 28 + man/ages.Rd | 40 ++ man/baseTable.Rd | 30 ++ man/baseYear.Rd | 30 ++ man/deathProbabilities.Rd | 55 ++ man/getCohortTable.Rd | 28 + man/getOmega.Rd | 38 ++ man/getPeriodTable.Rd | 29 + man/lifeTable.Rd | 27 + man/makeQxDataFrame.Rd | 27 + man/periodDeathProbabilities.Rd | 59 +++ man/plotValuationTableComparisons.Rd | 35 ++ man/plotValuationTables.Rd | 11 +- man/setLoading.Rd | 25 + man/undampenTrend.Rd | 24 + man/valuationTable-class.Rd | 83 +-- man/valuationTable.ageShift-class.Rd | 16 + ...valuationTable.improvementFactors-class.Rd | 21 + man/valuationTable.joined-class.Rd | 24 + man/valuationTable.mixed-class.Rd | 24 + man/valuationTable.observed-class.Rd | 21 + man/valuationTable.period-class.Rd | 19 + man/valuationTable.trendProjection-class.Rd | 34 ++ man/valuationTable_ageShift-class.Rd | 47 -- ...valuationTable_improvementFactors-class.Rd | 38 -- man/valuationTable_joined-class.Rd | 37 -- man/valuationTable_mixed-class.Rd | 56 -- man/valuationTable_observed-class.Rd | 18 - man/valuationTable_period-class.Rd | 51 -- 59 files changed, 1484 insertions(+), 980 deletions(-) delete mode 100644 R/ValuationTables.R create mode 100644 R/ageShift.R create mode 100644 R/ages.R create mode 100644 R/baseTable.R create mode 100644 R/baseYear.R create mode 100644 R/deathProbabilities.R create mode 100644 R/getCohortTable.R create mode 100644 R/getOmega.R create mode 100644 R/getPeriodTable.R create mode 100644 R/lifeTable.R create mode 100644 R/makeQxDataFrame.R create mode 100644 R/periodDeathProbabilities.R create mode 100644 R/plotValuationTableComparisons.R create mode 100644 R/setLoading.R create mode 100644 R/undampenTrend.R create mode 100644 R/valuationTable.R create mode 100644 R/valuationTable.ageShift.R create mode 100644 R/valuationTable.improvementFactors.R create mode 100644 R/valuationTable.joined.R create mode 100644 R/valuationTable.mixed.R create mode 100644 R/valuationTable.observed.R create mode 100644 R/valuationTable.period.R create mode 100644 R/valuationTable.trendProjection.R delete mode 100644 Read-and-delete-me create mode 100644 man/ageShift.Rd create mode 100644 man/ages.Rd create mode 100644 man/baseTable.Rd create mode 100644 man/baseYear.Rd create mode 100644 man/deathProbabilities.Rd create mode 100644 man/getCohortTable.Rd create mode 100644 man/getOmega.Rd create mode 100644 man/getPeriodTable.Rd create mode 100644 man/lifeTable.Rd create mode 100644 man/makeQxDataFrame.Rd create mode 100644 man/periodDeathProbabilities.Rd create mode 100644 man/plotValuationTableComparisons.Rd create mode 100644 man/setLoading.Rd create mode 100644 man/undampenTrend.Rd create mode 100644 man/valuationTable.ageShift-class.Rd create mode 100644 man/valuationTable.improvementFactors-class.Rd create mode 100644 man/valuationTable.joined-class.Rd create mode 100644 man/valuationTable.mixed-class.Rd create mode 100644 man/valuationTable.observed-class.Rd create mode 100644 man/valuationTable.period-class.Rd create mode 100644 man/valuationTable.trendProjection-class.Rd delete mode 100644 man/valuationTable_ageShift-class.Rd delete mode 100644 man/valuationTable_improvementFactors-class.Rd delete mode 100644 man/valuationTable_joined-class.Rd delete mode 100644 man/valuationTable_mixed-class.Rd delete mode 100644 man/valuationTable_observed-class.Rd delete mode 100644 man/valuationTable_period-class.Rd diff --git a/.Rbuildignore b/.Rbuildignore index 91114bf..eae2540 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -1,2 +1,4 @@ ^.*\.Rproj$ ^\.Rproj\.user$ +ValuationTables.RData +data.saved diff --git a/DESCRIPTION b/DESCRIPTION index db17621..f9e94ff 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -9,7 +9,6 @@ Maintainer: Reinhold Kainhofer <reinhold@kainhofer.com> Depends: ggplot2, methods, - openxlsx, scales, utils Suggests: @@ -21,3 +20,28 @@ Description: This package provides classes to implement cohort life tables merged life tables. License: GPL (>= 2) RoxygenNote: 5.0.1 +Collate: + 'ValuationTables.R' + 'valuationTable.R' + 'valuationTable.period.R' + 'valuationTable.ageShift.R' + 'ageShift.R' + 'valuationTable.observed.R' + 'valuationTable.joined.R' + 'valuationTable.mixed.R' + 'ages.R' + 'baseTable.R' + 'baseYear.R' + 'valuationTable.improvementFactors.R' + 'valuationTable.trendProjection.R' + 'deathProbabilities.R' + 'getCohortTable.R' + 'getOmega.R' + 'getPeriodTable.R' + 'lifeTable.R' + 'makeQxDataFrame.R' + 'periodDeathProbabilities.R' + 'plotValuationTableComparisons.R' + 'plotValuationTables.R' + 'setLoading.R' + 'undampenTrend.R' diff --git a/NAMESPACE b/NAMESPACE index f665307..8481cfa 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,23 +1,24 @@ # Generated by roxygen2: do not edit by hand export(makeQxDataFrame) +export(plotValuationTableComparisons) export(plotValuationTables) export(valuationTable) -export(valuationTable_ageShift) -export(valuationTable_improvementFactors) -export(valuationTable_joined) -export(valuationTable_mixed) -export(valuationTable_observed) -export(valuationTable_period) -export(valuationTable_trendProjection) +export(valuationTable.ageShift) +export(valuationTable.improvementFactors) +export(valuationTable.joined) +export(valuationTable.mixed) +export(valuationTable.observed) +export(valuationTable.period) +export(valuationTable.trendProjection) exportClasses(valuationTable) -exportClasses(valuationTable_ageShift) -exportClasses(valuationTable_improvementFactors) -exportClasses(valuationTable_joined) -exportClasses(valuationTable_mixed) -exportClasses(valuationTable_observed) -exportClasses(valuationTable_period) -exportClasses(valuationTable_trendProjection) +exportClasses(valuationTable.ageShift) +exportClasses(valuationTable.improvementFactors) +exportClasses(valuationTable.joined) +exportClasses(valuationTable.mixed) +exportClasses(valuationTable.observed) +exportClasses(valuationTable.period) +exportClasses(valuationTable.trendProjection) exportMethods(ageShift) exportMethods(ages) exportMethods(baseTable) @@ -28,7 +29,8 @@ exportMethods(getOmega) exportMethods(getPeriodTable) exportMethods(lifeTable) exportMethods(periodDeathProbabilities) +exportMethods(setLoading) exportMethods(undampenTrend) import(ggplot2) import(methods) -import(openxlsx) +import(scales) diff --git a/R/ValuationTables.R b/R/ValuationTables.R deleted file mode 100644 index cd00b9e..0000000 --- a/R/ValuationTables.R +++ /dev/null @@ -1,501 +0,0 @@ -#' Provide life table classes for life insurance purposes -#' -#' @import openxlsx -#' @import methods -#' @import ggplot2 -#' -"_PACKAGE" - - -#' Class valuationTable -#' -#' Class \code{valuationTable} is the (virtual) base class for all valuation -#' tables. It contains the name and some general values applying to all -#' types of tables, but does not contain any data itself. Use a child class -#' to create actual valuation tables. -#' -#' @slot name The human-readable name of the valuation table -#' @slot baseYear The base year of the valuation table (e.g. for tables with trend projection) -#' @slot modification A function that will be called with the final death probabilities -#' to give the user a way to modify the final probabilities -#' @slot loading Additional security loading on the resulting table (single numeric -#' value, e.g. 0.05 adds 5% security margin to the probabilities) -#' -#' @export valuationTable -#' @exportClass valuationTable -valuationTable=setClass( - "valuationTable", - slots=list(name="character", baseYear="numeric", loading="numeric", modification="function"), - prototype=list(name="Actuarial Valuation Table", baseYear=2000, loading=0, modification=identity), - contains="VIRTUAL" -); - -#' Class valuationTable_period - Period life tables -#' -#' A period life table, giving death probabilities for each age, up to -#' maximum age omega. Optionally apply selection factors to the probabilities -#' -#' @slot ages The ages corresponding to the entries of the deathProbs -#' @slot deathProbs The one-year death probabilities for the ages -#' -#' @export valuationTable_period -#' @exportClass valuationTable_period -valuationTable_period=setClass( - "valuationTable_period", - slots=list(ages="numeric", deathProbs="numeric"), - prototype=list(ages=eval(0:120), deathProbs=rep(1,120)), - contains="valuationTable" -); - - -#' Class valuationTable_ageShift - Cohort life tables generated by age-shift -#' -#' A cohort life table, obtained by age-shifting from a given base table (death probabilities -# for a base birth year) -#' -#' @slot ageShifts A \code{data.frame} with columns \code{YOB} and \code{shifts} giving the age shifts for each birth year -#' -#' @export valuationTable_ageShift -#' @exportClass valuationTable_ageShift -valuationTable_ageShift=setClass( - "valuationTable_ageShift", - slots=list(ageShifts="data.frame"), - prototype=list(ageShifts=data.frame(YOB=c(), shifts=c())), - contains="valuationTable_period" -); - -#' Class valuationTable_trendProjection - Cohort life table with age-specific trend -#' -#' A cohort life table, obtained by a trend projection from a given base table -#' (PODs for a given observation year). Typically, the trend is obtained by -#' the Lee-Carter method or some other trend estimation. -#' The dampingFunction can be used to modify the cumulative years (e.g. G(tau+x) instead of tau+x) -#' If trend2 is given, the G(tau+x) gives the weight of the first trend, 1-G(tau+x) the weight of the second trend -#' -#' @slot baseYear The base year of the trend projection (\code{baseTable} describes the death probabilities in this year) -#' @slot trend The yearly improvements of the log-death probabilities (per age) -#' @slot dampingFunction A possible damping of the trend. This is a function \code{damping(delta_years)} that gets a vector of years from the baseYear and should return the dampened values. -#' @slot trend2 The alternate trend. If given, the damping function interpolates between \code{trend} and \code{trend2}, otherwise the dumping function simply modifies the coefficients of \code{trend}. -#' -#' @export valuationTable_trendProjection -#' @exportClass valuationTable_trendProjection -valuationTable_trendProjection=setClass( - "valuationTable_trendProjection", - slots=list(baseYear="numeric", trend="numeric", dampingFunction="function", trend2="numeric"), - prototype=list(baseYear=1980, trend=rep(0,120), dampingFunction=identity, trend2=0), - contains="valuationTable_period" -); - -#' Class valuationTable_improvementFactors - Cohort life table with improvement factors -#' -#' A cohort life table, obtained by an improvment factor projection -#' from a given base table (PODs for a given observation year). -#' -#' @slot baseYear The base year for the improvements (\code{baseTable} describes the death probabilities in this year) -#' @slot improvement Yearly improvement factors per age -#' -#' @export valuationTable_improvementFactors -#' @exportClass valuationTable_improvementFactors -valuationTable_improvementFactors=setClass( - "valuationTable_improvementFactors", - slots=list(baseYear="numeric", improvement="numeric"), - prototype=list(baseYear=2012, improvement=rep(0,120)), - contains="valuationTable_period" -); - -#' Class valuationTable_observed - Life table from actual observations -#' -#' A cohort life table described by actual observations (data frame of PODs -#' per year and age) -#' -#' @slot data The observations -#' @slot years The observation years -#' @slot ages The observation ages -#' -#' @export valuationTable_observed -#' @exportClass valuationTable_observed -valuationTable_observed=setClass( - "valuationTable_observed", - slots=list(data="data.frame", years="numeric", ages="numeric"), - prototype=list(data=data.frame(), years=c(), ages=c()), - contains="valuationTable" -); - - -#' Class valuationTable_joined - Life table created by joining two lift tables -#' -#' A cohort life table obtained by joining two cohort life tables, each of which -#' applies only to certain observation years (e.g. for the past use the observed -#' PODs, and project them to the future with the trend projection) -#' -#' @slot table1 The first \code{valuationTable}, valid for years given in \code{yearRange1} -#' @slot yearRange1 The years, for which \code{table1} describes the death probabilities -#' @slot table2 The second \code{valuationTable}, valid for years given in \code{yearRange2} -#' @slot yearRange2 The years, for which \code{table2} describes the death probabilities -#' -#' @export valuationTable_joined -#' @exportClass valuationTable_joined -valuationTable_joined=setClass( - "valuationTable_joined", - slots=list( - table1="valuationTable", yearRange1="numeric", - table2="valuationTable", yearRange2="numeric"), - contains="valuationTable" -); - -#' Class valuationTable_mixed - Life table as a mix of two life tables -#' -#' A cohort life table obtained by mixing two life tables with the given weights -#' -#' @slot table1 The first \code{valuationTable} -#' @slot table2 The second \code{valuationTable} -#' @slot weight1 The weight of the first valuation table -#' @slot weight2 The weight of the second valuation table -#' @slot loading Additional security loading -#' -#' @export valuationTable_mixed -#' @exportClass valuationTable_mixed -valuationTable_mixed=setClass( - "valuationTable_mixed", - slots=c(table1="valuationTable", table2="valuationTable", weight1="numeric", weight2="numeric", loading="numeric"), - prototype=list(weight1=1/2, weight2=1/2, loading=0), - contains="valuationTable" -); - - - -#' Return the maximum age of the life table -#' @exportMethod getOmega -setGeneric("getOmega", function(object) standardGeneric("getOmega")); -#' @describeIn valuationTable_period Return the maximum age of the period life table -setMethod("getOmega", "valuationTable_period", - function (object) { - max(object@ages,na.rm=TRUE); - }) -#' @describeIn valuationTable_mixed Return the maximum age of the mixed life table -setMethod("getOmega", "valuationTable_mixed", - function (object) { - getOmega(object@table1); - }) -#' @describeIn valuationTable_joined Return the maximum age of the joined life table -setMethod("getOmega", "valuationTable_joined", - function (object) { - getOmega(object@table1); - }) -#' @describeIn valuationTable_observed Return the maximum age of the joined life table -setMethod("getOmega", "valuationTable_observed", - function (object) { - max(object@ages,na.rm=TRUE); - }) - - -#' Return the defined ages of the life table -#' @param object A life table object (instance of a \code{valuationTable} class) -#' @param ... Currently unused -#' @exportMethod ages -setGeneric("ages", function(object, ...) standardGeneric("ages")); -#' @describeIn valuationTable_period Return the defined ages of the life table -setMethod("ages", "valuationTable_period", - function (object, ...) { - object@ages; - }) -#' @describeIn valuationTable_mixed Return the defined ages of the life table -setMethod("ages", "valuationTable_mixed", - function (object, ...) { - ages(object@table1); - }) -#' @describeIn valuationTable_joined Return the defined ages of the life table -setMethod("ages", "valuationTable_joined", - function (object, ...) { - ages(object@table1); - }) -#' @describeIn valuationTable_observed Return the defined ages of the life table -setMethod("ages", "valuationTable_observed", - function (object, ...) { - object@ages; - }) - - - -#' Return the age shift of the age-shifted life table given the birth year -#' -#' @param object The life table object (class inherited from valuationTable) -#' @param ... Other parameters (currently unused) -#' @param YOB The birth year for which the age shift should be determined. -#' @exportMethod ageShift -setGeneric("ageShift", function(object, YOB=1975, ...) standardGeneric("ageShift")); -#' @describeIn valuationTable_ageShift Return the age shift of the age-shifted life table given the birth year -#' -#' @param YOB The birth year for which the age shift should be determined1. -setMethod("ageShift","valuationTable_ageShift", - function(object, YOB, ...) { - shift = object@ageShifts[toString(YOB),]; - if (is.na(shift)) { - # The row names (YOB) are unfortunately strings, so we cannot easily query them. - # TODO: Change the data.frame to use a real column for the YOB - firstYOB = utils::head(rownames(object@ageShifts), n=1); - lastYOB = utils::tail(rownames(object@ageShifts), n=1); - if (YOB < as.integer(firstYOB)) { - shift = object@ageShifts[firstYOB,]; - } else if (YOB > as.integer(lastYOB)) { - shift = object@ageShifts[lastYOB,]; - } - } - shift - }) - - - -#' Return the (cohort) death probabilities of the life table given the birth year (if needed) -#' -#' @param object The life table object (class inherited from valuationTable) -#' @param ... Other parameters (currently unused) -#' @param YOB The birth year for which the death probabilities should be calculated -#' @exportMethod deathProbabilities -setGeneric("deathProbabilities", function(object, ..., YOB=1975) standardGeneric("deathProbabilities")); -#' @describeIn valuationTable_period Return the (cohort) death probabilities of the life table given the birth year (if needed) -#' @param YOB The birth year for which the death probabilities should be calculated -setMethod("deathProbabilities", "valuationTable_period", - function(object, ..., YOB=1975) { - object@modification(object@deathProbs * (1+object@loading)); - }) -#' @describeIn valuationTable_ageShift Return the (cohort) death probabilities of the life table given the birth year (if needed) -#' -#' @param YOB The birth year for which the death probabilities should be calculated -setMethod("deathProbabilities","valuationTable_ageShift", - function (object, ..., YOB=1975) { - qx=object@deathProbs * (1+object@loading); - shift = ageShift(object, YOB); - if (shift>0) { - qx = c(qx[(shift+1):length(qx)], rep(qx[length(qx)], shift)); - } else if (shift<0) { - qx = c(rep(0, -shift), qx[1:(length(qx)-(-shift))]) - } - object@modification(qx) - }) - -#' @describeIn valuationTable_trendProjection Return the (cohort) death probabilities of the life table given the birth year (if needed) -#' -#' @param YOB The birth year for which the death probabilities should be calculated -setMethod("deathProbabilities","valuationTable_trendProjection", - function (object, ..., YOB=1975) { - qx=object@deathProbs * (1+object@loading); - if (is.null(object@trend2) || length(object@trend2)<=1) { - ages=0:(length(qx)-1); - damping=sapply(ages, function (age) { object@dampingFunction(YOB+age-object@baseYear) }); - # print(data.frame(age=0:(length(qx)-1), trend=object@trend, exponent=-object@trend*damping, damping=damping, baseqx=qx, qx=exp(-object@trend*damping)*qx)[66:90,]); - finalqx=exp(-object@trend*damping)*qx; - } else { - # dampingFunction interpolates between the two trends: - weights=sapply(YOB+0:(length(qx)-1), object@dampingFunction); - finalqx=qx*exp(-(object@trend*(1-weights) + object@trend2*(weights))*(YOB+0:(length(qx)-1)-object@baseYear)) - } - object@modification(finalqx) - }) - -#' @describeIn valuationTable_improvementFactors Return the (cohort) death probabilities of the life table given the birth year (if needed) -#' -#' @param YOB The birth year for which the death probabilities should be calculated -setMethod("deathProbabilities","valuationTable_improvementFactors", - function (object, ..., YOB=1975) { - qx=object@deathProbs * (1+object@loading); - finalqx=(1-object@improvement)^(YOB+0:(length(qx)-1)-object@baseYear)*qx; - object@modification(finalqx) - }) -#' @describeIn valuationTable_mixed Return the (cohort) death probabilities of the life table given the birth year (if needed) -#' -#' @param YOB The birth year for which the death probabilities should be calculated -setMethod("deathProbabilities","valuationTable_mixed", - function (object, ..., YOB=1975) { - qx1=deathProbabilities(object@table1, ..., YOB) * (1+object@loading); - qx2=deathProbabilities(object@table2, ..., YOB) * (1+object@loading); - mixedqx=(object@weight1*qx1 + object@weight2*qx2)/(object@weight1 + object@weight2); - object@modification(mixedqx) - }) - - - - -#' Return the (period) death probabilities of the life table for a given observation year -#' -#' @param object The life table object (class inherited from valuationTable) -#' @param ... Other parameters (currently unused) -#' @param Period The observation year for which the period death probabilities should be determined -#' @exportMethod periodDeathProbabilities -setGeneric("periodDeathProbabilities", function(object, ..., Period=1975) standardGeneric("periodDeathProbabilities")); -#' @describeIn valuationTable_period Return the (period) death probabilities of the life table for a given observation year -#' @param Period The observation year for which the period death probabilities should be determined -setMethod("periodDeathProbabilities", "valuationTable_period", - function(object, ..., Period=1975) { - object@modification(object@deathProbs * (1+object@loading)); - }) -#' @describeIn valuationTable_ageShift Return the (period) death probabilities of the life table for a given observation year -#' -#' @param Period The observation year for which the period death probabilities should be determined -setMethod("periodDeathProbabilities","valuationTable_ageShift", - function (object, ..., Period=1975) { - # TODO - qx=object@deathProbs * (1+object@loading); - # TODO!!! - # shift.index=match(YOB, object@shifts, 0); - # if (shift.index) {} - object@modification(qx) - }) -#' @describeIn valuationTable_trendProjection Return the (period) death probabilities of the life table for a given observation year -#' -#' @param Period The observation year for which the period death probabilities should be determined -setMethod("periodDeathProbabilities","valuationTable_trendProjection", - function (object, ..., Period=1975) { - qx=object@deathProbs * (1+object@loading); - if (is.null(object@trend2) || length(object@trend2)<=1) { - # ages=0:(length(qx)-1); - damping=object@dampingFunction(Period-object@baseYear); - # print(data.frame(age=0:(length(qx)-1), trend=object@trend, exponent=-object@trend*damping, damping=damping, baseqx=qx, qx=exp(-object@trend*damping)*qx)[66:90,]); - finalqx=exp(-object@trend*damping)*qx; - } else { - # TODO!!! - # dampingFunction interpolates between the two trends: - # weights=sapply(YOB+0:(length(qx)-1), object@dampingFunction); - # finalqx=qx*exp(-(object@trend*(1-weights) + object@trend2*(weights))*(YOB+0:(length(qx)-1)-object@baseYear)); - } - object@modification(finalqx) - }) -#' @describeIn valuationTable_improvementFactors Return the (period) death probabilities of the life table for a given observation year -#' -#' @param Period The observation year for which the period death probabilities should be determined -setMethod("periodDeathProbabilities","valuationTable_improvementFactors", - function (object, ..., Period=1975) { - qx=object@deathProbs * (1+object@loading); - finalqx=(1-object@improvement)^(Period-object@baseYear)*qx; - object@modification(finalqx) - }) -#' @describeIn valuationTable_mixed Return the (period) death probabilities of the life table for a given observation year -#' -#' @param Period The observation year for which the period death probabilities should be determined -setMethod("periodDeathProbabilities","valuationTable_mixed", - function (object, ..., Period=1975) { - qx1=periodDeathProbabilities(object@table1, ..., Period=Period) * (1+object@loading); - qx2=periodDeathProbabilities(object@table2, ..., Period=Period) * (1+object@loading); - mixedqx=(object@weight1*qx1 + object@weight2*qx2)/(object@weight1 + object@weight2); - object@modification(mixedqx) - }) - - - - -#' Return the lifetable object (package lifecontingencies) for the cohort life table -#' @param object The life table object (class inherited from valuationTable) -#' @param ... Parameters to be handed to the \code{deathProbabilities} method of the life table -#' @exportMethod lifeTable -setGeneric("lifeTable", function(object, ...) standardGeneric("lifeTable")); -#' @describeIn valuationTable Return the lifetable object (package lifecontingencies) for the cohort life table -#' -#' @param ... Parameters to be handed to the \code{deathProbabilities} method of the life table -setMethod("lifeTable","valuationTable", - function (object, ...) { - qx=deathProbabilities(object, ...); - if (qx[[length(qx)]]!=1) { qx=c(qx, 1, 1); } - lifecontingencies::probs2lifetable(qx, type="qx") - }) - - - - -#' Return the base year of the life table -#' @param object The life table object (class inherited from valuationTable) -#' @param ... Other parameters (currently unused) -#' @exportMethod baseYear -setGeneric("baseYear", function(object, ...) standardGeneric("baseYear")); -#' @describeIn valuationTable Return the base year of the life table -#' @param object The life table object (class inherited from valuationTable) -#' @param ... Other parameters (currently unused) -setMethod("baseYear","valuationTable", - function (object, ...) { - object@baseYear - }) -#' @describeIn valuationTable_mixed Return the base year of the life table -setMethod("baseYear","valuationTable_mixed", - function (object, ...) { - baseYear(object@table1) - }) - - - -#' Return the base table of the life table -#' @param object The life table object (class inherited from valuationTable) -#' @param ... Other parameters (currently unused) -#' @exportMethod baseTable -setGeneric("baseTable", function(object, ...) standardGeneric("baseTable")); -#' @describeIn valuationTable Return the base table of the life table -setMethod("baseTable","valuationTable", - function (object, ...) { - c() - }) -#' @describeIn valuationTable_period Return the base table of the life table -setMethod("baseTable","valuationTable_period", - function (object, ...) { - object@deathProbs - }) - - - - -#' Return the period life table as a \code{valuationTable_period} object -#' -#' @param object The life table object (class inherited from valuationTable) -#' @param Period The observation year, for which the death probabilities should be determined -#' @param ... Other parameters (currently unused) -#' @exportMethod getPeriodTable -setGeneric("getPeriodTable", function(object, Period, ...) standardGeneric("getPeriodTable")); -#' @describeIn valuationTable Return the period life table as a \code{valuationTable_period} object -#' -#' @param Period The observation year, for which the death probabilities should be determined -#' @param ... Currently unused -setMethod("getPeriodTable","valuationTable", - function (object, Period, ...) { - valuationTable_period( - name = paste(object@name, ", Period ", Period), - baseYear = Period, - ages = ages(object), - deathProbs = periodDeathProbabilities(object, Period=Period) - ) - }) - - - -#' Return the cohort life table as a \code{valuationTable_period} object -#' -#' @param object The life table object (class inherited from valuationTable) -#' @param YOB The birth year for which the life table should be calculated -#' @param ... Other parameters (currently unused) -#' @exportMethod getCohortTable -setGeneric("getCohortTable", function(object, YOB, ...) standardGeneric("getCohortTable")); -#' @describeIn valuationTable Return the cohort life table as a \code{valuationTable_period} object -#' -#' @param YOB The birth year for which the life table should be calculated -#' -# @export getCohortTable -setMethod("getCohortTable","valuationTable", - function (object, YOB, ...) { - valuationTable_period( - name = paste(object@name, ", YOB ", YOB), - baseYear = YOB, - ages=ages(object), - deathProbs=deathProbabilities(object, YOB=YOB) - ); - }) - - - - -#' Return a \code{valuationTable_trensProjection} object with the trend damping removed. -#' -#' @param object The life table object (class inherited from valuationTable) -#' @exportMethod undampenTrend -setGeneric("undampenTrend", function (object) standardGeneric("undampenTrend")); -#' @describeIn valuationTable_trendProjection Return a \code{valuationTable_trendProjection} object with the trend damping removed. -setMethod("undampenTrend", "valuationTable_trendProjection", - function (object) { - object@dampingFunction=identity; - object - }); diff --git a/R/ageShift.R b/R/ageShift.R new file mode 100644 index 0000000..fb93282 --- /dev/null +++ b/R/ageShift.R @@ -0,0 +1,32 @@ +#' @include valuationTable.ageShift.R +NULL + +#' Return the age shift of the age-shifted life table given the birth year +#' +#' @param object The life table object (class inherited from valuationTable) +#' @param ... Other parameters (currently unused) +#' @param YOB The birth year for which the age shift should be determined. +#' +#' @exportMethod ageShift +setGeneric("ageShift", function(object, YOB=1975, ...) standardGeneric("ageShift")); + +#' @describeIn ageShift Return the age shift of the age-shifted life table +#' given the birth year +setMethod("ageShift", + "valuationTable.ageShift", + function(object, YOB, ...) { + shift = object@ageShifts[toString(YOB),]; + if (is.na(shift)) { + # The row names (YOB) are unfortunately strings, so we cannot easily query them. + # TODO: Change the data.frame to use a real column for the YOB + firstYOB = utils::head(rownames(object@ageShifts), n = 1); + lastYOB = utils::tail(rownames(object@ageShifts), n = 1); + if (YOB < as.integer(firstYOB)) { + shift = object@ageShifts[firstYOB,]; + } else if (YOB > as.integer(lastYOB)) { + shift = object@ageShifts[lastYOB,]; + } + } + shift + }) + diff --git a/R/ages.R b/R/ages.R new file mode 100644 index 0000000..ff28f76 --- /dev/null +++ b/R/ages.R @@ -0,0 +1,35 @@ +#' @include valuationTable.period.R valuationTable.mixed.R valuationTable.joined.R valuationTable.observed.R +NULL + +#' Return the defined ages of the life table +#' +#' @param object A life table object (instance of a \code{valuationTable} class) +#' @param ... Currently unused +#' +#' @exportMethod ages +setGeneric("ages", function(object, ...) standardGeneric("ages")); + +#' @describeIn ages Return the defined ages of the life table +setMethod("ages", "valuationTable.period", + function (object, ...) { + object@ages; + }) + +#' @describeIn ages Return the defined ages of the life table +setMethod("ages", "valuationTable.mixed", + function (object, ...) { + ages(object@table1); + }) + +#' @describeIn ages Return the defined ages of the life table +setMethod("ages", "valuationTable.joined", + function (object, ...) { + ages(object@table1); + }) + +#' @describeIn ages Return the defined ages of the life table +setMethod("ages", "valuationTable.observed", + function (object, ...) { + object@ages; + }) + diff --git a/R/baseTable.R b/R/baseTable.R new file mode 100644 index 0000000..fd9a358 --- /dev/null +++ b/R/baseTable.R @@ -0,0 +1,22 @@ +#' @include valuationTable.R valuationTable.period.R +NULL + +#' Return the base table of the life table +#' +#' @param object The life table object (class inherited from valuationTable) +#' @param ... Other parameters (currently unused) +#' +#' @exportMethod baseTable +setGeneric("baseTable", function(object, ...) standardGeneric("baseTable")); + +#' @describeIn baseTable Return the base table of the life table +setMethod("baseTable", "valuationTable", + function (object, ...) { + c() + }) + +#' @describeIn baseTable Return the base table of the life table +setMethod("baseTable", "valuationTable.period", + function (object, ...) { + object@deathProbs + }) diff --git a/R/baseYear.R b/R/baseYear.R new file mode 100644 index 0000000..ccf9c70 --- /dev/null +++ b/R/baseYear.R @@ -0,0 +1,22 @@ +#' @include valuationTable.R valuationTable.mixed.R +NULL + +#' Return the base year of the life table +#' +#' @param object The life table object (class inherited from valuationTable) +#' @param ... Other parameters (currently unused) +#' +#' @exportMethod baseYear +setGeneric("baseYear", function(object, ...) standardGeneric("baseYear")); + +#' @describeIn baseYear Return the base year of the life table +setMethod("baseYear", "valuationTable", + function (object, ...) { + object@baseYear + }) + +#' @describeIn baseYear Return the base year of the life table +setMethod("baseYear", "valuationTable.mixed", + function (object, ...) { + baseYear(object@table1) + }) diff --git a/R/deathProbabilities.R b/R/deathProbabilities.R new file mode 100644 index 0000000..b34c12b --- /dev/null +++ b/R/deathProbabilities.R @@ -0,0 +1,74 @@ +#' @include valuationTable.R valuationTable.period.R valuationTable.ageShift.R valuationTable.trendProjection.R valuationTable.improvementFactors.R valuationTable.mixed.R +NULL + +#' Return the (cohort) death probabilities of the life table given the birth year (if needed) +#' +#' @param object The life table object (class inherited from valuationTable) +#' @param ... Other parameters (currently unused) +#' @param YOB The birth year for which the death probabilities should be calculated +#' +#' @exportMethod deathProbabilities +setGeneric("deathProbabilities", function(object, ..., YOB = 1975) standardGeneric("deathProbabilities")); + +#' @describeIn deathProbabilities Return the (cohort) death probabilities of the +#' life table given the birth year (if needed) +setMethod("deathProbabilities", "valuationTable.period", + function(object, ..., YOB = 1975) { + object@modification(object@deathProbs * (1 + object@loading)); + }) + +#' @describeIn deathProbabilities Return the (cohort) death probabilities of the +#' life table given the birth year (if needed) +setMethod("deathProbabilities","valuationTable.ageShift", + function (object, ..., YOB = 1975) { + qx=object@deathProbs * (1 + object@loading); + shift = ageShift(object, YOB); + if (shift>0) { + qx = c(qx[(shift+1):length(qx)], rep(qx[length(qx)], shift)); + } else if (shift<0) { + qx = c(rep(0, -shift), qx[1:(length(qx)-(-shift))]) + } + object@modification(qx) + }) + +#' @describeIn deathProbabilities Return the (cohort) death probabilities of the +#' life table given the birth year (if needed) +setMethod("deathProbabilities","valuationTable.trendProjection", + function (object, ..., YOB = 1975) { + qx=object@deathProbs * (1 + object@loading); + if (is.null(object@trend2) || length(object@trend2) <= 1) { + ages = 0:(length(qx)-1); + damping = sapply( + ages, + function (age) { object@dampingFunction(YOB + age - object@baseYear) } + ); + finalqx = exp(-object@trend * damping) * qx; + } else { + # dampingFunction interpolates between the two trends: + weights = sapply(YOB + 0:(length(qx)-1), object@dampingFunction); + finalqx = qx * exp( + -(object@trend * (1 - weights) + object@trend2 * weights) * + (YOB + 0:(length(qx)-1) - object@baseYear)) + } + object@modification(finalqx) + }) + +#' @describeIn deathProbabilities Return the (cohort) death probabilities of the +#' life table given the birth year (if needed) +setMethod("deathProbabilities","valuationTable.improvementFactors", + function (object, ..., YOB = 1975) { + qx = object@deathProbs * (1 + object@loading); + finalqx = (1 - object@improvement)^(YOB + 0:(length(qx) - 1) - object@baseYear) * qx; + object@modification(finalqx) + }) + +#' @describeIn deathProbabilities Return the (cohort) death probabilities of the +#' life table given the birth year (if needed) +setMethod("deathProbabilities","valuationTable.mixed", + function (object, ..., YOB = 1975) { + qx1 = deathProbabilities(object@table1, ..., YOB) * (1 + object@loading); + qx2 = deathProbabilities(object@table2, ..., YOB) * (1 + object@loading); + mixedqx = (object@weight1 * qx1 + object@weight2 * qx2)/(object@weight1 + object@weight2); + object@modification(mixedqx) + }) + diff --git a/R/getCohortTable.R b/R/getCohortTable.R new file mode 100644 index 0000000..2a980a7 --- /dev/null +++ b/R/getCohortTable.R @@ -0,0 +1,23 @@ +#' @include valuationTable.R +NULL + +#' Return the cohort life table as a \code{valuationTable.period} object +#' +#' @param object The life table object (class inherited from valuationTable) +#' @param YOB The birth year for which the life table should be calculated +#' @param ... Other parameters (currently unused) +#' +#' @exportMethod getCohortTable +setGeneric("getCohortTable", function(object, YOB, ...) standardGeneric("getCohortTable")); + +#' @describeIn getCohortTable Return the cohort life table as a +#' \code{valuationTable.period} object +setMethod("getCohortTable","valuationTable", + function (object, YOB, ...) { + valuationTable.period( + name = paste(object@name, ", YOB ", YOB), + baseYear = YOB, + ages = ages(object), + deathProbs = deathProbabilities(object, YOB = YOB) + ); + }) diff --git a/R/getOmega.R b/R/getOmega.R new file mode 100644 index 0000000..94ea831 --- /dev/null +++ b/R/getOmega.R @@ -0,0 +1,33 @@ +#' @include valuationTable.R valuationTable.period.R valuationTable.mixed.R valuationTable.joined.R valuationTable.observed.R +NULL + +#' Return the maximum age of the life table +#' +#' @param object A life table object (instance of a \code{valuationTable} class) +#' +#' @exportMethod getOmega +setGeneric("getOmega", function(object) standardGeneric("getOmega")); + +#' @describeIn getOmega Return the maximum age of the period life table +setMethod("getOmega", "valuationTable.period", + function (object) { + max(object@ages, na.rm = TRUE); + }) + +#' @describeIn getOmega Return the maximum age of the mixed life table +setMethod("getOmega", "valuationTable.mixed", + function (object) { + getOmega(object@table1); + }) + +#' @describeIn getOmega Return the maximum age of the joined life table +setMethod("getOmega", "valuationTable.joined", + function (object) { + getOmega(object@table1); + }) + +#' @describeIn getOmega Return the maximum age of the joined life table +setMethod("getOmega", "valuationTable.observed", + function (object) { + max(object@ages, na.rm = TRUE); + }) diff --git a/R/getPeriodTable.R b/R/getPeriodTable.R new file mode 100644 index 0000000..08349de --- /dev/null +++ b/R/getPeriodTable.R @@ -0,0 +1,27 @@ +#' @include valuationTable.R +NULL + +#' Return the period life table as a \code{valuationTable.period} object +#' +#' @param object The life table object (class inherited from valuationTable) +#' @param Period The observation year, for which the death probabilities should +#' be determined +#' @param ... Other parameters (currently unused) +#' +#' @exportMethod getPeriodTable +setGeneric("getPeriodTable", + function(object, Period, ...) + standardGeneric("getPeriodTable") +); + +#' @describeIn getPeriodTable Return the period life table as a +#' \code{valuationTable.period} object +setMethod("getPeriodTable","valuationTable", + function (object, Period, ...) { + valuationTable.period( + name = paste(object@name, ", Period ", Period), + baseYear = Period, + ages = ages(object), + deathProbs = periodDeathProbabilities(object, Period = Period) + ) + }) diff --git a/R/lifeTable.R b/R/lifeTable.R new file mode 100644 index 0000000..6190fdd --- /dev/null +++ b/R/lifeTable.R @@ -0,0 +1,22 @@ +#' @include valuationTable.R +NULL + +#' Return the lifetable object (package lifecontingencies) for the cohort life table +#' +#' @param object The life table object (class inherited from valuationTable) +#' @param ... Parameters to be passed to the \code{deathProbabilities} method +#' of the life table +#' +#' @exportMethod lifeTable +setGeneric("lifeTable", function(object, ...) standardGeneric("lifeTable")); + +#' @describeIn lifeTable Return the lifetable object (package lifecontingencies) +#' for the cohort life table +setMethod("lifeTable","valuationTable", + function (object, ...) { + qx = deathProbabilities(object, ...); + if (qx[[length(qx)]] != 1) { + qx = c(qx, 1, 1); + } + lifecontingencies::probs2lifetable(qx, type = "qx") + }) diff --git a/R/makeQxDataFrame.R b/R/makeQxDataFrame.R new file mode 100644 index 0000000..91cf8c0 --- /dev/null +++ b/R/makeQxDataFrame.R @@ -0,0 +1,76 @@ +#' Converts one or multiple life table objects to a data frame that can be +#' plotted by \code{plotValuationTables} or \code{plotValuationTableComparisons} +#' +#' It is not required to call this function manually, \code{plotValuationTables} +#' will automatically do it if object derived from class \code{valuationTable} +#' are passed. +#' +#' @param ... Life tables (objects of classes derived from \code{valuationTable}) +#' @param YOB desired year of birth to be plotted as cohort life table (default: 1972) +#' @param Period desired observation year to be plotted (default: NA). If both +#' \code{YOB} and \code{Period} are given, a period comparison is generated. +#' @param reference Reference life table, used to show relative death +#' probabilities (i.e. the q_x for all ages are divided by the +#' corresponding probabilities of the reference table) +#' +#' @export +makeQxDataFrame = function(..., YOB = 1972, Period = NA, reference = NULL) { + # If reference is given, normalize all probabilities by that table! + data = list(...); + names(data) = lapply(data, function(t) t@name); + reference_ages = NULL; + + if (missing(Period)) { + if (!missing(reference)) { + reference_ages = ages(reference); + reference = deathProbabilities(reference, YOB = YOB); + } + data = lapply(data, function(t) { + normalize_deathProbabilities( + cbind(x = ages(t), y = deathProbabilities(t, YOB = YOB)), + reference = reference, + referenceAges = reference_ages) + }); + } else { + if (!missing(reference)) { + reference_ages = ages(reference); + reference = periodDeathProbabilities(reference, Period = Period); + } + data = lapply(data, function(t) { + normalize_deathProbabilities( + cbind(x = ages(t), y = periodDeathProbabilities(t, Period = Period)), + reference = reference, + referenceAges = reference_ages) + }); + } + + list.names = names(data) + lns <- sapply(data, nrow) + data <- as.data.frame(do.call("rbind", data)) + data$group <- rep(list.names, lns) + data +} + +normalize_deathProbabilities = function (data, reference = NULL, referenceAges = NULL) { + if (missing(reference) || missing(referenceAges) || is.null(reference) || is.null(referenceAges)) { + return(data); + } + # Find which ages exist in both and obtain those indices from the data and the reference list: + useages = intersect(data[,"x"], referenceAges) + dataindices = match(useages, data[,"x"]) + refindices = match(useages, referenceAges) + + # Find which ages in data do NOT exist in the reference ages (and are thus NOT normalized at all) + # Print a warning! + missingrefs = setdiff(data[,"x"], referenceAges) + if (length(missingrefs)>0) { + warning("Reference mortality table does not contain ages ", + missingrefs, + " required for normalization. These ages will not be normalized!") + } + + # Now divide the data by the corresponding entries from the reference list + data[dataindices, "y"] = data[dataindices, "y"] / reference[refindices] + data +} + diff --git a/R/periodDeathProbabilities.R b/R/periodDeathProbabilities.R new file mode 100644 index 0000000..67dcbfe --- /dev/null +++ b/R/periodDeathProbabilities.R @@ -0,0 +1,69 @@ +#' @include valuationTable.R valuationTable.period.R valuationTable.trendProjection.R valuationTable.improvementFactors.R valuationTable.mixed.R +NULL + +#' Return the (period) death probabilities of the life table for a given +#' observation year +#' +#' @param object The life table object (class inherited from valuationTable) +#' @param ... Other parameters (currently unused) +#' @param Period The observation year for which the period death probabilities should be determined +#' +#' @exportMethod periodDeathProbabilities +setGeneric("periodDeathProbabilities", function(object, ..., Period = 1975) standardGeneric("periodDeathProbabilities")); + +#' @describeIn periodDeathProbabilities Return the (period) death probabilities +#' of the life table for a given observation year +setMethod("periodDeathProbabilities", "valuationTable.period", + function(object, ..., Period = 1975) { + object@modification(object@deathProbs * (1 + object@loading)); + }) + +#' @describeIn periodDeathProbabilities Return the (period) death probabilities +#' of the life table for a given observation year +setMethod("periodDeathProbabilities", "valuationTable.ageShift", + function (object, ..., Period = 1975) { + # TODO + qx = object@deathProbs * (1 + object@loading); + # TODO!!! + # shift.index = match(YOB, object@shifts, 0); + # if (shift.index) {} + object@modification(qx) + }) + +#' @describeIn periodDeathProbabilities Return the (period) death probabilities +#' of the life table for a given observation year +setMethod("periodDeathProbabilities", "valuationTable.trendProjection", + function (object, ..., Period = 1975) { + qx = object@deathProbs * (1 + object@loading); + if (is.null(object@trend2) || length(object@trend2) <= 1) { + # ages = 0:(length(qx)-1); + damping = object@dampingFunction(Period - object@baseYear); + finalqx = exp(-object@trend * damping) * qx; + } else { + # TODO!!! + # dampingFunction interpolates between the two trends: + # weights = sapply(YOB+0:(length(qx)-1), object@dampingFunction); + # finalqx = qx*exp(-(object@trend*(1-weights) + object@trend2*(weights))*(YOB+0:(length(qx)-1)-object@baseYear)); + } + object@modification(finalqx) + }) + +#' @describeIn periodDeathProbabilities Return the (period) death probabilities +#' of the life table for a given observation year +setMethod("periodDeathProbabilities", "valuationTable.improvementFactors", + function (object, ..., Period = 1975) { + qx = object@deathProbs * (1 + object@loading); + finalqx = (1 - object@improvement) ^ (Period - object@baseYear) * qx; + object@modification(finalqx) + }) + +#' @describeIn periodDeathProbabilities Return the (period) death probabilities +#' of the life table for a given observation year +setMethod("periodDeathProbabilities", "valuationTable.mixed", + function (object, ..., Period = 1975) { + qx1 = periodDeathProbabilities(object@table1, ..., Period = Period) * (1 + object@loading); + qx2 = periodDeathProbabilities(object@table2, ..., Period = Period) * (1 + object@loading); + mixedqx = (object@weight1 * qx1 + object@weight2 * qx2) / (object@weight1 + object@weight2); + object@modification(mixedqx) + }) + diff --git a/R/plotValuationTableComparisons.R b/R/plotValuationTableComparisons.R new file mode 100644 index 0000000..1825956 --- /dev/null +++ b/R/plotValuationTableComparisons.R @@ -0,0 +1,71 @@ +#' Plot multiple valuation tables (life tables) in one plot, relative to a given reference table +#' +#' \code{plotValuationTableComparisons} prints multiple life tables (objects of child classes of \code{valuationTable}) 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. +#' +#' @inheritParams plotValuationTables +#' @param reference The reference table that determines the 100\% values. If not given, the first argument of \code{data} is used as reference table. +#' +#' @import scales +#' @export +plotValuationTableComparisons = function( + data, ..., + xlim = NULL, ylim = NULL, + xlab = NULL, ylab = NULL, + title = "", + legend.position = c(0.9,0.1), legend.key.width = unit(25, "mm"), + reference = NULL) +{ + # If no reference mortality table is given, use the first table (data if its a valuation table) + if (missing(reference)) { + if (inherits(data, "valuationTable")) { + reference = data; + } else { + reference = NULL;# TODO; + } + } + if (!is.data.frame(data)) { + data = makeQxDataFrame(data, ..., reference=reference); + } + if (missing(xlab)) xlab = "Alter"; + if (missing(ylab)) { + ylab = substitute(paste("Sterbewahrscheinlichkeit ", q[x], + " relativ zu ", refname), + env=list(refname=reference@name)); + } + + pl = ggplot(data, aes(x = x, y = y, colour = data$group)) + + theme_bw() + + theme( + plot.title = element_text(size=18, face="bold"), + legend.title = element_text(size=14, face="bold.italic"), + # legend in bottom right corner of the plot + legend.justification=c(1,0), legend.position=legend.position, + # No box around legend entries + legend.key = element_blank(), + legend.key.width = legend.key.width, + legend.background = element_rect(colour="gray50", linetype="solid") + ) + + geom_line() + + coord_cartesian(xlim=xlim, ylim=ylim) + + scale_y_continuous( + name=ylab, + labels=percent + # # breaks = scales::trans_breaks('log10', function(x) 10^x), + # # labels = scales::trans_format('log10', scales::math_format(10^.x)) + # #minor_breaks = log(c(sapply(x, function(x) seq(0, x, x/10))), 10) + ) + + scale_x_continuous( + name = xlab, + #breaks = function (limits) scales::trans_breaks('', function(x) 10^x), + breaks = function (limits) seq(max(min(limits),0),max(limits),5), + minor_breaks = function (limits) seq(max(round(min(limits)),0),round(max(limits)),1)#, + #labels = scales::trans_format('log10', scales::math_format(10^.x)) + + ) + + # annotation_logticks(sides="lr") + + xlab("Alter") + labs(colour="Sterbetafel"); + if (title != "") { + pl = pl + ggtitle(title); + } + pl +} diff --git a/R/plotValuationTables.R b/R/plotValuationTables.R index 1e05048..542c49d 100644 --- a/R/plotValuationTables.R +++ b/R/plotValuationTables.R @@ -1,84 +1,25 @@ -#' @export -#' If reference is given, normalize all probabilities by that table! -makeQxDataFrame = function(..., YOB=1972, Period=NA, reference=NULL) { - data=list(...); - names(data) = lapply(data, function(t) t@name); - reference_ages = NULL; - - if (missing(Period)) { - cat("Year of birth: ", YOB, "\n"); - if (!missing(reference)) { - reference_ages = ages(reference); - reference = deathProbabilities(reference, YOB=YOB); - } - data = lapply(data, function(t) { - str(deathProbabilities(t, YOB=YOB)); - normalize_deathProbabilities( - cbind(x=ages(t), y=deathProbabilities(t, YOB=YOB)), - reference = reference, - referenceAges = reference_ages) - }); - } else { - cat("Period: ", Period,"\n"); - if (!missing(reference)) { - reference_ages = ages(reference); - reference = periodDeathProbabilities(reference, Period=Period); - } - data = lapply(data, function(t) { - str(deathProbabilities(t, YOB=YOB)); - normalize_deathProbabilities( - cbind(x=ages(t), y=periodDeathProbabilities(t, Period=Period)), - reference = reference, - referenceAges = reference_ages) - }); - } - - list.names = names(data) - lns <- sapply(data, nrow) - data <- as.data.frame(do.call("rbind", data)) - data$group <- rep(list.names, lns) - data -} - -normalize_deathProbabilities = function (data, reference=NULL, referenceAges=NULL) { - if (missing(reference) || missing(referenceAges) || is.null(reference) || is.null(referenceAges)) { - return(data); - } -# browser(); - # Find which ages exist in both and obtain those indices from the data and the reference list: - useages = intersect(data[,"x"], referenceAges) - dataindices = match(useages, data[,"x"]) - refindices = match(useages, referenceAges) - - # Find which ages in data do NOT exist in the reference ages (and are thus NOT normalized at all) - # Print a warning! - missingrefs = setdiff(data[,"x"], referenceAges) - if (length(missingrefs)>0) { - warning("Reference mortality table does not contain ages ", - missingrefs, - " required for normalization. These ages will not be normalized!") - } - - # Now divide the data by the corresponding entries from the reference list - data[dataindices, "y"] = data[dataindices, "y"] / reference[refindices] - data -} - #' Plot multiple valuation tables (life tables) in one plot #' #' \code{plotValuationTables} prints multiple life tables (objects of child classes of \code{valuationTable}) in one log-linear plot, with a legend showing the names of the tables. #' #' @param data First life table to be plotted. Either a \code{data.frame} generated by \code{makeQxDataFrame} or a \code{valuationTable} object #' @param ... Additional life tables to be plotted (if \code{data} is a \code{valuationTable} object) +#' @param xlim X-axis limitatation (as a two-element vector) +#' @param ylim Y-axis limitatation (as a two-element vector) +#' @param xlab X-axis label (default: "Alter") +#' @param ylab Y-axis label (default: "Sterbewahrscheinlichkeit q_x relativ zu ....") #' @param title The plot title #' @param legend.position The position of the legend (default is \code{c(0.9,0.1)}) #' @param legend.key.width The keywith of the lines in the legend (default is \code{unit(25,"mm")}) #' +#' @import scales #' @export -plotValuationTables = function(data, ..., xlim=NULL, ylim=NULL, title = "", legend.position=c(0.9,0.1), legend.key.width = unit(25, "mm")) { +plotValuationTables = function(data, ..., xlim=NULL, ylim=NULL, xlab=NULL, ylab=NULL, title = "", legend.position=c(0.9,0.1), legend.key.width = unit(25, "mm")) { if (!is.data.frame(data)) { data = makeQxDataFrame(data, ...); } + if (missing(xlab)) xlab="Alter"; + if (missing(ylab)) ylab=expression(paste("Sterbewahrscheinlichkeit ", q[x])); pl = ggplot(data, aes(x = x, y = y, colour = data$group)) + theme_bw() + @@ -94,16 +35,16 @@ plotValuationTables = function(data, ..., xlim=NULL, ylim=NULL, title = "", lege ) + geom_line() + scale_y_log10( - name=expression(paste("Sterbewahrscheinlichkeit ", q[x])), + name = ylab, breaks = scales::trans_breaks('log10', function(x) 10^x), labels = scales::trans_format('log10', scales::math_format(10^.x)) #minor_breaks = log(c(sapply(x, function(x) seq(0, x, x/10))), 10) ) + scale_x_continuous( - name="Alter", + name = xlab, #breaks = function (limits) scales::trans_breaks('', function(x) 10^x), breaks = function (limits) seq(max(min(limits),0),max(limits),5), - minor_breaks = function (limits) seq(max(round(min(limits)),0),round(max(limits)),1), + minor_breaks = function (limits) seq(max(round(min(limits)),0),round(max(limits)),1) #labels = scales::trans_format('log10', scales::math_format(10^.x)) ) + @@ -116,60 +57,6 @@ plotValuationTables = function(data, ..., xlim=NULL, ylim=NULL, title = "", lege pl } -plotValuationTableComparisons = function(data, ..., xlim=NULL, ylim=NULL, title = "", legend.position=c(0.9,0.1), legend.key.width = unit(25, "mm"), reference=NULL) { - # If no reference mortality table is given, use the first table (data if its a valuation table) - if (missing(reference)) { - if (inherits(data, "valuationTable")) { - reference = data; - } else { - reference = NULL;# TODO; - } - } - refname=reference@name; - yAxisLabel = expression(paste("Sterbewahrscheinlichkeit ", q[x], " relativ zu ", refname)); -yAxisLabel[1][3]="asfd" -yAxisLabel - if (!is.data.frame(data)) { - data = makeQxDataFrame(data, ..., reference=reference); - } - - pl = ggplot(data, aes(x = x, y = y, colour = data$group)) + - theme_bw() + - theme( - plot.title = element_text(size=18, face="bold"), - legend.title = element_text(size=14, face="bold.italic"), - # legend in bottom right corner of the plot - legend.justification=c(1,0), legend.position=legend.position, - # No box around legend entries - legend.key = element_blank(), - legend.key.width = legend.key.width, - legend.background = element_rect(colour="gray50", linetype="solid") - ) + - geom_line() + - coord_cartesian(xlim=xlim, ylim=ylim) + - scale_y_continuous( -# #name=substitute(paste("Sterbewahrscheinlichkeit ", q[x], " relativ zu ", refname), env=list(refname=refname))#, - name=substitute(refname^3, env=list(refname=refname)), - labels=percent -# # breaks = scales::trans_breaks('log10', function(x) 10^x), -# # labels = scales::trans_format('log10', scales::math_format(10^.x)) -# #minor_breaks = log(c(sapply(x, function(x) seq(0, x, x/10))), 10) - ) + - scale_x_continuous( - name="Alter", - #breaks = function (limits) scales::trans_breaks('', function(x) 10^x), - breaks = function (limits) seq(max(min(limits),0),max(limits),5), - minor_breaks = function (limits) seq(max(round(min(limits)),0),round(max(limits)),1), - #labels = scales::trans_format('log10', scales::math_format(10^.x)) - - ) + - # annotation_logticks(sides="lr") + - xlab("Alter") + labs(colour="Sterbetafel"); - if (title != "") { - pl = pl + ggtitle(title); - } - pl -} # # plotValuationTables(mort.AT.census.1869.male, mort.AT.census.1869.female, mort.AT.census.2011.male, mort.AT.census.2011.female, AVOe2005R.male, AVOe2005R.female, YOB=1972,title="Vergleich österreichische Sterbetafeln, YOB=1972 (bei Generationentafeln)") diff --git a/R/setLoading.R b/R/setLoading.R new file mode 100644 index 0000000..3de795e --- /dev/null +++ b/R/setLoading.R @@ -0,0 +1,17 @@ +#' @include valuationTable.R +NULL + +#' Return a copy of the table with an additional loading added +#' +#' @param object A life table object (instance of a \code{valuationTable} class) +#' @param loading The additional (security) loading to be added to the table. +#' +#' @exportMethod setLoading +setGeneric("setLoading", function(object, loading = 0) standardGeneric("setLoading")); + +#' @describeIn setLoading Return the life table with the given loading set +setMethod("setLoading", "valuationTable", + function (object, loading = 0) { + object@loading = loading; + object + }) diff --git a/R/undampenTrend.R b/R/undampenTrend.R new file mode 100644 index 0000000..a3d08bb --- /dev/null +++ b/R/undampenTrend.R @@ -0,0 +1,17 @@ +#' @include valuationTable.trendProjection.R +NULL + +#' Return a \code{valuationTable.trendProjection} object with the trend damping removed. +#' +#' @param object The life table object (class inherited from valuationTable) +#' +#' @exportMethod undampenTrend +setGeneric("undampenTrend", function (object) standardGeneric("undampenTrend")); + +#' @describeIn undampenTrend Return a \code{valuationTable.trendProjection} +#' object with the trend damping removed. +setMethod("undampenTrend", "valuationTable.trendProjection", + function (object) { + object@dampingFunction=identity; + object + }) diff --git a/R/valuationTable.R b/R/valuationTable.R new file mode 100644 index 0000000..7366938 --- /dev/null +++ b/R/valuationTable.R @@ -0,0 +1,40 @@ +#' Provide life table classes for life insurance purposes +#' +#' @import methods +#' @import ggplot2 +#' +"_PACKAGE" + + +#' Class valuationTable +#' +#' Class \code{valuationTable} is the (virtual) base class for all valuation +#' tables. It contains the name and some general values applying to all +#' types of tables, but does not contain any data itself. Use a child class +#' to create actual valuation tables. +#' +#' @slot name The human-readable name of the valuation table +#' @slot baseYear The base year of the valuation table (e.g. for tables with trend projection) +#' @slot modification A function that will be called with the final death probabilities +#' to give the user a way to modify the final probabilities +#' @slot loading Additional security loading on the resulting table (single numeric +#' value, e.g. 0.05 adds 5\% security margin to the probabilities) +#' +#' @export valuationTable +#' @exportClass valuationTable +valuationTable=setClass( + "valuationTable", + slots = list( + name = "character", + baseYear = "numeric", + loading = "numeric", + modification = "function" + ), + prototype = list( + name = "Actuarial Valuation Table", + baseYear = 2000, + loading = 0, + modification = identity + ), + contains = "VIRTUAL" +) diff --git a/R/valuationTable.ageShift.R b/R/valuationTable.ageShift.R new file mode 100644 index 0000000..5bcfe86 --- /dev/null +++ b/R/valuationTable.ageShift.R @@ -0,0 +1,22 @@ +#' @include valuationTable.R valuationTable.period.R +NULL + +#' Class valuationTable.ageShift - Cohort life tables generated by age-shift +#' +#' A cohort life table, obtained by age-shifting from a given base table (death probabilities +# for a base birth year) +#' +#' @slot ageShifts A \code{data.frame} with columns \code{YOB} and \code{shifts} giving the age shifts for each birth year +#' +#' @export valuationTable.ageShift +#' @exportClass valuationTable.ageShift +valuationTable.ageShift = setClass( + "valuationTable.ageShift", + slots = list( + ageShifts = "data.frame" + ), + prototype = list( + ageShifts = data.frame(YOB = c(), shifts = c()) + ), + contains = "valuationTable.period" +) diff --git a/R/valuationTable.improvementFactors.R b/R/valuationTable.improvementFactors.R new file mode 100644 index 0000000..53925a9 --- /dev/null +++ b/R/valuationTable.improvementFactors.R @@ -0,0 +1,27 @@ +#' @include valuationTable.R valuationTable.period.R +NULL + +#' Class valuationTable.improvementFactors - Cohort life table with improvement +#' factors +#' +#' A cohort life table, obtained by an improvment factor projection +#' from a given base table (PODs for a given observation year). +#' +#' @slot baseYear The base year for the improvements (\code{baseTable} +#' describes the death probabilities in this year) +#' @slot improvement Yearly improvement factors per age +#' +#' @export valuationTable.improvementFactors +#' @exportClass valuationTable.improvementFactors +valuationTable.improvementFactors = setClass( + "valuationTable.improvementFactors", + slots = list( + baseYear = "numeric", + improvement = "numeric" + ), + prototype = list( + baseYear = 2012, + improvement = rep(0,120) + ), + contains = "valuationTable.period" +) diff --git a/R/valuationTable.joined.R b/R/valuationTable.joined.R new file mode 100644 index 0000000..ec797e0 --- /dev/null +++ b/R/valuationTable.joined.R @@ -0,0 +1,26 @@ +#' @include valuationTable.R +NULL + +#' Class valuationTable.joined - Life table created by joining two life tables +#' +#' A cohort life table obtained by joining two cohort life tables, each of which +#' applies only to certain observation years (e.g. for the past use the observed +#' PoDs, and project them to the future with the trend projection) +#' +#' @slot table1 The first \code{valuationTable}, valid for years given in \code{yearRange1} +#' @slot yearRange1 The years, for which \code{table1} describes the death probabilities +#' @slot table2 The second \code{valuationTable}, valid for years given in \code{yearRange2} +#' @slot yearRange2 The years, for which \code{table2} describes the death probabilities +#' +#' @export valuationTable.joined +#' @exportClass valuationTable.joined +valuationTable.joined = setClass( + "valuationTable.joined", + slots=list( + table1 = "valuationTable", + yearRange1 = "numeric", + table2 = "valuationTable", + yearRange2 = "numeric" + ), + contains = "valuationTable" +) diff --git a/R/valuationTable.mixed.R b/R/valuationTable.mixed.R new file mode 100644 index 0000000..c5acb33 --- /dev/null +++ b/R/valuationTable.mixed.R @@ -0,0 +1,31 @@ +#' @include valuationTable.R +NULL + +#' Class valuationTable.mixed - Life table as a mix of two life tables +#' +#' A cohort life table obtained by mixing two life tables with the given weights +#' +#' @slot table1 The first \code{valuationTable} +#' @slot table2 The second \code{valuationTable} +#' @slot weight1 The weight of the first valuation table +#' @slot weight2 The weight of the second valuation table +#' @slot loading Additional security loading +#' +#' @export valuationTable.mixed +#' @exportClass valuationTable.mixed +valuationTable.mixed = setClass( + "valuationTable.mixed", + slots = c( + table1 = "valuationTable", + table2 = "valuationTable", + weight1 = "numeric", + weight2 = "numeric", + loading = "numeric" + ), + prototype=list( + weight1 = 1/2, + weight2 = 1/2, + loading = 0 + ), + contains = "valuationTable" +) diff --git a/R/valuationTable.observed.R b/R/valuationTable.observed.R new file mode 100644 index 0000000..d86201a --- /dev/null +++ b/R/valuationTable.observed.R @@ -0,0 +1,28 @@ +#' @include valuationTable.R +NULL + +#' Class valuationTable.observed - Life table from actual observations +#' +#' A cohort life table described by actual observations (data frame of PODs +#' per year and age) +#' +#' @slot data The observations +#' @slot years The observation years +#' @slot ages The observation ages +#' +#' @export valuationTable.observed +#' @exportClass valuationTable.observed +valuationTable.observed = setClass( + "valuationTable.observed", + slots = list( + data = "data.frame", + years = "numeric", + ages = "numeric" + ), + prototype = list( + data = data.frame(), + years = c(), + ages = c() + ), + contains = "valuationTable" +) diff --git a/R/valuationTable.period.R b/R/valuationTable.period.R new file mode 100644 index 0000000..89802ee --- /dev/null +++ b/R/valuationTable.period.R @@ -0,0 +1,25 @@ +#' @include valuationTable.R +NULL + +#' Class valuationTable.period - Period life tables +#' +#' A period life table, giving death probabilities for each age, up to +#' maximum age omega. Optionally apply selection factors to the probabilities +#' +#' @slot ages The ages corresponding to the entries of the deathProbs +#' @slot deathProbs The one-year death probabilities for the ages +#' +#' @export valuationTable.period +#' @exportClass valuationTable.period +valuationTable.period = setClass( + "valuationTable.period", + slots = list( + ages = "numeric", + deathProbs = "numeric" + ), + prototype = list( + ages = eval(0:120), + deathProbs = rep(1,120) + ), + contains = "valuationTable" +) diff --git a/R/valuationTable.trendProjection.R b/R/valuationTable.trendProjection.R new file mode 100644 index 0000000..3da5c67 --- /dev/null +++ b/R/valuationTable.trendProjection.R @@ -0,0 +1,42 @@ +#' @include valuationTable.R valuationTable.period.R +NULL + +#' Class valuationTable.trendProjection - Cohort life table with age-specific trend +#' +#' A cohort life table, obtained by a trend projection from a given base table +#' (PODs for a given observation year). Typically, the trend is obtained by +#' the Lee-Carter method or some other trend estimation. +#' The dampingFunction can be used to modify the cumulative years (e.g. G(tau+x) +#' instead of tau+x) +#' If trend2 is given, the G(tau+x) gives the weight of the first trend, +#' 1-G(tau+x) the weight of the second trend +#' +#' @slot baseYear The base year of the trend projection (\code{baseTable} +#' describes the death probabilities in this year) +#' @slot trend The yearly improvements of the log-death probabilities (per age) +#' @slot dampingFunction A possible damping of the trend. This is a function +#' \code{damping(delta_years)} that gets a vector of years +#' from the baseYear and should return the dampened values. +#' @slot trend2 The alternate trend. If given, the damping function +#' interpolates between \code{trend} and \code{trend2}, otherwise +#' the dumping function simply modifies the coefficients of +#' \code{trend}. +#' +#' @export valuationTable.trendProjection +#' @exportClass valuationTable.trendProjection +valuationTable.trendProjection = setClass( + "valuationTable.trendProjection", + slots = list( + baseYear = "numeric", + trend = "numeric", + dampingFunction = "function", + trend2 = "numeric" + ), + prototype = list( + baseYear = 1980, + trend = rep(0,120), + dampingFunction = identity, + trend2 = 0 + ), + contains = "valuationTable.period" +) diff --git a/Read-and-delete-me b/Read-and-delete-me deleted file mode 100644 index dcaca43..0000000 --- a/Read-and-delete-me +++ /dev/null @@ -1,8 +0,0 @@ -* Edit the help file skeletons in 'man', possibly combining help files for multiple functions. -* Edit the exports in 'NAMESPACE', and add necessary imports. -* Put any C/C++/Fortran code in 'src'. -* If you have compiled code, add a useDynLib() directive to 'NAMESPACE'. -* Run R CMD build to build the package tarball. -* Run R CMD check to check the package tarball. - -Read "Writing R Extensions" for more information. diff --git a/ValuationTables.Rproj b/ValuationTables.Rproj index d4713ef..ee5cfd9 100644 --- a/ValuationTables.Rproj +++ b/ValuationTables.Rproj @@ -6,7 +6,7 @@ AlwaysSaveHistory: Default EnableCodeIndexing: Yes UseSpacesForTab: Yes -NumSpacesForTab: 2 +NumSpacesForTab: 4 Encoding: UTF-8 RnwWeave: Sweave diff --git a/man/ValuationTables-package.Rd b/man/ValuationTables-package.Rd index be62d48..3aecba0 100644 --- a/man/ValuationTables-package.Rd +++ b/man/ValuationTables-package.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ValuationTables.R +% Please edit documentation in R/valuationTable.R \docType{package} \name{ValuationTables-package} \alias{ValuationTables} diff --git a/man/ageShift.Rd b/man/ageShift.Rd new file mode 100644 index 0000000..88d2e91 --- /dev/null +++ b/man/ageShift.Rd @@ -0,0 +1,28 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/ageShift.R +\docType{methods} +\name{ageShift} +\alias{ageShift} +\alias{ageShift,valuationTable.ageShift-method} +\title{Return the age shift of the age-shifted life table given the birth year} +\usage{ +ageShift(object, YOB = 1975, ...) + +\S4method{ageShift}{valuationTable.ageShift}(object, YOB = 1975, ...) +} +\arguments{ +\item{object}{The life table object (class inherited from valuationTable)} + +\item{YOB}{The birth year for which the age shift should be determined.} + +\item{...}{Other parameters (currently unused)} +} +\description{ +Return the age shift of the age-shifted life table given the birth year +} +\section{Methods (by class)}{ +\itemize{ +\item \code{valuationTable.ageShift}: Return the age shift of the age-shifted life table +given the birth year +}} + diff --git a/man/ages.Rd b/man/ages.Rd new file mode 100644 index 0000000..142107a --- /dev/null +++ b/man/ages.Rd @@ -0,0 +1,40 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/ages.R +\docType{methods} +\name{ages} +\alias{ages} +\alias{ages,valuationTable.joined-method} +\alias{ages,valuationTable.mixed-method} +\alias{ages,valuationTable.observed-method} +\alias{ages,valuationTable.period-method} +\title{Return the defined ages of the life table} +\usage{ +ages(object, ...) + +\S4method{ages}{valuationTable.period}(object, ...) + +\S4method{ages}{valuationTable.mixed}(object, ...) + +\S4method{ages}{valuationTable.joined}(object, ...) + +\S4method{ages}{valuationTable.observed}(object, ...) +} +\arguments{ +\item{object}{A life table object (instance of a \code{valuationTable} class)} + +\item{...}{Currently unused} +} +\description{ +Return the defined ages of the life table +} +\section{Methods (by class)}{ +\itemize{ +\item \code{valuationTable.period}: Return the defined ages of the life table + +\item \code{valuationTable.mixed}: Return the defined ages of the life table + +\item \code{valuationTable.joined}: Return the defined ages of the life table + +\item \code{valuationTable.observed}: Return the defined ages of the life table +}} + diff --git a/man/baseTable.Rd b/man/baseTable.Rd new file mode 100644 index 0000000..2956b33 --- /dev/null +++ b/man/baseTable.Rd @@ -0,0 +1,30 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/baseTable.R +\docType{methods} +\name{baseTable} +\alias{baseTable} +\alias{baseTable,valuationTable-method} +\alias{baseTable,valuationTable.period-method} +\title{Return the base table of the life table} +\usage{ +baseTable(object, ...) + +\S4method{baseTable}{valuationTable}(object, ...) + +\S4method{baseTable}{valuationTable.period}(object, ...) +} +\arguments{ +\item{object}{The life table object (class inherited from valuationTable)} + +\item{...}{Other parameters (currently unused)} +} +\description{ +Return the base table of the life table +} +\section{Methods (by class)}{ +\itemize{ +\item \code{valuationTable}: Return the base table of the life table + +\item \code{valuationTable.period}: Return the base table of the life table +}} + diff --git a/man/baseYear.Rd b/man/baseYear.Rd new file mode 100644 index 0000000..896cacf --- /dev/null +++ b/man/baseYear.Rd @@ -0,0 +1,30 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/baseYear.R +\docType{methods} +\name{baseYear} +\alias{baseYear} +\alias{baseYear,valuationTable-method} +\alias{baseYear,valuationTable.mixed-method} +\title{Return the base year of the life table} +\usage{ +baseYear(object, ...) + +\S4method{baseYear}{valuationTable}(object, ...) + +\S4method{baseYear}{valuationTable.mixed}(object, ...) +} +\arguments{ +\item{object}{The life table object (class inherited from valuationTable)} + +\item{...}{Other parameters (currently unused)} +} +\description{ +Return the base year of the life table +} +\section{Methods (by class)}{ +\itemize{ +\item \code{valuationTable}: Return the base year of the life table + +\item \code{valuationTable.mixed}: Return the base year of the life table +}} + diff --git a/man/deathProbabilities.Rd b/man/deathProbabilities.Rd new file mode 100644 index 0000000..7b5fc96 --- /dev/null +++ b/man/deathProbabilities.Rd @@ -0,0 +1,55 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/deathProbabilities.R +\docType{methods} +\name{deathProbabilities} +\alias{deathProbabilities} +\alias{deathProbabilities,valuationTable.ageShift-method} +\alias{deathProbabilities,valuationTable.improvementFactors-method} +\alias{deathProbabilities,valuationTable.mixed-method} +\alias{deathProbabilities,valuationTable.period-method} +\alias{deathProbabilities,valuationTable.trendProjection-method} +\title{Return the (cohort) death probabilities of the life table given the birth year (if needed)} +\usage{ +deathProbabilities(object, ..., YOB = 1975) + +\S4method{deathProbabilities}{valuationTable.period}(object, ..., YOB = 1975) + +\S4method{deathProbabilities}{valuationTable.ageShift}(object, ..., + YOB = 1975) + +\S4method{deathProbabilities}{valuationTable.trendProjection}(object, ..., + YOB = 1975) + +\S4method{deathProbabilities}{valuationTable.improvementFactors}(object, ..., + YOB = 1975) + +\S4method{deathProbabilities}{valuationTable.mixed}(object, ..., YOB = 1975) +} +\arguments{ +\item{object}{The life table object (class inherited from valuationTable)} + +\item{...}{Other parameters (currently unused)} + +\item{YOB}{The birth year for which the death probabilities should be calculated} +} +\description{ +Return the (cohort) death probabilities of the life table given the birth year (if needed) +} +\section{Methods (by class)}{ +\itemize{ +\item \code{valuationTable.period}: Return the (cohort) death probabilities of the +life table given the birth year (if needed) + +\item \code{valuationTable.ageShift}: Return the (cohort) death probabilities of the +life table given the birth year (if needed) + +\item \code{valuationTable.trendProjection}: Return the (cohort) death probabilities of the +life table given the birth year (if needed) + +\item \code{valuationTable.improvementFactors}: Return the (cohort) death probabilities of the +life table given the birth year (if needed) + +\item \code{valuationTable.mixed}: Return the (cohort) death probabilities of the +life table given the birth year (if needed) +}} + diff --git a/man/getCohortTable.Rd b/man/getCohortTable.Rd new file mode 100644 index 0000000..82494cd --- /dev/null +++ b/man/getCohortTable.Rd @@ -0,0 +1,28 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/getCohortTable.R +\docType{methods} +\name{getCohortTable} +\alias{getCohortTable} +\alias{getCohortTable,valuationTable-method} +\title{Return the cohort life table as a \code{valuationTable.period} object} +\usage{ +getCohortTable(object, YOB, ...) + +\S4method{getCohortTable}{valuationTable}(object, YOB, ...) +} +\arguments{ +\item{object}{The life table object (class inherited from valuationTable)} + +\item{YOB}{The birth year for which the life table should be calculated} + +\item{...}{Other parameters (currently unused)} +} +\description{ +Return the cohort life table as a \code{valuationTable.period} object +} +\section{Methods (by class)}{ +\itemize{ +\item \code{valuationTable}: Return the cohort life table as a +\code{valuationTable.period} object +}} + diff --git a/man/getOmega.Rd b/man/getOmega.Rd new file mode 100644 index 0000000..d1c4e27 --- /dev/null +++ b/man/getOmega.Rd @@ -0,0 +1,38 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/getOmega.R +\docType{methods} +\name{getOmega} +\alias{getOmega} +\alias{getOmega,valuationTable.joined-method} +\alias{getOmega,valuationTable.mixed-method} +\alias{getOmega,valuationTable.observed-method} +\alias{getOmega,valuationTable.period-method} +\title{Return the maximum age of the life table} +\usage{ +getOmega(object) + +\S4method{getOmega}{valuationTable.period}(object) + +\S4method{getOmega}{valuationTable.mixed}(object) + +\S4method{getOmega}{valuationTable.joined}(object) + +\S4method{getOmega}{valuationTable.observed}(object) +} +\arguments{ +\item{object}{A life table object (instance of a \code{valuationTable} class)} +} +\description{ +Return the maximum age of the life table +} +\section{Methods (by class)}{ +\itemize{ +\item \code{valuationTable.period}: Return the maximum age of the period life table + +\item \code{valuationTable.mixed}: Return the maximum age of the mixed life table + +\item \code{valuationTable.joined}: Return the maximum age of the joined life table + +\item \code{valuationTable.observed}: Return the maximum age of the joined life table +}} + diff --git a/man/getPeriodTable.Rd b/man/getPeriodTable.Rd new file mode 100644 index 0000000..6cbac14 --- /dev/null +++ b/man/getPeriodTable.Rd @@ -0,0 +1,29 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/getPeriodTable.R +\docType{methods} +\name{getPeriodTable} +\alias{getPeriodTable} +\alias{getPeriodTable,valuationTable-method} +\title{Return the period life table as a \code{valuationTable.period} object} +\usage{ +getPeriodTable(object, Period, ...) + +\S4method{getPeriodTable}{valuationTable}(object, Period, ...) +} +\arguments{ +\item{object}{The life table object (class inherited from valuationTable)} + +\item{Period}{The observation year, for which the death probabilities should +be determined} + +\item{...}{Other parameters (currently unused)} +} +\description{ +Return the period life table as a \code{valuationTable.period} object +} +\section{Methods (by class)}{ +\itemize{ +\item \code{valuationTable}: Return the period life table as a +\code{valuationTable.period} object +}} + diff --git a/man/lifeTable.Rd b/man/lifeTable.Rd new file mode 100644 index 0000000..6b30753 --- /dev/null +++ b/man/lifeTable.Rd @@ -0,0 +1,27 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/lifeTable.R +\docType{methods} +\name{lifeTable} +\alias{lifeTable} +\alias{lifeTable,valuationTable-method} +\title{Return the lifetable object (package lifecontingencies) for the cohort life table} +\usage{ +lifeTable(object, ...) + +\S4method{lifeTable}{valuationTable}(object, ...) +} +\arguments{ +\item{object}{The life table object (class inherited from valuationTable)} + +\item{...}{Parameters to be passed to the \code{deathProbabilities} method +of the life table} +} +\description{ +Return the lifetable object (package lifecontingencies) for the cohort life table +} +\section{Methods (by class)}{ +\itemize{ +\item \code{valuationTable}: Return the lifetable object (package lifecontingencies) +for the cohort life table +}} + diff --git a/man/makeQxDataFrame.Rd b/man/makeQxDataFrame.Rd new file mode 100644 index 0000000..76ffdea --- /dev/null +++ b/man/makeQxDataFrame.Rd @@ -0,0 +1,27 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/makeQxDataFrame.R +\name{makeQxDataFrame} +\alias{makeQxDataFrame} +\title{Converts one or multiple life table objects to a data frame that can be +plotted by \code{plotValuationTables} or \code{plotValuationTableComparisons}} +\usage{ +makeQxDataFrame(..., YOB = 1972, Period = NA, reference = NULL) +} +\arguments{ +\item{...}{Life tables (objects of classes derived from \code{valuationTable})} + +\item{YOB}{desired year of birth to be plotted as cohort life table (default: 1972)} + +\item{Period}{desired observation year to be plotted (default: NA). If both +\code{YOB} and \code{Period} are given, a period comparison is generated.} + +\item{reference}{Reference life table, used to show relative death +probabilities (i.e. the q_x for all ages are divided by the +corresponding probabilities of the reference table)} +} +\description{ +It is not required to call this function manually, \code{plotValuationTables} +will automatically do it if object derived from class \code{valuationTable} +are passed. +} + diff --git a/man/periodDeathProbabilities.Rd b/man/periodDeathProbabilities.Rd new file mode 100644 index 0000000..57ee3b1 --- /dev/null +++ b/man/periodDeathProbabilities.Rd @@ -0,0 +1,59 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/periodDeathProbabilities.R +\docType{methods} +\name{periodDeathProbabilities} +\alias{periodDeathProbabilities} +\alias{periodDeathProbabilities,valuationTable.ageShift-method} +\alias{periodDeathProbabilities,valuationTable.improvementFactors-method} +\alias{periodDeathProbabilities,valuationTable.mixed-method} +\alias{periodDeathProbabilities,valuationTable.period-method} +\alias{periodDeathProbabilities,valuationTable.trendProjection-method} +\title{Return the (period) death probabilities of the life table for a given +observation year} +\usage{ +periodDeathProbabilities(object, ..., Period = 1975) + +\S4method{periodDeathProbabilities}{valuationTable.period}(object, ..., + Period = 1975) + +\S4method{periodDeathProbabilities}{valuationTable.ageShift}(object, ..., + Period = 1975) + +\S4method{periodDeathProbabilities}{valuationTable.trendProjection}(object, ..., + Period = 1975) + +\S4method{periodDeathProbabilities}{valuationTable.improvementFactors}(object, + ..., Period = 1975) + +\S4method{periodDeathProbabilities}{valuationTable.mixed}(object, ..., + Period = 1975) +} +\arguments{ +\item{object}{The life table object (class inherited from valuationTable)} + +\item{...}{Other parameters (currently unused)} + +\item{Period}{The observation year for which the period death probabilities should be determined} +} +\description{ +Return the (period) death probabilities of the life table for a given +observation year +} +\section{Methods (by class)}{ +\itemize{ +\item \code{valuationTable.period}: Return the (period) death probabilities +of the life table for a given observation year + +\item \code{valuationTable.ageShift}: Return the (period) death probabilities +of the life table for a given observation year + +\item \code{valuationTable.trendProjection}: Return the (period) death probabilities +of the life table for a given observation year + +\item \code{valuationTable.improvementFactors}: Return the (period) death probabilities +of the life table for a given observation year + +\item \code{valuationTable.mixed}: Return the (period) death probabilities +of the life table for a given observation year +}} + diff --git a/man/plotValuationTableComparisons.Rd b/man/plotValuationTableComparisons.Rd new file mode 100644 index 0000000..02841f6 --- /dev/null +++ b/man/plotValuationTableComparisons.Rd @@ -0,0 +1,35 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/plotValuationTableComparisons.R +\name{plotValuationTableComparisons} +\alias{plotValuationTableComparisons} +\title{Plot multiple valuation tables (life tables) in one plot, relative to a given reference table} +\usage{ +plotValuationTableComparisons(data, ..., xlim = NULL, ylim = NULL, + xlab = NULL, ylab = NULL, title = "", legend.position = c(0.9, 0.1), + legend.key.width = unit(25, "mm"), reference = NULL) +} +\arguments{ +\item{data}{First life table to be plotted. Either a \code{data.frame} generated by \code{makeQxDataFrame} or a \code{valuationTable} object} + +\item{...}{Additional life tables to be plotted (if \code{data} is a \code{valuationTable} object)} + +\item{xlim}{X-axis limitatation (as a two-element vector)} + +\item{ylim}{Y-axis limitatation (as a two-element vector)} + +\item{xlab}{X-axis label (default: "Alter")} + +\item{ylab}{Y-axis label (default: "Sterbewahrscheinlichkeit q_x relativ zu ....")} + +\item{title}{The plot title} + +\item{legend.position}{The position of the legend (default is \code{c(0.9,0.1)})} + +\item{legend.key.width}{The keywith of the lines in the legend (default is \code{unit(25,"mm")})} + +\item{reference}{The reference table that determines the 100\% values. If not given, the first argument of \code{data} is used as reference table.} +} +\description{ +\code{plotValuationTableComparisons} prints multiple life tables (objects of child classes of \code{valuationTable}) 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. +} + diff --git a/man/plotValuationTables.Rd b/man/plotValuationTables.Rd index 2d855be..088d13b 100644 --- a/man/plotValuationTables.Rd +++ b/man/plotValuationTables.Rd @@ -4,7 +4,8 @@ \alias{plotValuationTables} \title{Plot multiple valuation tables (life tables) in one plot} \usage{ -plotValuationTables(data, ..., title = "", legend.position = c(0.9, 0.1), +plotValuationTables(data, ..., xlim = NULL, ylim = NULL, xlab = NULL, + ylab = NULL, title = "", legend.position = c(0.9, 0.1), legend.key.width = unit(25, "mm")) } \arguments{ @@ -12,6 +13,14 @@ plotValuationTables(data, ..., title = "", legend.position = c(0.9, 0.1), \item{...}{Additional life tables to be plotted (if \code{data} is a \code{valuationTable} object)} +\item{xlim}{X-axis limitatation (as a two-element vector)} + +\item{ylim}{Y-axis limitatation (as a two-element vector)} + +\item{xlab}{X-axis label (default: "Alter")} + +\item{ylab}{Y-axis label (default: "Sterbewahrscheinlichkeit q_x relativ zu ....")} + \item{title}{The plot title} \item{legend.position}{The position of the legend (default is \code{c(0.9,0.1)})} diff --git a/man/setLoading.Rd b/man/setLoading.Rd new file mode 100644 index 0000000..0914b2a --- /dev/null +++ b/man/setLoading.Rd @@ -0,0 +1,25 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/setLoading.R +\docType{methods} +\name{setLoading} +\alias{setLoading} +\alias{setLoading,valuationTable-method} +\title{Return a copy of the table with an additional loading added} +\usage{ +setLoading(object, loading = 0) + +\S4method{setLoading}{valuationTable}(object, loading = 0) +} +\arguments{ +\item{object}{A life table object (instance of a \code{valuationTable} class)} + +\item{loading}{The additional (security) loading to be added to the table.} +} +\description{ +Return a copy of the table with an additional loading added +} +\section{Methods (by class)}{ +\itemize{ +\item \code{valuationTable}: Return the life table with the given loading set +}} + diff --git a/man/undampenTrend.Rd b/man/undampenTrend.Rd new file mode 100644 index 0000000..f49416e --- /dev/null +++ b/man/undampenTrend.Rd @@ -0,0 +1,24 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/undampenTrend.R +\docType{methods} +\name{undampenTrend} +\alias{undampenTrend} +\alias{undampenTrend,valuationTable.trendProjection-method} +\title{Return a \code{valuationTable.trendProjection} object with the trend damping removed.} +\usage{ +undampenTrend(object) + +\S4method{undampenTrend}{valuationTable.trendProjection}(object) +} +\arguments{ +\item{object}{The life table object (class inherited from valuationTable)} +} +\description{ +Return a \code{valuationTable.trendProjection} object with the trend damping removed. +} +\section{Methods (by class)}{ +\itemize{ +\item \code{valuationTable.trendProjection}: Return a \code{valuationTable.trendProjection} +object with the trend damping removed. +}} + diff --git a/man/valuationTable-class.Rd b/man/valuationTable-class.Rd index 49e5016..89df9ad 100644 --- a/man/valuationTable-class.Rd +++ b/man/valuationTable-class.Rd @@ -1,94 +1,15 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ValuationTables.R +% Please edit documentation in R/valuationTable.R \docType{class} \name{valuationTable-class} -\alias{baseTable,valuationTable-method} -\alias{baseYear,valuationTable-method} -\alias{getCohortTable,valuationTable-method} -\alias{getPeriodTable,valuationTable-method} -\alias{lifeTable,valuationTable-method} \alias{valuationTable} \alias{valuationTable-class} \title{Class valuationTable} -\usage{ -getOmega(object) - -ages(object, ...) - -deathProbabilities(object, ..., YOB = 1975) - -periodDeathProbabilities(object, ...) - -lifeTable(object, ...) - -\S4method{lifeTable}{valuationTable}(object, ...) - -baseYear(object, ...) - -\S4method{baseYear}{valuationTable}(object, ...) - -baseTable(object, ...) - -\S4method{baseTable}{valuationTable}(object, ...) - -getPeriodTable(object, Period, ...) - -\S4method{getPeriodTable}{valuationTable}(object, Period, ...) - -getCohortTable(object, YOB, ...) - -\S4method{getCohortTable}{valuationTable}(object, YOB, ...) -} -\arguments{ -\item{...}{Parameters to be handed to the \code{deathProbabilities} method of the life table} - -\item{YOB}{The birth year for which the death probabilities should be calculated} - -\item{Period}{The observation year for which the period death probabilities should be determined} - -\item{...}{Parameters to be handed to the \code{deathProbabilities} method of the life table} - -\item{Period}{The observation year, for which the death probabilities should be determined} - -\item{Period}{The observation year, for which the death probabilities should be determined} - -\item{YOB}{The birth year for which the life table should be calculated} - -\item{YOB}{The birth year for which the life table should be calculated} -} \description{ Class \code{valuationTable} is the (virtual) base class for all valuation tables. It contains the name and some general values applying to all types of tables, but does not contain any data itself. Use a child class to create actual valuation tables. - -Return the maximum age of the life table - -Return the defined ages of the life table - -Return the (cohort) death probabilities of the life table given the birth year (if needed) - -Return the (period) death probabilities of the life table for a given observation year - -Return the lifetable object (package lifecontingencies) for the cohort life table - -Return the lifetable object (package lifecontingencies) for the cohort life table - -Return the base year of the life table - -Return the base year of the life table - -Return the base table of the life table - -Return the base table of the life table - -Return the period life table as a \code{valuationTable_period} object - -Return the period life table as a \code{valuationTable_period} object - -Return the cohort life table as a \code{valuationTable_period} object - -Return the cohort life table as a \code{valuationTable_period} object } \section{Slots}{ @@ -101,6 +22,6 @@ Return the cohort life table as a \code{valuationTable_period} object to give the user a way to modify the final probabilities} \item{\code{loading}}{Additional security loading on the resulting table (single numeric -value, e.g. 0.05 adds 5% security margin to the probabilities)} +value, e.g. 0.05 adds 5\% security margin to the probabilities)} }} diff --git a/man/valuationTable.ageShift-class.Rd b/man/valuationTable.ageShift-class.Rd new file mode 100644 index 0000000..3b64aa1 --- /dev/null +++ b/man/valuationTable.ageShift-class.Rd @@ -0,0 +1,16 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/valuationTable.ageShift.R +\docType{class} +\name{valuationTable.ageShift-class} +\alias{valuationTable.ageShift} +\alias{valuationTable.ageShift-class} +\title{Class valuationTable.ageShift - Cohort life tables generated by age-shift} +\description{ +A cohort life table, obtained by age-shifting from a given base table (death probabilities +} +\section{Slots}{ + +\describe{ +\item{\code{ageShifts}}{A \code{data.frame} with columns \code{YOB} and \code{shifts} giving the age shifts for each birth year} +}} + diff --git a/man/valuationTable.improvementFactors-class.Rd b/man/valuationTable.improvementFactors-class.Rd new file mode 100644 index 0000000..a324ef2 --- /dev/null +++ b/man/valuationTable.improvementFactors-class.Rd @@ -0,0 +1,21 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/valuationTable.improvementFactors.R +\docType{class} +\name{valuationTable.improvementFactors-class} +\alias{valuationTable.improvementFactors} +\alias{valuationTable.improvementFactors-class} +\title{Class valuationTable.improvementFactors - Cohort life table with improvement +factors} +\description{ +A cohort life table, obtained by an improvment factor projection +from a given base table (PODs for a given observation year). +} +\section{Slots}{ + +\describe{ +\item{\code{baseYear}}{The base year for the improvements (\code{baseTable} +describes the death probabilities in this year)} + +\item{\code{improvement}}{Yearly improvement factors per age} +}} + diff --git a/man/valuationTable.joined-class.Rd b/man/valuationTable.joined-class.Rd new file mode 100644 index 0000000..409dc79 --- /dev/null +++ b/man/valuationTable.joined-class.Rd @@ -0,0 +1,24 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/valuationTable.joined.R +\docType{class} +\name{valuationTable.joined-class} +\alias{valuationTable.joined} +\alias{valuationTable.joined-class} +\title{Class valuationTable.joined - Life table created by joining two life tables} +\description{ +A cohort life table obtained by joining two cohort life tables, each of which +applies only to certain observation years (e.g. for the past use the observed +PoDs, and project them to the future with the trend projection) +} +\section{Slots}{ + +\describe{ +\item{\code{table1}}{The first \code{valuationTable}, valid for years given in \code{yearRange1}} + +\item{\code{yearRange1}}{The years, for which \code{table1} describes the death probabilities} + +\item{\code{table2}}{The second \code{valuationTable}, valid for years given in \code{yearRange2}} + +\item{\code{yearRange2}}{The years, for which \code{table2} describes the death probabilities} +}} + diff --git a/man/valuationTable.mixed-class.Rd b/man/valuationTable.mixed-class.Rd new file mode 100644 index 0000000..02f0791 --- /dev/null +++ b/man/valuationTable.mixed-class.Rd @@ -0,0 +1,24 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/valuationTable.mixed.R +\docType{class} +\name{valuationTable.mixed-class} +\alias{valuationTable.mixed} +\alias{valuationTable.mixed-class} +\title{Class valuationTable.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 +} +\section{Slots}{ + +\describe{ +\item{\code{table1}}{The first \code{valuationTable}} + +\item{\code{table2}}{The second \code{valuationTable}} + +\item{\code{weight1}}{The weight of the first valuation table} + +\item{\code{weight2}}{The weight of the second valuation table} + +\item{\code{loading}}{Additional security loading} +}} + diff --git a/man/valuationTable.observed-class.Rd b/man/valuationTable.observed-class.Rd new file mode 100644 index 0000000..c8b6bbe --- /dev/null +++ b/man/valuationTable.observed-class.Rd @@ -0,0 +1,21 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/valuationTable.observed.R +\docType{class} +\name{valuationTable.observed-class} +\alias{valuationTable.observed} +\alias{valuationTable.observed-class} +\title{Class valuationTable.observed - Life table from actual observations} +\description{ +A cohort life table described by actual observations (data frame of PODs +per year and age) +} +\section{Slots}{ + +\describe{ +\item{\code{data}}{The observations} + +\item{\code{years}}{The observation years} + +\item{\code{ages}}{The observation ages} +}} + diff --git a/man/valuationTable.period-class.Rd b/man/valuationTable.period-class.Rd new file mode 100644 index 0000000..5163817 --- /dev/null +++ b/man/valuationTable.period-class.Rd @@ -0,0 +1,19 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/valuationTable.period.R +\docType{class} +\name{valuationTable.period-class} +\alias{valuationTable.period} +\alias{valuationTable.period-class} +\title{Class valuationTable.period - Period life tables} +\description{ +A period life table, giving death probabilities for each age, up to +maximum age omega. Optionally apply selection factors to the probabilities +} +\section{Slots}{ + +\describe{ +\item{\code{ages}}{The ages corresponding to the entries of the deathProbs} + +\item{\code{deathProbs}}{The one-year death probabilities for the ages} +}} + diff --git a/man/valuationTable.trendProjection-class.Rd b/man/valuationTable.trendProjection-class.Rd new file mode 100644 index 0000000..f9bb6e2 --- /dev/null +++ b/man/valuationTable.trendProjection-class.Rd @@ -0,0 +1,34 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/valuationTable.trendProjection.R +\docType{class} +\name{valuationTable.trendProjection-class} +\alias{valuationTable.trendProjection} +\alias{valuationTable.trendProjection-class} +\title{Class valuationTable.trendProjection - Cohort life table with age-specific trend} +\description{ +A cohort life table, obtained by a trend projection from a given base table +(PODs for a given observation year). Typically, the trend is obtained by +the Lee-Carter method or some other trend estimation. +The dampingFunction can be used to modify the cumulative years (e.g. G(tau+x) +instead of tau+x) +If trend2 is given, the G(tau+x) gives the weight of the first trend, +1-G(tau+x) the weight of the second trend +} +\section{Slots}{ + +\describe{ +\item{\code{baseYear}}{The base year of the trend projection (\code{baseTable} +describes the death probabilities in this year)} + +\item{\code{trend}}{The yearly improvements of the log-death probabilities (per age)} + +\item{\code{dampingFunction}}{A possible damping of the trend. This is a function +\code{damping(delta_years)} that gets a vector of years +from the baseYear and should return the dampened values.} + +\item{\code{trend2}}{The alternate trend. If given, the damping function +interpolates between \code{trend} and \code{trend2}, otherwise +the dumping function simply modifies the coefficients of +\code{trend}.} +}} + diff --git a/man/valuationTable_ageShift-class.Rd b/man/valuationTable_ageShift-class.Rd deleted file mode 100644 index 6e7857a..0000000 --- a/man/valuationTable_ageShift-class.Rd +++ /dev/null @@ -1,47 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ValuationTables.R -\docType{class} -\name{valuationTable_ageShift-class} -\alias{ageShift,valuationTable_ageShift-method} -\alias{deathProbabilities,valuationTable_ageShift-method} -\alias{periodDeathProbabilities,valuationTable_ageShift-method} -\alias{valuationTable_ageShift} -\alias{valuationTable_ageShift-class} -\title{A cohort life table, obtained by age-shifting from a given base table (death probabilities} -\usage{ -ageShift(object, YOB = 1975, ...) - -\S4method{ageShift}{valuationTable_ageShift}(object, YOB = 1975, ...) - -\S4method{deathProbabilities}{valuationTable_ageShift}(object, ..., - YOB = 1975) - -\S4method{periodDeathProbabilities}{valuationTable_ageShift}(object, ..., - Period = 1975) -} -\arguments{ -\item{YOB}{The birth year for which the age shift should be determined.} - -\item{Period}{The observation year for which the period death probabilities should be determined} - -\item{YOB}{The birth year for which the age shift should be determined.} - -\item{YOB}{The birth year for which the death probabilities should be calculated} -} -\description{ -A cohort life table, obtained by age-shifting from a given base table (death probabilities - -Return the age shift of the age-shifted life table given the birth year - -Return the age shift of the age-shifted life table given the birth year - -Return the (cohort) death probabilities of the life table given the birth year (if needed) - -Return the (period) death probabilities of the life table for a given observation year -} -\section{Slots}{ - -\describe{ -\item{\code{ageShifts}}{A \code{data.frame} with columns \code{YOB} and \code{shifts} giving the age shifts for each birth year} -}} - diff --git a/man/valuationTable_improvementFactors-class.Rd b/man/valuationTable_improvementFactors-class.Rd deleted file mode 100644 index 6dd7d59..0000000 --- a/man/valuationTable_improvementFactors-class.Rd +++ /dev/null @@ -1,38 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ValuationTables.R -\docType{class} -\name{valuationTable_improvementFactors-class} -\alias{deathProbabilities,valuationTable_improvementFactors-method} -\alias{periodDeathProbabilities,valuationTable_improvementFactors-method} -\alias{valuationTable_improvementFactors} -\alias{valuationTable_improvementFactors-class} -\title{A cohort life table, obtained by an improvment factor projection -from a given base table (PODs for a given observation year).} -\usage{ -\S4method{deathProbabilities}{valuationTable_improvementFactors}(object, ..., - YOB = 1975) - -\S4method{periodDeathProbabilities}{valuationTable_improvementFactors}(object, - ..., Period = 1975) -} -\arguments{ -\item{YOB}{The birth year for which the death probabilities should be calculated} - -\item{Period}{The observation year for which the period death probabilities should be determined} -} -\description{ -A cohort life table, obtained by an improvment factor projection -from a given base table (PODs for a given observation year). - -Return the (cohort) death probabilities of the life table given the birth year (if needed) - -Return the (period) death probabilities of the life table for a given observation year -} -\section{Slots}{ - -\describe{ -\item{\code{baseYear}}{The base year for the improvements (\code{baseTable} describes the death probabilities in this year)} - -\item{\code{improvement}}{Yearly improvement factors per age} -}} - diff --git a/man/valuationTable_joined-class.Rd b/man/valuationTable_joined-class.Rd deleted file mode 100644 index ccfc977..0000000 --- a/man/valuationTable_joined-class.Rd +++ /dev/null @@ -1,37 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ValuationTables.R -\docType{class} -\name{valuationTable_joined-class} -\alias{ages,valuationTable_joined-method} -\alias{getOmega,valuationTable_joined-method} -\alias{valuationTable_joined} -\alias{valuationTable_joined-class} -\title{A cohort life table obtained by joining two cohort life tables, each of which -applies only to certain observation years (e.g. for the past use the observed -PODs, and project them to the future with the trend projection)} -\usage{ -\S4method{getOmega}{valuationTable_joined}(object) - -\S4method{ages}{valuationTable_joined}(object, ...) -} -\description{ -A cohort life table obtained by joining two cohort life tables, each of which -applies only to certain observation years (e.g. for the past use the observed -PODs, and project them to the future with the trend projection) - -Return the maximum age of the joined life table - -Return the defined ages of the life table -} -\section{Slots}{ - -\describe{ -\item{\code{table1}}{The first \code{valuationTable}, valid for years given in \code{yearRange1}} - -\item{\code{yearRange1}}{The years, for which \code{table1} describes the death probabilities} - -\item{\code{table2}}{The second \code{valuationTable}, valid for years given in \code{yearRange2}} - -\item{\code{yearRange2}}{The years, for which \code{table2} describes the death probabilities} -}} - diff --git a/man/valuationTable_mixed-class.Rd b/man/valuationTable_mixed-class.Rd deleted file mode 100644 index 208f3bb..0000000 --- a/man/valuationTable_mixed-class.Rd +++ /dev/null @@ -1,56 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ValuationTables.R -\docType{class} -\name{valuationTable_mixed-class} -\alias{ages,valuationTable_mixed-method} -\alias{baseYear,valuationTable_mixed-method} -\alias{deathProbabilities,valuationTable_mixed-method} -\alias{getOmega,valuationTable_mixed-method} -\alias{periodDeathProbabilities,valuationTable_mixed-method} -\alias{valuationTable_mixed} -\alias{valuationTable_mixed-class} -\title{A cohort life table obtained by mixing two life tables with the given weights} -\usage{ -\S4method{getOmega}{valuationTable_mixed}(object) - -\S4method{ages}{valuationTable_mixed}(object, ...) - -\S4method{deathProbabilities}{valuationTable_mixed}(object, ..., YOB = 1975) - -\S4method{periodDeathProbabilities}{valuationTable_mixed}(object, ..., - Period = 1975) - -\S4method{baseYear}{valuationTable_mixed}(object, ...) -} -\arguments{ -\item{YOB}{The birth year for which the death probabilities should be calculated} - -\item{Period}{The observation year for which the period death probabilities should be determined} -} -\description{ -A cohort life table obtained by mixing two life tables with the given weights - -Return the maximum age of the mixed life table - -Return the defined ages of the life table - -Return the (cohort) death probabilities of the life table given the birth year (if needed) - -Return the (period) death probabilities of the life table for a given observation year - -Return the base year of the life table -} -\section{Slots}{ - -\describe{ -\item{\code{table1}}{The first \code{valuationTable}} - -\item{\code{table2}}{The second \code{valuationTable}} - -\item{\code{weight1}}{The weight of the first valuation table} - -\item{\code{weight2}}{The weight of the second valuation table} - -\item{\code{loading}}{Additional security loading} -}} - diff --git a/man/valuationTable_observed-class.Rd b/man/valuationTable_observed-class.Rd deleted file mode 100644 index 14b5261..0000000 --- a/man/valuationTable_observed-class.Rd +++ /dev/null @@ -1,18 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ValuationTables.R -\docType{class} -\name{valuationTable_observed-class} -\alias{valuationTable_observed} -\alias{valuationTable_observed-class} -\title{A cohort life table described by actual observations (data frame of PODs -per year and age)} -\description{ -A cohort life table described by actual observations (data frame of PODs -per year and age) -} -\section{Slots}{ - -\describe{ -\item{\code{data}}{The observations} -}} - diff --git a/man/valuationTable_period-class.Rd b/man/valuationTable_period-class.Rd deleted file mode 100644 index 401788b..0000000 --- a/man/valuationTable_period-class.Rd +++ /dev/null @@ -1,51 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ValuationTables.R -\docType{class} -\name{valuationTable_period-class} -\alias{ages,valuationTable_period-method} -\alias{baseTable,valuationTable_period-method} -\alias{deathProbabilities,valuationTable_period-method} -\alias{getOmega,valuationTable_period-method} -\alias{periodDeathProbabilities,valuationTable_period-method} -\alias{valuationTable_period} -\alias{valuationTable_period-class} -\title{A period life table, giving death probabilities for each age, up to -maximum age omega. Optionally apply selection factors to the probabilities} -\usage{ -\S4method{getOmega}{valuationTable_period}(object) - -\S4method{ages}{valuationTable_period}(object, ...) - -\S4method{deathProbabilities}{valuationTable_period}(object, ..., YOB = 1975) - -\S4method{periodDeathProbabilities}{valuationTable_period}(object, ...) - -\S4method{baseTable}{valuationTable_period}(object, ...) -} -\arguments{ -\item{YOB}{The birth year for which the death probabilities should be calculated} - -\item{Period}{The observation year for which the period death probabilities should be determined} -} -\description{ -A period life table, giving death probabilities for each age, up to -maximum age omega. Optionally apply selection factors to the probabilities - -Return the maximum age of the period life table - -Return the defined ages of the life table - -Return the (cohort) death probabilities of the life table given the birth year (if needed) - -Return the (period) death probabilities of the life table for a given observation year - -Return the base table of the life table -} -\section{Slots}{ - -\describe{ -\item{\code{ages}}{The ages corresponding to the entries of the deathProbs} - -\item{\code{deathProbs}}{The one-year death probabilities for the ages} -}} - -- GitLab