if (FALSE) {
# Two studies with homogeneous CATEs, such that the test should not reject.
set.seed(123)
n <- 2000
x <- matrix(rnorm(n * 5), ncol = 5)
z <- sample(1:2, n, replace = TRUE) # two studies
d <- rbinom(n, 1, plogis(0.5 * x[, 1] + 0.5 * (z == 2)))
y <- d + x[, 2] + rnorm(n) # CATE is 1 in both studies
output <- catehetDML(y = y, d = d, x = x, z = z)
output$teststat
output$pval
# Same design, but with CATEs differing across studies, such that the test should reject.
y <- d + 1 * (z == 2) * d + x[, 2] + rnorm(n) # CATE is 1 vs. 2
output <- catehetDML(y = y, d = d, x = x, z = z)
output$teststat
output$pval
}
Run the code above in your browser using DataLab