# Generate some synthetic 2-armed RCT data along with historical controls
n <- 100
dat_rct <- glm_data(
Y ~ 1+2*x1+3*a,
x1 = rnorm(n, 2),
a = rbinom (n, 1, .5),
family = gaussian()
)
dat_hist <- glm_data(
Y ~ 1+2*x1,
x1 = rnorm(n, 2),
family = gaussian()
)
# Fit a learner to the historical control data
learners <- list(
mars = list(
model = parsnip::set_engine(
parsnip::mars(
mode = "regression", prod_degree = 3
),
"earth"
)
)
)
fit <- fit_best_learner(
preproc = list(mod = Y ~ .),
data = dat_hist,
learners = learners
)
# Use it fx. to predict the "control outcome" in the 2-armed RCT
predict(fit, new_data = dat_rct)
Run the code above in your browser using DataLab