Skip to content

Instantly share code, notes, and snippets.

@mjadkins
Created February 26, 2020 13:42
Show Gist options
  • Select an option

  • Save mjadkins/bf9295c24c70f282b536fd399f3c2a15 to your computer and use it in GitHub Desktop.

Select an option

Save mjadkins/bf9295c24c70f282b536fd399f3c2a15 to your computer and use it in GitHub Desktop.
odds_to_rr <-function (fit)
{
Estimates <- fixef(fit)
param <-data.frame(Estimates)
param$Parameter <- row.names(param)
est <- param %>% select(Parameter, Estimates)
rownames(est) <- NULL
est[[2]] <- exp(est[[2]])
ci <- stats::confint(fit, method = "Wald", parm = "beta_")
else ci <- stats::confint(fit)
or.dat <- data.frame(est, exp(ci))
colnames(or.dat) <- c("Parameter", "OR", "CI_low", "CI_high")
modfram <- insight::get_data(fit)
outcome <- sjmisc::recode_to(sjlabelled::as_numeric(insight::get_response(fit)))
P0 <- c()
for (i in 1:nrow(est)) {
P0 <- c(P0, .baseline_risk_for_predictor(modfram, outcome,
est[[1]][i]))
}
rr.dat <- or.dat[, 2:4]/((1 - P0) + (P0 * or.dat[, 2:4]))
rr.dat <- cbind(or.dat$Parameter, or.dat$OR, rr.dat)
colnames(rr.dat) <- c("Parameter", "Odds Ratio", "Risk Ratio",
"CI_low", "CI_high")
rownames(rr.dat) <- NULL
rr.dat
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment