knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
This R-package fetches and organises the human mortality data from the Human Mortality Database in a tidy fashion. For a more richer and complete package, you should have a look at the demography package.
The mortality package is a modern re-imagination and extension of the functions hmd.mx, hmd.e0, and hmd.pop in the demography package. Specifically:
RCurl is replaced by curl where the latter is a modern version of the former with zero import,tibble, called humble (think human life is short so stay humble -- okay, I'll see my way out 😅), instead of a list of class demogdata, as_demogdata, to convert the Mx and exposure table to hmd.mx output (i.e. demogdata), anddemogdata to a humble tableYou can install the development version of mortality as below:
install.packages("remotes") remotes::install_github("emitanaka/mortality")
library(mortality)
You first need to register as a user (if you haven't already) at the Human Mortality Database. To now set a session with your username and password, fill in your details below and run the code.
hmd_session(username = <YOUR USERNAME>, password = <YOUR PASSWORD>)
Alternatively, you can store your username and password in the .Renviron file
containing below:
HMD_USERNAME=<YOUR USERNAME> HMD_PASSWORD=<YOUR PASSWORD>
then simply just run the command before just once before getting the data:
hmd_session()
All data are obtained via hmd_data().
hmd_data("AUS", stats = "death")
The function offers support for multiple countries:
hmd_data(c("AUS", "JPN"), stats = "death")
or multiple statistics:
hmd_data(c("AUS", "JPN"), stats = c("death", "death_rate"))
or relabeling of the countries like below:
hmd_data(c("Australia" = "AUS", "Japan" = "JPN"), stats = "population")
You can also get a different age or year range:
hmd_data(c("Australia" = "AUS", "Japan" = "JPN"), stats = "exposure_to_risk", year_range = 5, age_range = 5)
Now also supports getting the data with a long format with sex as a variable:
hmd_data(c("AUS", "JPN"), sex_format = "long")
demographyHMDHFDplusMortalityLawstidylife (note: developmental)rawactuarActuDistns (note: archived on CRAN)CompLognormallifecontingenciesChainLadderELTDCLMRMR (note: archived on CRAN)lossDev (note: archived on CRAN)Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.