knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
The risks package can be installed from CRAN:
install.packages("risks")
Development versions can be installed from GitHub using:
remotes::install_github("stopsack/risks")
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.
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.