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

champsmortality

R-CMD-check Codecov test coverage

The goal of champsmortality is to provide functions for calculating mortality fractions and rates at CHAMPS sites for various causes.

Below is a high-level walkthrough of some of the major package functionality and workflow. Read the additional articles for more depth:

Installation

You can install the development version of champsmortality with the following:

install.packages("remotes") # one time only
remotes::install_github("ki-tools/champs-mortality")

Example

This package is most useful with real data obtainable from CHAMPS. For the purposes of documentation and examples, the package ships with synthetic datasets. As such, keep in mind that the results of the examples in this documentation not meaningful.

library(champsmortality)

Data setup

The first time you use this package, you need to place the appropriate data files in a data directory that the package will pull from to perform the calculations. A function create_dataset_directory() is provided to help get this set up.

data_dir <- tempfile()
create_dataset_directory(data_dir)

This is something that only needs to be done once. Public data that comes with the package will be placed here, and additional private datasets will need to be added. More about the required datasets and expected formats can be found in this article.

For the purpose of these examples, we will change data_dir to point to a directory containing synthetic data. SKIP THIS STEP IF YOU ARE WORKING WITH REAL DATA.

data_dir <- file.path(system.file(package = "champsmortality"), "testdata")

Read the data

Once this is set up and the appropriate files are placed and mapped in the config.yaml file, you can read in the data with the following:

d <- read_and_validate_data(data_dir)

This will read in the data files and ensure that all of the variables required to perform the calculations are present. If they are not, you will see an error message and will need to correct the error before being able to use the package.

Process the data

A function, process_data() takes the data that has been read and joins it together to create a dataset ready analysis.

dd <- process_data(d, start_year = 2017, end_year = 2020)

Valid conditions

Computations with this data typically have the goal of finding adjusted mortality fractions and rates for a given condition found in the causal chain. As you will see, these can be specified by either using the condition name or a regular expression indicating ICD10 codes that indicate the condition.

A convenience function that lists all available conditions in the data is provided, valid_conditions():

valid_conditions(dd)

This searches the CHAMPS data and finds all unique condition values found anywhere in the causal chain. A ranking is also provided where a higher ranking indicates that the condition is found more frequently in the data than a condition with a lower ranking.

Getting Rates and Fractions

The main function of this package computes factor-adjusted mortality rates and fractions for a specified set of sites and catchments. More details about the methodology can be found in this article.

graf <- get_rates_and_fractions(
  dd,
  sites = c("S6", "S5", "S7"),
  catchments = c("C1", "C4", "C3", "C5", "C6", "C7"),
  causal_chain = FALSE,
  pval_cutoff = 0.1,
  pct_na_cutoff = 20,
  condition = "Lower respiratory infections")

The output of this function contains many pieces of information for each site including underlying statistics that went into the calculations, but the most interesting outputs are the rates and fractions.

For site S6, for example, we can extract the computed rates and fractions with the following:

graf$S6$rate
graf$S6$frac


ki-tools/champs-mortality documentation built on Oct. 9, 2022, 6:32 a.m.