Intro Thoughts

Status Quo

library(tidyverse)

Experiment

library(ggprop.test)

data_hospital_nurse |> 
  ggplot() + 
  aes(x = outcome) + 
  geom_stack() + 
  geom_prop() + 
  ggprop.test:::facet_align(gilbert_worked) + 
  ggprop.test:::geom_prop_diff() + 
  ggprop.test:::geom_prop_diff_label()

compute_diff <- function(data, scales){
  
  data |> 
    summarise(prop = outcome |> as.factor() |> 
             as.numeric() |> mean(), 
           .by = group) |> 
    summarise(diff_prop = max(prop)- min(prop)) |> 
    mutate(group = 1, PANEL = 1) |> 
    mutate(x = diff_prop) |> 
    mutate(label = x |> round(2))
  
}


data_hospital_nurse |> 
  rename(outcome = outcome, group = gilbert_worked) |>
  compute_diff() 
## # A tibble: 1 × 5
##   diff_prop group PANEL     x label
##       <dbl> <dbl> <dbl> <dbl> <dbl>
## 1     0.131     1     1 0.131  0.13
data_hospital_nurse |> 
  ggplot() + 
  aes(outcome = outcome, group = gilbert_worked) + 
  scale_x_continuous(limits = c(-1, 1), 
                     name = "possible differences in proportions", 
                     breaks = c(-1, -.5, 0, .5, 1),
                     labels = c(-1, -.5, "no\ndifference", .5, 1)
                     ) + 
  annotate(geom = "segment", x = 1, xend = -1, y = I(0.05), yend = I(0.05) ) + 
  geom_text(y = I(0.05), 
            stat = statexpress::qstat_panel(compute_diff),
            label = "^",
            vjust = 1, size = 6,
            color = "blue") +  
  geom_label(y = I(0.05), 
            stat = statexpress::qstat_panel(compute_diff),
            vjust = 0, size = 4,
            color = "blue")  + 
  annotate("text", y = I(0.05), 
            label = "^", x = 0,
            vjust = 1, size = 6) +  
  annotate("label", y = I(0.05), 
            x = 0, label = 0,
            vjust = 0, size = 4)  +
  annotate("label", x = I(.2), y = I(.7), 
           label = "sd[null] * {phantom() == phantom()} * sqrt(frac(s[1]^{2}, n[1]) * phantom(.) + frac(s[2]^{2}, n[2]), ) ", parse = T )

ggprop.test:::scale_x_prop
## function (...) 
## {
##     scale_x_discrete(palette = scales::pal_manual(0:1), ...)
## }
## <bytecode: 0x154fd35b0>
## <environment: namespace:ggprop.test>

Closing remarks, Other Relevant Work, Caveats