1

There are many examples on these forums of people calculating risk ratios from logistic regressions, but none of them seem to match my situation.

I have two predictor variables - one continuous and one binary. I'm interested in how the association between the continuous predictor and the outcome differs for group1 vs group2. I know this information is contained in the model coefficients, but I'd like to present the predicted risk ratio and confidence intervals for group1/group2 as a function of the continuous variable.

Here's some simulated data:

library(tidyr)
library(dplyr)
set.seed(42)
N  <- 1000
dat <- data.frame(X1 = rnorm(N, 0, 1),
                  X2 = rbinom(N, 1, .5))

dat$Y <- 0.5*dat$X1 - 0.3*dat$X2 - (0.2*dat$X1*dat$X2) + rnorm(N, 0, 1)

dat$Y <- as.numeric(cut(dat$Y, breaks=c(-Inf, median(dat$Y), Inf)))-1

mod <- glm(Y~X1*X2, family='binomial', data=dat)

newdat <- expand.grid(X1 = seq(-3, 3, .25),
                      X2 = c(0, 1))

newdat$y_pred <- predict(mod, type='response', newdata = newdat)
newdat %>%
  spread(X2, y_pred) %>%
  mutate(relative_risk = `0`/`1`) -> newdat

Basically, I would like to know whether it is possible for me to obtain a confidence interval for that relative_risk variable, and if so, how to compute it.

Bonus points if the method can be generalized to multilevel models.

kjetil b halvorsen
  • 63,378
  • 26
  • 142
  • 467
triddle
  • 460
  • 3
  • 7
  • 1
    "risk ratio (RR) or relative risk is the ratio of the probability of an outcome in an exposed group to the probability of an outcome in an unexposed group.".So relative risk is kind of ratio already. The relative risk ratio is ratio of ratio. Do you have any idea what it is? – user158565 Dec 28 '18 at 18:06
  • If you use a log link, I think the coefficients of a logistic regression become risk rations. Alternatively, you could use a Modified Poisson to estimate the RR, but that analysis requires that your data be cohort data with exposure times. – Demetri Pananos Feb 08 '19 at 20:05

0 Answers0