mortalityTable.period.R 2.36 KB
Newer Older
1
#' @include mortalityTable.R
2 3
NULL

4 5 6
setClassUnion("numericOrNULL", c("numeric", "NULL"))


7
#' Class mortalityTable.period - Period life tables
8 9
#'
#' A period life table, giving death probabilities for each age, up to
Reinhold Kainhofer's avatar
Reinhold Kainhofer committed
10 11
#' maximum age \code{omega}. The \code{baseYear} slot can be used to hold
#' information about the period.
12 13 14
#'
#' @slot ages       The ages corresponding to the entries of the deathProbs
#' @slot deathProbs The one-year death probabilities for the ages
15 16
#' @slot exposures  (Optional) exposured used to determine death probabilities
#'                  (can be used as weights for smoothing, for variances, etc.)
17
#'
18 19 20 21
#' @export mortalityTable.period
#' @exportClass mortalityTable.period
mortalityTable.period = setClass(
    "mortalityTable.period",
22 23
    slots = list(
        ages = "numeric",
24
        deathProbs = "numeric",
25
        exposures = "numericOrNULL"
26 27 28
    ),
    prototype = list(
        ages = eval(0:120),
29 30
        deathProbs = rep(1,120),
        exposures = NULL
31
    ),
32
    contains = "mortalityTable"
33
)
34 35 36 37 38 39 40 41 42 43 44 45 46

#' Generate a mortality table with all probabilities set to zero.
#'
#' @param name The name of the table
#' @param ages The ages of the table
#'
#' @export
mortalityTable.zeroes = function(name = "Zero mortality table", ages = 0:99) {
    mortalityTable.period(name = name, ages = ages, deathProbs = ages * 0)
}

#' Generate a (deterministic) mortality table with only one probability set to 1 (for the given age)
#'
47
#' @param transitionAge The age where the deterministic transition occurs
48 49 50 51 52 53 54 55 56 57 58 59
#' @param name The name of the table
#' @param ages The ages of the table
#'
#' @export
mortalityTable.once = function(transitionAge, name = "Deterministic mortality table", ages = 0:99) {
    mortalityTable.period(
        name = name,
        ages = ages,
        deathProbs = sapply(ages, function(x) { if (x == transitionAge) 1 else 0})
    )
}

60 61 62 63 64 65 66 67 68 69 70 71 72 73
#' Generate a (deterministic) mortality table with all probabilities starting at a given age set to 1
#'
#' @param transitionAge The age where the deterministic transition occurs
#' @param name The name of the table
#' @param ages The ages of the table
#'
#' @export
mortalityTable.onceAndFuture = function(transitionAge, name = "Deterministic mortality table", ages = 0:99) {
    mortalityTable.period(
        name = name,
        ages = ages,
        deathProbs = sapply(ages, function(x) { if (x >= transitionAge) 1 else 0})
    )
}
74