knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)

mortality

Lifecycle: experimental

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:

Installation

You can install the development version of mortality as below:

install.packages("remotes")
remotes::install_github("emitanaka/mortality")

Usage

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")

Related packages



emitanaka/mortality documentation built on Nov. 2, 2022, 12:29 a.m.