Skip to content

Instantly share code, notes, and snippets.

@clayford
Created June 20, 2023 13:11
Show Gist options
  • Save clayford/7052cf34d65f5b8ce6812eb788f6b5ad to your computer and use it in GitHub Desktop.
Save clayford/7052cf34d65f5b8ce6812eb788f6b5ad to your computer and use it in GitHub Desktop.
Reproduce Figure 2 of Pocock, et al (2002)
# replicate Fig 2 of
# Pocock, S.J., Assmann, S.E., Enos, L.E. and Kasten, L.E. (2002),
# Subgroup analysis, covariate adjustment and baseline comparisons in clinical trial reporting: current practiceand problems.
# Statist. Med., 21: 2917-2930. https://doi.org/10.1002/sim.1296
Z_x <- seq(-2, 2, 0.1)
rho <- c(0, 0.1, 0.3, 0.5, 0.7, 0.9)
d <- expand.grid(Z_x = Z_x, rho = rho)
Z_a <- qnorm(0.025, lower.tail = F)
d$size <- pnorm((Z_a - d$Z_x*d$rho)/sqrt(1 - d$rho^2),
lower.tail = F)
d$size2 <- qnorm(d$size)
library(ggplot2)
ggplot(d) +
aes(x = Z_x, y = size2, color = factor(rho)) +
geom_line() +
scale_y_reverse(limits = c(-0.5, -3.1),
breaks = qnorm(c(0.3, 0.2, 0.1, 0.05, 0.025,
0.01, 0.005, 0.002, 0.001)),
labels = c(0.3, 0.2, 0.1, 0.05, 0.025,
0.01, 0.005, 0.002, 0.001),
minor_breaks = NULL) +
labs(color = "rho", x = "standardized imbalance",
y = "size of unadjusted test given imblance and correlation")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment