Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
R - Mortality Tables
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
R
R - Mortality Tables
Commits
e1b39386
Commit
e1b39386
authored
3 years ago
by
Reinhold Kainhofer
Browse files
Options
Downloads
Patches
Plain Diff
Vignette: Name all chunks to improve performance
parent
b7e38769
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
vignettes/using-the-mortalityTables-package.Rmd
+13
-13
13 additions, 13 deletions
vignettes/using-the-mortalityTables-package.Rmd
vignettes/using-the-mortalityTables-package.html
+536
-396
536 additions, 396 deletions
vignettes/using-the-mortalityTables-package.html
with
549 additions
and
409 deletions
vignettes/using-the-mortalityTables-package.Rmd
+
13
−
13
View file @
e1b39386
...
@@ -80,7 +80,7 @@ Provided types of mortality tables are:
...
@@ -80,7 +80,7 @@ Provided types of mortality tables are:
retirement and death, with a possible widow in the event of death).
retirement and death, with a possible widow in the event of death).
# Loading the MortalityTables package
# Loading the MortalityTables package
```{r message=FALSE}
```{r
library,
message=FALSE}
library("MortalityTables")
library("MortalityTables")
```
```
...
@@ -93,7 +93,7 @@ or all datasets that match the given pattern (wildcard character is *). You can
...
@@ -93,7 +93,7 @@ or all datasets that match the given pattern (wildcard character is *). You can
then use `mortalityTables.load` to load either one single data set or all
then use `mortalityTables.load` to load either one single data set or all
datasets that match the pattern.
datasets that match the pattern.
```{r}
```{r
DataSets
}
# list all available data sets
# list all available data sets
mortalityTables.list()
mortalityTables.list()
...
@@ -132,7 +132,7 @@ mortalityTable class, so you can usually just call plot on the mortality tables.
...
@@ -132,7 +132,7 @@ mortalityTable class, so you can usually just call plot on the mortality tables.
If the `trend = TRUE` argument is given, `plotMortalityTrend` is used,
If the `trend = TRUE` argument is given, `plotMortalityTrend` is used,
if the `reference` argument is given, `plotMortalityTableComparisons` is used,
if the `reference` argument is given, `plotMortalityTableComparisons` is used,
otherwise `plotMortalityTables` is called.
otherwise `plotMortalityTables` is called.
```{r}
```{r
PlottingLogLinear
}
# Log-linear plot comparing some Austrian census tables
# Log-linear plot comparing some Austrian census tables
plot(mort.AT.census.1951.male, mort.AT.census.1991.male,
plot(mort.AT.census.1951.male, mort.AT.census.1991.male,
mort.AT.census.2001.male, mort.AT.census.2011.male,
mort.AT.census.2001.male, mort.AT.census.2011.male,
...
@@ -148,7 +148,7 @@ For cohort life tables, the plot functions also take either the `YOB` or the
...
@@ -148,7 +148,7 @@ For cohort life tables, the plot functions also take either the `YOB` or the
`Period` parameter to plot either the cohort death probabilities for the given
`Period` parameter to plot either the cohort death probabilities for the given
birth year or the period death probabilities for the given observation year.
birth year or the period death probabilities for the given observation year.
```{r}
```{r
PlottingCohort
}
# Comparison of two Austrian annuity tables for birth year 1977
# Comparison of two Austrian annuity tables for birth year 1977
plot(AVOe1996R.male, AVOe2005R.male, YOB = 1977, title = "Comparison for YOB=1977")
plot(AVOe1996R.male, AVOe2005R.male, YOB = 1977, title = "Comparison for YOB=1977")
...
@@ -165,7 +165,7 @@ To obtain death probabilities from all the different types of tables, there are
...
@@ -165,7 +165,7 @@ To obtain death probabilities from all the different types of tables, there are
* `periodDeathProbabilities`: Returns the (period) death probabilities of the life table for a given
* `periodDeathProbabilities`: Returns the (period) death probabilities of the life table for a given
observation year
observation year
```{r message=FALSE}
```{r
Probabilities,
message=FALSE}
mortalityTables.load("Austria_Annuities")
mortalityTables.load("Austria_Annuities")
# Get the cohort death probabilities for Austrian Annuitants born in 1977:
# Get the cohort death probabilities for Austrian Annuitants born in 1977:
qx.coh1977 = deathProbabilities(AVOe2005R.male, YOB = 1977)
qx.coh1977 = deathProbabilities(AVOe2005R.male, YOB = 1977)
...
@@ -181,7 +181,7 @@ There are two similar functions that return the death probabilities as a period
...
@@ -181,7 +181,7 @@ There are two similar functions that return the death probabilities as a period
* `getCohortTable`: Get a `mortalityTable` object describing the death probabilities for people born in the given year
* `getCohortTable`: Get a `mortalityTable` object describing the death probabilities for people born in the given year
* `getPeriodTable`: Get a `mortalityTable` object describing the death probabilities observed in the given year
* `getPeriodTable`: Get a `mortalityTable` object describing the death probabilities observed in the given year
```{r}
```{r
getTables
}
# Get the cohort death probabilities for Austrian Annuitants born in 1977 as a mortalityTable.period object:
# Get the cohort death probabilities for Austrian Annuitants born in 1977 as a mortalityTable.period object:
table.coh1977 = getCohortTable(AVOe2005R.male, YOB = 1977)
table.coh1977 = getCohortTable(AVOe2005R.male, YOB = 1977)
...
@@ -226,7 +226,7 @@ factor variable in a ggplot):
...
@@ -226,7 +226,7 @@ factor variable in a ggplot):
```{r DimensionalInfoPlot}
```{r DimensionalInfoPlot}
plotMortalityTables(
plotMortalityTables(
mort.AT.census[c("m", "w"), c("1951", "199
1
", "200
1
", "201
1
")]) +
mort.AT.census[c("m", "w"), c("19
49/
51", "199
0/92
", "200
0/02
", "201
0/12
")]) +
aes(color = as.factor(year), linetype = sex) + labs(color = "Period", linetype = "Sex")
aes(color = as.factor(year), linetype = sex) + labs(color = "Period", linetype = "Sex")
```
```
...
@@ -265,7 +265,7 @@ corresponding year (the "period"). The death probabilities of different ages
...
@@ -265,7 +265,7 @@ corresponding year (the "period"). The death probabilities of different ages
refer to different persons, being of the corresponding ages in the observation
refer to different persons, being of the corresponding ages in the observation
year. All that is needed to create a period life table are the death probabilities
year. All that is needed to create a period life table are the death probabilities
and the corresponding ages:
and the corresponding ages:
```{r}
```{r
PeriodLifeTables
}
lt = mortalityTable.period(name = "Sample period lifetable", ages = 1:99, deathProbs = exp(-(99:1)/10))
lt = mortalityTable.period(name = "Sample period lifetable", ages = 1:99, deathProbs = exp(-(99:1)/10))
plot(lt, title = "Simple log-linear period mortality table")
plot(lt, title = "Simple log-linear period mortality table")
deathProbabilities(lt)
deathProbabilities(lt)
...
@@ -288,7 +288,7 @@ A cohort life table with trend projection needs the following parameters:
...
@@ -288,7 +288,7 @@ A cohort life table with trend projection needs the following parameters:
* The base year (numeric)
* The base year (numeric)
*
*
```{r}
```{r
CohortLifeTablesTrendProjection
}
atPlus2 = mortalityTable.trendProjection(
atPlus2 = mortalityTable.trendProjection(
name = "Austrian Census Males 2011, 2% yearly trend",
name = "Austrian Census Males 2011, 2% yearly trend",
baseYear = 2011,
baseYear = 2011,
...
@@ -313,7 +313,7 @@ the observation year.
...
@@ -313,7 +313,7 @@ the observation year.
To implement this trend reduction with the MortalityTables package, simply pass
To implement this trend reduction with the MortalityTables package, simply pass
a one-argument function as the `dampingFunction` slot to the class, the argument
a one-argument function as the `dampingFunction` slot to the class, the argument
will be the number of years from the base year (NOT the calendar year!):
will be the number of years from the base year (NOT the calendar year!):
```{r}
```{r
CohortLifeTableTrendDamping
}
atPlus2.damp = mortalityTable.trendProjection(
atPlus2.damp = mortalityTable.trendProjection(
name = "Austrian M '11, 2% yearly, damping until 2111",
name = "Austrian M '11, 2% yearly, damping until 2111",
baseYear = 2011,
baseYear = 2011,
...
@@ -338,7 +338,7 @@ need to be cumulated and normalized.
...
@@ -338,7 +338,7 @@ need to be cumulated and normalized.
The argument
The argument
in this case is the actual calendar year (not the year since the base year like it was in the one-trend case above!)
in this case is the actual calendar year (not the year since the base year like it was in the one-trend case above!)
```{r}
```{r
CohortLifeTableTrendSwitch
}
atPlus2.damp2 = mortalityTable.trendProjection(
atPlus2.damp2 = mortalityTable.trendProjection(
name = "Austrian M '11, 2% yearly, 1% long-term",
name = "Austrian M '11, 2% yearly, 1% long-term",
baseYear = 2011,
baseYear = 2011,
...
@@ -384,7 +384,7 @@ table for YOB 2011. A full trend projection moves the curve down to the green li
...
@@ -384,7 +384,7 @@ table for YOB 2011. A full trend projection moves the curve down to the green li
while age-shifting moves the base curve to the right so that it coincides as
while age-shifting moves the base curve to the right so that it coincides as
much as possible with the exact (green) line.
much as possible with the exact (green) line.
```{r}
```{r
CohortLifeTableAgeShirt
}
baseTableShift = getCohortTable(atPlus2, YOB = 2011);
baseTableShift = getCohortTable(atPlus2, YOB = 2011);
baseTableShift@name = "Base table of the shift (YOB 2011)"
baseTableShift@name = "Base table of the shift (YOB 2011)"
...
@@ -657,7 +657,7 @@ Let us first apply the male trend to the observed period life table of the year
...
@@ -657,7 +657,7 @@ Let us first apply the male trend to the observed period life table of the year
```{r AustrianPopulationTableTrend}
```{r AustrianPopulationTableTrend}
PopulationTable.AT2017.trend = PopulationTable.AT2017.ex %>%
PopulationTable.AT2017.trend = PopulationTable.AT2017.ex %>%
mT.addTrend(mort.AT.forecast$m@trend, trendages = ages(mort.AT.forecast$m)) %>%
mT.addTrend(mort.AT.forecast
.trend
$m@trend, trendages = ages(mort.AT.forecast
.trend
$m)) %>%
mT.setDimInfo(type = "smoothed, extrapolated, trend")
mT.setDimInfo(type = "smoothed, extrapolated, trend")
PopulationTable.AT2017.trend.ex = PopulationTable.AT2017.trend %>%
PopulationTable.AT2017.trend.ex = PopulationTable.AT2017.trend %>%
...
...
This diff is collapsed.
Click to expand it.
vignettes/using-the-mortalityTables-package.html
+
536
−
396
View file @
e1b39386
Source diff could not be displayed: it is too large. Options to address this:
view the blob
.
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment