Simulate power and bias of ANCOVA vs change score with the same measurement errors of pre an post and some correlation
# In obs studies, ANCOVA has more power than the change score, but bias is variable. In RCT, ANCOVA increases efficiency simulate_data <- function(n = 100) { # Simulate baseline scores and add measurement error baseline <- rnorm(n, mean = 50, sd = 10) + rnorm(n, mean = 0, sd = 2) # Introduce a treatment effect with some noise, ensuring a correlation of r=0.5 treatment_effect <- 5 noise <- rnorm(n, 0, sqrt(10^2 - (0.5 * 10)^2)) post <- baseline * 0.5 + treatment_effect + noise + rnorm(n, mean = 0, sd = 2) group <- ifelse(runif(n) > 0.5, "treatment", "control") post[group == "control"] <- post[group == "control"] - treatment_effect data <- data.frame(id = 1:n, group = group, baseline = baseline, post = post) return(data) } n_simulations <- 1000 alpha <- 0.05 power_ANCOVA <- 0 power_change_score <- 0 # To store estimated effects for both methods across simu...