Commit e8bc0981 authored by Reinhold Kainhofer's avatar Reinhold Kainhofer

Add analytic mortality distributions

- mortalityTable.deMoivre(omega)
- mortalityTable.MakehamGompertz(A, B, c)
- mortalityTable.Weibull(k, n)
parent 17570bef
......@@ -44,6 +44,9 @@ Collate:
'makeQxDataFrame.R'
'mortalityComparisonTable.R'
'mortalityImprovement.R'
'mortalityTable.MakehamGompertz.R'
'mortalityTable.Weibull.R'
'mortalityTable.deMoivre.R'
'periodDeathProbabilities.R'
'mortalityTable.jointLives.R'
'mortalityTables.list.R'
......
......@@ -6,7 +6,10 @@ export(generateAgeShift)
export(makeQxDataFrame)
export(mortalityComparisonTable)
export(mortalityTable)
export(mortalityTable.MakehamGompertz)
export(mortalityTable.Weibull)
export(mortalityTable.ageShift)
export(mortalityTable.deMoivre)
export(mortalityTable.improvementFactors)
export(mortalityTable.joined)
export(mortalityTable.jointLives)
......@@ -26,7 +29,10 @@ export(plotMortalityTableComparisons)
export(plotMortalityTables)
export(plotMortalityTrend)
exportClasses(mortalityTable)
exportClasses(mortalityTable.MakehamGompertz)
exportClasses(mortalityTable.Weibull)
exportClasses(mortalityTable.ageShift)
exportClasses(mortalityTable.deMoivre)
exportClasses(mortalityTable.improvementFactors)
exportClasses(mortalityTable.joined)
exportClasses(mortalityTable.jointLives)
......
#' @include mortalityTable.period.R
NULL
#' Class mortalityTable.MakehamGompertz - Mortality table with Makeham-Gompertz's law
#'
#' A period life table following Makeham and Gompertz's law of a mortality rate
#' $\mu$ increasing exponentially with age $x$ ($\mu_{x+t} = A + B c^{(x+t)}$).
#' The only required slots are the parameters $A$, $B$ and $c$, all probabilities
#' are calculated from them, for technical reasons a maximum age of 120 is
#' technically assumed. Optionally, a name and loading can be passed
#' (inherited from \code{\link{mortalityTable}}).
#'
#' @slot A Parameter A of the Makeham-Gompertz distribution
#' @slot B Parameter B of the Makeham-Gompertz distribution
#' @slot c Parameter c of the Makeham-Gompertz distribution
#' @slot omega Maximum age (default: 150)
#'
#' @examples
#' # A Gompertz mortality, roughtly approximating the Austrian annuitants 2017
#' gmp = mortalityTable.MakehamGompertz(A = 0, B = 0.00001, c = 1.11)
#' mortalityTables.load("Austria_Annuities_AVOe2005R")
#' plot(gmp, AVOe2005R.male, Period=2017)
#'
#' # A Makeham-Gompertz mortality, approximating the Austrian annuitants 2017
#' mg = mortalityTable.MakehamGompertz(A = 0.0002, B = 0.00001, c = 1.11)
#' plot(mg, gmp, AVOe2005R.male, Period=2017)
#'
#' @export mortalityTable.MakehamGompertz
#' @exportClass mortalityTable.MakehamGompertz
mortalityTable.MakehamGompertz = setClass(
"mortalityTable.MakehamGompertz",
slots = list(
A = "numeric",
B = "numeric",
c = "numeric",
omega = "numeric"
),
prototype = list(
A = 0,
B = 1,
c = 1,
omega = 120
),
contains = "mortalityTable.period"
)
setMethod("initialize", "mortalityTable.MakehamGompertz", function(.Object, A = 0, B = 1, c = 1, omega = 120, name = NULL, ...) {
if (missing(name) || is.null(name)) {
if (A == 0) {
name = paste("Gompertz mortality, B=", B, ", c=", c, collapse = "")
} else if (B == 0 || c == 1) {
name = paste("Exponential mortality, mu=", A + B * c, collapse = "")
} else {
name = paste("Makeham-Gompertz mortality, A=", A, ", B=", B, ", c=", c, collapse = "")
}
}
ages = 0:omega
if (c == 1 || B == 0) {
deathProbs = 1 - exp(-A)
} else {
deathProbs = 1 - exp(-A) * exp(B/log(c) * (c^ages - c^(ages + 1)))
}
callNextMethod(.Object, A = A, B = B, c = c, omega = omega, name = name, ages = ages, deathProbs = deathProbs, ...)
})
#' @include mortalityTable.period.R
NULL
#' Class mortalityTable.Weibull - Mortality table with Weibull's law
#'
#' A period life table following Weibulls's law of a mortality rate
#' $\mu$ increasing as a power of $t$ ($\mu_{x+t} = k * (x+t)^n$).
#' The only required slots are the parameters $k>0$ and $n>0$, all probabilities
#' are calculated from them, for technical reasons a maximum age of 150 is
#' technically assumed. Optionally, a name and loading can be passed
#' (inherited from \code{\link{mortalityTable}}).
#'
#' @slot k Parameter k of the Weibull distribution
#' @slot n Parameter n of the Weibull distribution
#' @slot omega Maximum age (default: 120)
#'
#' @examples
#' # A Weibull mortality
#' wbl = mortalityTable.Weibull(k = 0.0000000001, n = 4.8)
#' mortalityTables.load("Austria_Annuities_AVOe2005R")
#' plot(wbl, AVOe2005R.male, Period=2017, ylim = c(0.00005, 1))
#'
#' @export mortalityTable.Weibull
#' @exportClass mortalityTable.Weibull
mortalityTable.Weibull = setClass(
"mortalityTable.Weibull",
slots = list(
k = "numeric",
n = "numeric",
omega = "numeric"
),
prototype = list(
k = 0.005,
n = 5,
omega = 120
),
contains = "mortalityTable.period"
)
setMethod("initialize", "mortalityTable.Weibull", function(.Object, k = 1, n = 1, omega = 120, name = NULL, ...) {
if (missing(name) || is.null(name)) {
name = paste("Weibull mortality, k=", k, ", n=", n, collapse = "")
}
ages = 0:omega
deathProbs = 1 - exp(-k / (n + 1) * ((ages + 1)^(n + 1) - ages^(n + 1)))
callNextMethod(.Object, k = k, n = n, omega = omega, name = name, ages = ages, deathProbs = deathProbs, ...)
})
#' @include mortalityTable.period.R
NULL
#' Class mortalityTable.deMoivre - Mortality table with de Moivre's law
#'
#' A period life table with maximum age omega dn the time of death identically
#' distributed on the interval [0, omega]. The only required slot is the maximum
#' age \code{omega}, all probabilities are calculated from it.
#' Optionally, a name and loading can be passed (inherited from
#' \code{\link{mortalityTable}}).
#'
#' @slot omega Maximum age
#'
#' @examples
#' mm = mortalityTable.deMoivre(100)
#' plot(mm,
#' mortalityTable.deMoivre(90),
#' mortalityTable.deMoivre(50))
#'
#' @export mortalityTable.deMoivre
#' @exportClass mortalityTable.deMoivre
mortalityTable.deMoivre = setClass(
"mortalityTable.deMoivre",
slots = list(
omega = "numeric"
),
prototype = list(
omega = 100
),
contains = "mortalityTable.period"
)
setMethod("initialize", "mortalityTable.deMoivre", function(.Object, omega = 100, name = NULL, ...) {
if (missing(name) || is.null(name)) {
name = paste("de Moivre mortality, omega=", omega)
}
callNextMethod(.Object, omega = omega, name = name, ages = 0:omega, deathProbs = c(1 / (omega - 0:(omega - 1)), 1), ...)
})
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/mortalityTable.MakehamGompertz.R
\docType{class}
\name{mortalityTable.MakehamGompertz-class}
\alias{mortalityTable.MakehamGompertz-class}
\alias{mortalityTable.MakehamGompertz}
\title{Class mortalityTable.MakehamGompertz - Mortality table with Makeham-Gompertz's law}
\description{
A period life table following Makeham and Gompertz's law of a mortality rate
$\mu$ increasing exponentially with age $x$ ($\mu_{x+t} = A + B c^{(x+t)}$).
The only required slots are the parameters $A$, $B$ and $c$, all probabilities
are calculated from them, for technical reasons a maximum age of 120 is
technically assumed. Optionally, a name and loading can be passed
(inherited from \code{\link{mortalityTable}}).
}
\section{Slots}{
\describe{
\item{\code{A}}{Parameter A of the Makeham-Gompertz distribution}
\item{\code{B}}{Parameter B of the Makeham-Gompertz distribution}
\item{\code{c}}{Parameter c of the Makeham-Gompertz distribution}
\item{\code{omega}}{Maximum age (default: 150)}
}}
\examples{
# A Gompertz mortality, roughtly approximating the Austrian annuitants 2017
gmp = mortalityTable.MakehamGompertz(A = 0, B = 0.00001, c = 1.11)
mortalityTables.load("Austria_Annuities_AVOe2005R")
plot(gmp, AVOe2005R.male, Period=2017)
# A Makeham-Gompertz mortality, approximating the Austrian annuitants 2017
mg = mortalityTable.MakehamGompertz(A = 0.0002, B = 0.00001, c = 1.11)
plot(mg, gmp, AVOe2005R.male, Period=2017)
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/mortalityTable.Weibull.R
\docType{class}
\name{mortalityTable.Weibull-class}
\alias{mortalityTable.Weibull-class}
\alias{mortalityTable.Weibull}
\title{Class mortalityTable.Weibull - Mortality table with Weibull's law}
\description{
A period life table following Weibulls's law of a mortality rate
$\mu$ increasing as a power of $t$ ($\mu_{x+t} = k * (x+t)^n$).
The only required slots are the parameters $k>0$ and $n>0$, all probabilities
are calculated from them, for technical reasons a maximum age of 150 is
technically assumed. Optionally, a name and loading can be passed
(inherited from \code{\link{mortalityTable}}).
}
\section{Slots}{
\describe{
\item{\code{k}}{Parameter k of the Weibull distribution}
\item{\code{n}}{Parameter n of the Weibull distribution}
\item{\code{omega}}{Maximum age (default: 120)}
}}
\examples{
# A Weibull mortality
wbl = mortalityTable.Weibull(k = 0.0000000001, n = 4.8)
mortalityTables.load("Austria_Annuities_AVOe2005R")
plot(wbl, AVOe2005R.male, Period=2017, ylim = c(0.00005, 1))
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/mortalityTable.deMoivre.R
\docType{class}
\name{mortalityTable.deMoivre-class}
\alias{mortalityTable.deMoivre-class}
\alias{mortalityTable.deMoivre}
\title{Class mortalityTable.deMoivre - Mortality table with de Moivre's law}
\description{
A period life table with maximum age omega dn the time of death identically
distributed on the interval [0, omega]. The only required slot is the maximum
age \code{omega}, all probabilities are calculated from it.
Optionally, a name and loading can be passed (inherited from
\code{\link{mortalityTable}}).
}
\section{Slots}{
\describe{
\item{\code{omega}}{Maximum age}
}}
\examples{
mm = mortalityTable.deMoivre(100)
plot(mm,
mortalityTable.deMoivre(90),
mortalityTable.deMoivre(50))
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment