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

Style fixes

parent 6b355894
Branches
Tags
No related merge requests found
...@@ -20,13 +20,13 @@ setMethod("deathProbabilities", "mortalityTable.period", ...@@ -20,13 +20,13 @@ setMethod("deathProbabilities", "mortalityTable.period",
#' @describeIn deathProbabilities Return the (cohort) death probabilities of the #' @describeIn deathProbabilities Return the (cohort) death probabilities of the
#' life table given the birth year (if needed) #' life table given the birth year (if needed)
setMethod("deathProbabilities","mortalityTable.ageShift", setMethod("deathProbabilities","mortalityTable.ageShift",
function (object, ..., YOB = 1975) { function(object, ..., YOB = 1975) {
qx=object@deathProbs * (1 + object@loading); qx = object@deathProbs * (1 + object@loading);
shift = ageShift(object, YOB); shift = ageShift(object, YOB);
if (shift>0) { if (shift > 0) {
qx = c(qx[(shift+1):length(qx)], rep(qx[length(qx)], shift)); qx = c(qx[(shift + 1):length(qx)], rep(qx[length(qx)], shift));
} else if (shift<0) { } else if (shift < 0) {
qx = c(rep(0, -shift), qx[1:(length(qx)-(-shift))]) qx = c(rep(0, -shift), qx[1:(length(qx) - (-shift))])
} }
object@modification(qx) object@modification(qx)
}) })
...@@ -34,23 +34,23 @@ setMethod("deathProbabilities","mortalityTable.ageShift", ...@@ -34,23 +34,23 @@ setMethod("deathProbabilities","mortalityTable.ageShift",
#' @describeIn deathProbabilities Return the (cohort) death probabilities of the #' @describeIn deathProbabilities Return the (cohort) death probabilities of the
#' life table given the birth year (if needed) #' life table given the birth year (if needed)
setMethod("deathProbabilities","mortalityTable.trendProjection", setMethod("deathProbabilities","mortalityTable.trendProjection",
function (object, ..., YOB = 1975) { function(object, ..., YOB = 1975) {
qx=object@deathProbs * (1 + object@loading); qx = object@deathProbs * (1 + object@loading);
if (is.null(object@trend2) || length(object@trend2) <= 1) { if (is.null(object@trend2) || length(object@trend2) <= 1) {
ages = object@ages; ages = object@ages;
damping = sapply( damping = sapply(
ages, ages,
function (age) { object@dampingFunction(YOB + age - object@baseYear) } function(age) { object@dampingFunction(YOB + age - object@baseYear) }
); );
finalqx = exp(-object@trend * damping) * qx; finalqx = exp(-object@trend * damping) * qx;
} else { } else {
# dampingFunction interpolates between the two trends: # dampingFunction interpolates between the two trends:
# The damping functions does NOT give yearly weights, # The damping functions does NOT give yearly weights,
# but rather cumulative weights from the base year until the observation year! # but rather cumulative weights from the base year until the observation year!
weights = sapply(YOB + 0:(length(qx)-1), object@dampingFunction); weights = sapply(YOB + 0:(length(qx) - 1), object@dampingFunction);
finalqx = qx * exp( finalqx = qx * exp(
-(object@trend * (1 - weights) + object@trend2 * weights) * -(object@trend * (1 - weights) + object@trend2 * weights) *
(YOB + 0:(length(qx)-1) - object@baseYear)) (YOB + 0:(length(qx) - 1) - object@baseYear))
} }
object@modification(finalqx) object@modification(finalqx)
}) })
...@@ -58,7 +58,7 @@ setMethod("deathProbabilities","mortalityTable.trendProjection", ...@@ -58,7 +58,7 @@ setMethod("deathProbabilities","mortalityTable.trendProjection",
#' @describeIn deathProbabilities Return the (cohort) death probabilities of the #' @describeIn deathProbabilities Return the (cohort) death probabilities of the
#' life table given the birth year (if needed) #' life table given the birth year (if needed)
setMethod("deathProbabilities","mortalityTable.improvementFactors", setMethod("deathProbabilities","mortalityTable.improvementFactors",
function (object, ..., YOB = 1975) { function(object, ..., YOB = 1975) {
qx = object@deathProbs * (1 + object@loading); qx = object@deathProbs * (1 + object@loading);
finalqx = (1 - object@improvement)^(YOB + 0:(length(qx) - 1) - object@baseYear) * qx; finalqx = (1 - object@improvement)^(YOB + 0:(length(qx) - 1) - object@baseYear) * qx;
object@modification(finalqx) object@modification(finalqx)
...@@ -67,7 +67,7 @@ setMethod("deathProbabilities","mortalityTable.improvementFactors", ...@@ -67,7 +67,7 @@ setMethod("deathProbabilities","mortalityTable.improvementFactors",
#' @describeIn deathProbabilities Return the (cohort) death probabilities of the #' @describeIn deathProbabilities Return the (cohort) death probabilities of the
#' life table given the birth year (if needed) #' life table given the birth year (if needed)
setMethod("deathProbabilities","mortalityTable.mixed", setMethod("deathProbabilities","mortalityTable.mixed",
function (object, ..., YOB = 1975) { function(object, ..., YOB = 1975) {
qx1 = deathProbabilities(object@table1, ..., YOB); qx1 = deathProbabilities(object@table1, ..., YOB);
qx2 = deathProbabilities(object@table2, ..., YOB); qx2 = deathProbabilities(object@table2, ..., YOB);
mixedqx = (object@weight1 * qx1 + object@weight2 * qx2)/(object@weight1 + object@weight2) * (1 + object@loading); mixedqx = (object@weight1 * qx1 + object@weight2 * qx2)/(object@weight1 + object@weight2) * (1 + object@loading);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment