# Example: Continuous outcome, homogenuous treatment effect, two priors
n <- 50
p <- 3
X <- matrix(runif(n * p), ncol = p)
X_treat <- X_control <- X
treat <- rbinom(n, 1, X[,1])
tau <- 2
y <- X[, 1] + (0.5 - treat) * tau + rnorm(n)
# Fit a standard Causal Horseshoe Forest
fit_horseshoe <- CausalShrinkageForest(y = y,
X_train_control = X_control,
X_train_treat = X_treat,
treatment_indicator_train = treat,
outcome_type = "continuous",
number_of_trees_treat = 5,
number_of_trees_control = 5,
prior_type_control = "horseshoe",
prior_type_treat = "horseshoe",
local_hp_control = 0.1/sqrt(5),
local_hp_treat = 0.1/sqrt(5),
global_hp_control = 0.1/sqrt(5),
global_hp_treat = 0.1/sqrt(5),
N_post = 10,
N_burn = 5,
store_posterior_sample = TRUE,
verbose = FALSE,
seed = 1
)
# Fit a Causal Shrinkage Forest with half-cauchy prior
fit_halfcauchy <- CausalShrinkageForest(y = y,
X_train_control = X_control,
X_train_treat = X_treat,
treatment_indicator_train = treat,
outcome_type = "continuous",
number_of_trees_treat = 5,
number_of_trees_control = 5,
prior_type_control = "half-cauchy",
prior_type_treat = "half-cauchy",
local_hp_control = 1/sqrt(5),
local_hp_treat = 1/sqrt(5),
N_post = 10,
N_burn = 5,
store_posterior_sample = TRUE,
verbose = FALSE,
seed = 1
)
# Posterior mean CATEs
CATE_horseshoe <- colMeans(fit_horseshoe$train_predictions_sample_treat)
CATE_halfcauchy <- colMeans(fit_halfcauchy$train_predictions_sample_treat)
# Posteriors of the ATE
post_ATE_horseshoe <- rowMeans(fit_horseshoe$train_predictions_sample_treat)
post_ATE_halfcauchy <- rowMeans(fit_halfcauchy$train_predictions_sample_treat)
# Posterior mean ATE
ATE_horseshoe <- mean(post_ATE_horseshoe)
ATE_halfcauchy <- mean(post_ATE_halfcauchy)
Run the code above in your browser using DataLab