-
Notifications
You must be signed in to change notification settings - Fork 1
/
README.Rmd
121 lines (84 loc) · 5.04 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
<!-- devtools::build_readme() -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
options(width = 94)
```
# champsmortality
<!-- badges: start -->
[![R-CMD-check](https://github.com/ki-tools/champs-mortality/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/ki-tools/champs-mortality/actions/workflows/R-CMD-check.yaml)
[![Codecov test coverage](https://codecov.io/gh/ki-tools/champs-mortality/branch/main/graph/badge.svg)](https://app.codecov.io/gh/ki-tools/champs-mortality?branch=main)
<!-- badges: end -->
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:
- [Getting Started](https://ki-tools.github.io/champs-mortality/articles/getting-started.html)
- [Datasets](https://ki-tools.github.io/champs-mortality/articles/datasets.html)
- [Computing Adjusted Rates and Fractions](https://ki-tools.github.io/champs-mortality/articles/analysis.html)
- [Creating Reports](https://ki-tools.github.io/champs-mortality/articles/reports.html)
- [Methodology](https://ki-tools.github.io/champs-mortality/articles/methodology.html)
## Installation
You can install the development version of champsmortality with the following:
``` r
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](https://champshealth.org/data/). 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.
```{r}
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.
```{r strip.white=FALSE}
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](articles/datasets.html).
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.
```{r}
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:
```{r}
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.
```{r}
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](https://www.sitepoint.com/learn-regex/) indicating ICD10 codes that indicate the condition.
A convenience function that lists all available conditions in the data is provided, `valid_conditions()`:
```{r}
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](articles/methodology.html).
```{r}
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:
```{r}
graf$S6$rate
graf$S6$frac
```