What

Some extra plots from:

Init

options(digits = 2)
library(pacman)
p_load(kirkegaard, readxl, rms, broom)

d = readxl::read_xlsx("data.xlsx") %>% df_legalize_names()

#subset by outcome
subsets = df_to_ldf(d, "metric", remove_by = F)

#simple
d2 = imap(subsets, function(x, y) {
  # browser()
  select(x, `_50th`) %>% 
    set_colnames(y)
})
d2 = do.call(cbind, d2)
d2$race = subsets$`Abdominal Circumference (mm)`$race
d2$GA = subsets$`Abdominal Circumference (mm)`$GA
d2 %<>% df_legalize_names()

Models

#plot
bpd1 = d2 %>% 
  ggplot(aes(GA, Bi_parietal_Diameter_mm, color = race)) +
  geom_path() +
  theme_bw() +
  ggtitle("Bi-parietal Diameter")
bpd1

#control GA, replot
d2$bpd_resid = ols(Bi_parietal_Diameter_mm ~ rcs(GA), data = d2) %>% resid()
bpd2 = d2 %>% 
  ggplot(aes(GA, bpd_resid, color = race)) +
  geom_path() +
  theme_bw() +
  ggtitle("Bi-parietal Diameter, age controlled")
bpd2

#save together
GG_save("bpd.png", gridExtra::grid.arrange(bpd1, bpd2))