# NOT RUN {
set.seed(0)
rl <- function(x){
round(1/(1+exp(-x)))
}
n <- 2000; p <- 3
beta <- -0.5
X <- matrix(rnorm(n*p), n, p)
W <- rbinom(n, 1, 0.5)
Y <- rl(pmax(beta+X[,1], 0) * W + X[,2])
p1 <- 1/(1+exp(-(beta+X[,1])))
plot_uplift_guelman(p1, W, Y, groups=10, plotit=TRUE)
# }
# NOT RUN {
library(grf)
set.seed(123)
alpha <- 0.1
n <- 1000
W <- rbinom(n, 1, 0.5)
Y <- W
p1 <- Y + alpha*rnorm(n)
plot_uplift_guelman(p1, W, Y, groups=10)
rl <- function(x){
round(1/(1+exp(-x)))
}
n <- 2000; p = 10
X <- matrix(rnorm(n*p), n, p)
W <- rbinom(n, 1, 0.2)
Y <- rl(rl(X[,1]) * W - rl(X[,3]) * W + rnorm(n))
tau.forest <- causal_forest(X, Y, W)
tau.hat <- predict(tau.forest, X)
plot_uplift_guelman(tau.hat$predictions, W, Y)
# }
Run the code above in your browser using DataLab