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

risks: Estimating risk ratios and risk differences using regression

Codecov test coverage R CMD CHECK

Installation

The risks package can be installed from CRAN:

install.packages("risks")

Development versions can be installed from GitHub using:

remotes::install_github("stopsack/risks")

Summary

The risks package fits regression models for risk ratios (RR) and risk differences (RD). The package refers to “risk,” but “prevalence” can be substituted throughout.

What is the association between an exposure (smoker/nonsmoker, age in years, or underweight/lean/overweight/obese) and the risk of a binary outcome (dead/alive, disease/healthy), perhaps adjusting for confounders (men/women, years of education)? For such questions, many studies default to reporting odds ratios, which may exaggerate associations when the outcome is common. Odds ratios are often used because they are easily obtained from logistic regression models. Obtaining risk ratios or risk differences, especially adjusting for confounders, has typically required more advanced biostatistics and programming skills, including in R.

The risks package makes estimating adjusted risk ratios and risk differences as simple as fitting a logistic regression model. No advanced programming or biostatistics skills are required. Risk ratios or risk differences are returned whenever the data would allow for fitting a logistic model.

Basic example

The example data stem from a cohort of women with breast cancer. The the categorical exposure is stage, the binary outcome is death, and the binary confounder is receptor.

Fit a risk difference model:

library(risks)  # provides riskratio(), riskdiff(), postestimation functions
fit <- riskdiff(formula = death ~ stage + receptor, data = breastcancer)

Fitted objects can be used in the usual commands for generalized linear models, such as:

summary(fit)

tidy() from the broom package provides easy access to coefficients:

broom::tidy(fit)

Further reading



stopsack/risks documentation built on April 5, 2025, 6:02 p.m.