The goal of {epikit} is to provide miscellaneous functions for This is a product of the R4EPIs project; learn more at https://r4epis.netlify.com.

Installation

You can install {epikit} from CRAN:

Click here for alternative installation options If there is a bugfix or feature that is not yet on CRAN, you can install it via the {drat} package: You can install {epikit} from the R4EPI repository: ``` r # install.packages("drat") drat::addRepo("R4EPI") install.packages("epikit") ``` You can also install the in-development version from GitHub using the {remotes} package (but there’s no guarantee that it will be stable): ``` r # install.packages("remotes") remotes::install_github("R4EPI/epikit") ```

library("epikit")

The {epikit} was primarily designed to house convenience functions for field epidemiologists to use in tidying their reports. The functions in {epikit} come in a few categories:

Give me a break

If you need a quick function to determine the number of breaks you need for a color scale, you can use find_breaks(). This will always start from 1, so that you can include zero in your scale when you need to.

find_breaks(100) # four breaks from 1 to 100
#> [1]  1 26 51 76
find_breaks(100, snap = 20) # four breaks, snap to the nearest 20
#> [1]  1 41 81
find_breaks(100, snap = 20, ceiling = TRUE) # include the highest number
#> [1]   1  41  81 100

Table modification

These functions all modify the appearance of a table displayed in a report and work best with the knitr::kable() function.

  • rename_redundant() renames redundant columns with a single name. (e.g. hopitalized_percent and confirmed_percent can both be renamed to %)
  • augment_redundant() is similar to rename_redundant(), but it modifies the redundant column names (e.g. hospitalized_n and confirmed_n can become hospitalized (n) and confirmed (n))
  • merge_ci() combines estimate, lower bound, and upper bound columns into a single column.
a n a prop a deff b n b prop b deff
1 0.17 3.14 6 1.00 6.28
2 0.33 3.14 5 0.83 6.28
3 0.50 3.14 4 0.67 6.28
4 0.67 3.14 3 0.50 6.28
5 0.83 3.14 2 0.33 6.28
6 1.00 3.14 1 0.17 6.28
df %>%
  rename_redundant("%" = "prop", "Design Effect" = "deff") %>%
  augment_redundant(" (n)" = " n$") %>%
  knitr::kable()
a (n) % Design Effect b (n) % Design Effect
1 0.17 3.14 6 1.00 6.28
2 0.33 3.14 5 0.83 6.28
3 0.50 3.14 4 0.67 6.28
4 0.67 3.14 3 0.50 6.28
5 0.83 3.14 2 0.33 6.28
6 1.00 3.14 1 0.17 6.28

Inline functions

The inline functions make it easier to print estimates with confidence intervals in reports with the correct number of digits.

  • fmt_ci() formats confidence intervals from three numbers. (e.g. fmt_ci(50, 10, 80) produces 50.00% (CI 10.00–80.00)
  • fmt_pci() formats confidence intervals from three fractions, multiplying by 100 beforehand.

The _df suffixes (fmt_ci_df(), fmt_pci_df()) will print the confidence intervals for data stored in data frames. These are designed to work with the outputs of the rates functions. For example, fmt_ci_df(attack_rate(10, 50)) will produce 20.00% (CI 11.24–33.04). All of these suffixes will have three options e, l, and u. These refer to estimate, lower, and upper column positions or names.

Confidence interval manipulation

The confidence interval manipulation functions take in a data frame and combine their confidence intervals into a single character string much like the inline functions do. There are two flavors:

  • merge_ci_df() and merge_pci_df() will merge just the values of the confidence interval and leave the estimate alone. Note: this WILL remove the lower and upper columns.
  • unite_ci() merges both the confidence interval and the estimate into a single character column. This generally has more options than merge_ci()

This is useful for reporting models:

Age categories

A couple of functions are dedicated to constructing age categories and partitioning them into separate chunks.

  • age_categories() takes in a vector of numbers and returns formatted age categories.
  • group_age_categories() will take a data frame with different age categories in columns (e.g. years, months, weeks) and combine them into a single column, selecting the column with the lowest priority.