Odds ratio plot on log scale in R -


i have had difficulties plotting results glm logit models show odds ratios on log scale. want obtain estimates different models , plot results on 1 graph shown here (https://www.ctspedia.org/do/view/cts...clinaegraph001). have insight?

i making similar plots week , found worked best produce them confidence intervals running vertically @ first, use coord_flip() @ end convert horizontal:

library(tidyverse) library(ggplot2) library(broom)  set.seed(1234)  # using builtin titanic dataset example data glm tdf = as.data.frame(titanic)  m1 = glm(survived == "yes" ~ class + sex, data = tdf, family = "binomial", weights = freq) m1_preds = tidy(m1, conf.int = true, exponentiate = true) %>%     mutate(model = "m1") # create modified data mixing frequencies - doesn't meaningful, #   way different coefficients tdf$freqscrambled = sample(tdf$freq) m2 = glm(survived == "yes" ~ class + sex, data = tdf,           family = "binomial", weights = freqscrambled) m2_preds = tidy(m2, conf.int = true, exponentiate = true) %>%     mutate(model = "m2")  # @ point have table of odds ratios , confidence intervals #   plotting ors = bind_rows(m1_preds, m2_preds) ors   dodger = position_dodge(width = 0.3) # elements pointrange , position_dodge work when outcome #   mapped y, need go through or set y flip @ #   end ggplot(ors, aes(y = estimate, x = term, colour = model)) +         geom_pointrange(aes(ymin = conf.low, ymax = conf.high),                        position = dodger,                        size = 1.2) +         geom_hline(yintercept = 1.0, linetype = "dotted", size = 1) +         scale_y_log10(breaks = c(0.1, 0.2, 0.5, 1.0, 2.0, 5.0, 10),                       minor_breaks = null) +         labs(y = "odds ratio", x = "effect") +         coord_flip(ylim = c(0.1, 10)) +         theme_bw()  

the result forest plot looks this:

enter image description here


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -