R/odds_to_rr.R
odds_to_rr.Rd
odds_to_rr()
converts odds ratios from a logistic regression
model (including mixed models) into relative risks; or_to_rr()
converts a single odds ratio estimate into a relative risk estimate.
odds_to_rr(fit) or_to_rr(or, p0)
fit | A fitted binomial generalized linear (mixed) model with logit-link function (logistic (multilevel) regression model). |
---|---|
or | Numeric, an odds ratio estimate. |
p0 | Numeric, proportion of the incidence in the outcome variable (base line risk). |
A data frame with relative risks and lower/upper confidence interval for
the relative risks estimates; for or_to_rr()
, the risk ratio
estimate.
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)
and Grant (2014):
RR <- OR / (1 - P0 + (P0 * OR))
, where OR
is the odds
ratio and P0
indicates the proportion of the incidence in
the outcome variable.
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. doi: 10.1001/jama.280.19.1690
Grant RL. 2014. Converting an odds ratio to a range of plausible relative risks for better communication of research findings. BMJ 348:f7450. doi: 10.1136/bmj.f7450
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)#> RR lower.ci upper.ci #> (Intercept) 0.04308565 0.004411356 0.3597023 #> Days 1.41812942 1.212151446 1.5885357data(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)#>#> RR lower.ci upper.ci #> (Intercept) 1.0230093 0.4804412 1.4922066 #> sex 1.2748741 1.1265697 1.4048610 #> dep2 1.2100644 0.9105182 1.4697728 #> dep3 1.4387687 1.1925223 1.6182454 #> dep4 1.3695173 1.0275086 1.6049629 #> barthel 0.9865251 0.9822535 0.9906641 #> education2 1.1007470 0.9246644 1.2637281 #> education3 1.1254901 0.9072463 1.3216546# replicate OR/RR for coefficient "sex" from above regression or_to_rr(1.913887, .5516)#> [1] 1.272447