1 year ago

#326560

test-img

Xray017

Plot estimated effects as odds ratios?

I am currently trying to learn the basics of data visualization in R and have a question regarding the visualization of interaction effects. Namely, I want to visualize the estimated effects of treatment A vs B against the values for a mediator C using a logistic regression model with a binary outcome variable.

The question that has now arisen is whether the estimated treatment effects (i.e. betas) on the y-axis can also be plotted as odds ratios? I mean I can of course convert the coefficients into ORs -- but as expected the interplot() function (as well as other functions I tried) only accepts models (i.e. arguments like "exp(coef(model.A))" are not accepted). Can anyone advise me of a possible solution?

#Outcome analysis
model.A <- glm(outcome ~ treatmentAvsB * mediator, data=df_1, family=binomial())
summary(model.A)

#Store table
(ctable <- coef(summary(model.A)))

#Calculate & store p values
p <- pnorm(abs(ctable[, "t value"]), lower.tail = F) * 2

#Combined table
(ctable <- cbind(ctable, "p value" = p))

#CI's
ci <- confint(model.A)

#Odds ratios
exp(coef(model.A))
exp(cbind(OR = coef(model.A), ci))

#Plotting

library(interplot)
library(ggthemes)

interplot(m=model.A, var1="treatmentAvsB", var2="mediator", hist=T) +
          xlab("...; log10-scaletransformed)") +
          ylab("Estimated effect of treatment A vs B) +
  scale_x_continuous(trans = 'log10') +
  theme_few() +
  geom_hline(yintercept=0, linetype="dashed", colour="grey50")

Example dataset

dput(df_1)

structure(list(treatmentAvsB = c(1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 
1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 
1, 0, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 
0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 0, 
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 0, 1, 1, 0, 1, 
0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 
0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 
1, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 0), mediator = c(70, 40, 
35, 70, 180, 90, 81, 110, 130, 50, 30, 195, 20, 30, 30, 10, 80, 
100, 100, 20, 90, 20, 120, 5, 60, 20, 120, 0, 50, 250, 40, 50, 
140, 100, 0, 50, 40, 145, 0, 20, 380, 10, 50, 50, 40, 20, 100, 
50, 30, 25, 50, 80, 5, 80, 150, 30, 25, 80, 20, 150, 50, 80, 
80, 60, 30, 100, 0, 100, 0, 35, 80, 130, 5, 40, 80, 70, 35, 229, 
20, 60, 15, 110, 60, 70, 70, 45, 5, 35, 0, 30, 30, 15, 60, 20, 
30, 40, 90, 160, 50, 70, 60, 40, 85, 240, 50, 120, 200, 130, 
130, 110, 20, 130, 20, 25, 80, 20, 30, 15, 20, 25, 15, 5, 25, 
15, 50, 25, 10, 10, 50, 80, 30, 2, 55, 10, 100, 180, 10, 140, 
90, 85, 50, 100, 30, 60, 0, 25, 150, 80, 100, 170), outcome = c(1, 
1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 0, 
1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 1, 1, 
0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 
1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 
0, 0, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 
1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0)), row.names = c(NA, -150L), spec = structure(list(cols = list(
    treatmentAvsB = structure(list(), class = c("collector_double", 
    "collector")), mediator = structure(list(), class = c("collector_double", 
    "collector")), outcome = structure(list(), class = c("collector_double", 
    "collector"))), default = structure(list(), class = c("collector_guess", 
"collector")), delim = ","), class = "col_spec"), problems = <pointer: 0x000001dfd6345240>, class = c("spec_tbl_df", 
"tbl_df", "tbl", "data.frame"))

r

ggplot2

statistics

interaction

0 Answers

Your Answer

Accepted video resources