# NOT RUN {
if (require("glmnet") && require("ranger")) {
## generate data
set.seed(1)
n <- 150 # number of observations
p <- 5 # number of covariates
D <- rbinom(n, 1, 0.5) # random treatment assignment
Z <- matrix(runif(n*p), n, p) # design matrix
Y0 <- as.numeric(Z %*% rexp(p) + rnorm(n)) # potential outcome without treatment
Y1 <- 2 + Y0 # potential outcome under treatment
Y <- ifelse(D == 1, Y1, Y0) # observed outcome
## column names of Z
colnames(Z) <- paste0("V", 1:p)
## specify learners
learners <- c("lasso", "mlr3::lrn('ranger', num.trees = 10)")
## glmnet v4.1.3 isn't supported on Solaris, so skip Lasso in this case
if(Sys.info()["sysname"] == "SunOS") learners <- learners[-1]
## call GenericML three times and store the returned objects in a list x
x <- lapply(1:3, function(...) GenericML(Z, D, Y,
learners, num_splits = 2,
parallel = FALSE))
## combine the objects in x into one GenericML object
genML <- GenericML_combine(x)
## you can use all methods of GenericML objects on the combined object, for instance accessors:
get_BLP(genML, plot = TRUE)
}
# }
Run the code above in your browser using DataLab