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

Vignette: Name all chunks to improve performance

parent b7e38769
No related branches found
No related tags found
No related merge requests found
...@@ -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", "1991", "2001", "2011")]) + mort.AT.census[c("m", "w"), c("1949/51", "1990/92", "2000/02", "2010/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 %>%
......
Source diff could not be displayed: it is too large. Options to address this: view the blob.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment