Learn R Programming

sjstats (version 0.8.0)

odds_to_rr: Get relative risks estimates from logistic regressions

Description

This function converts odds ratios from a logistic regression model (including mixed models) into relative risks.

Usage

odds_to_rr(fit)

Arguments

fit
A fitted binomial generalized linear (mixed) model with logit-link function (logistic (multilevel) regression model).

Value

A data frame with relative risks and lower/upper confidence interval for the relative risks estimates.

Details

This function extracts the odds ratios (exponentiated model coefficients) from logistic regressions (fitted with glm or glmer) and their related confidence intervals, and transforms these values into relative risks (and their related confidence intervals). The formula for transformation is based on Zhang and Yu (1998): RR <- OR / ((1 - P0) + (P0 * OR)), where OR is the odds ratio and P0 indicates the proportion of the incidence in the outcome variable.

References

Zhang J, Yu KF. 1998. What's the Relative Risk? A Method of Correcting the Odds Ratio in Cohort Studies of Common Outcomes. JAMA; 280(19): 1690-1. \Sexpr[results=rd,stage=build]{tools:::Rd_expr_doi("#1")}10.1001/jama.280.19.1690http://doi.org/10.1001/jama.280.19.1690doi:\ifelse{latex}{\out{~}}{ }latex~ 10.1001/jama.280.19.1690

Examples

Run this code
library(sjmisc)
library(lme4)
# create binary response
sleepstudy$Reaction.dicho <- dicho(sleepstudy$Reaction, dich.by = "median")
# fit model
fit <- glmer(Reaction.dicho ~ Days + (Days | Subject),
             data = sleepstudy, family = binomial("logit"))
# convert to relative risks
odds_to_rr(fit)


data(efc)
# create binary response
y <- ifelse(efc$neg_c_7 < median(na.omit(efc$neg_c_7)), 0, 1)
# create data frame for fitted model
mydf <- data.frame(y = as.factor(y),
                   sex = efc$c161sex,
                   dep = to_factor(efc$e42dep),
                   barthel = efc$barthtot,
                   education = to_factor(efc$c172code))
# fit model
fit <- glm(y ~., data = mydf, family = binomial(link = "logit"))
# convert to relative risks
odds_to_rr(fit)

Run the code above in your browser using DataLab