| Title: | Evaluating Heterogeneous Treatment Effects |
|---|---|
| Description: | Provides various statistical methods for evaluating heterogeneous treatment effects (HTE) in randomized experiments. The package includes tools to estimate uniform confidence bands for estimation of the group average treatment effect sorted by generic machine learning algorithms (GATES). It also provides the tools to identify a subgroup of individuals who are likely to benefit from a treatment the most "exceptional responders" or those who are harmed by it. Detailed reference in Imai and Li (2023) <doi:10.48550/arXiv.2310.07973>. |
| Authors: | Michael Lingzhi Li [aut, cre], Kosuke Imai [aut], Jialu Li [ctb] |
| Maintainer: | Michael Lingzhi Li <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.2.0 |
| Built: | 2026-10-08 08:00:05 UTC |
| Source: | https://github.com/michaellli/evalhte |
Compute Quantities of Interest (GATE, GATEcv, URATE)
compute_qoi(fit_obj, algorithms)compute_qoi(fit_obj, algorithms)
fit_obj |
An output object of |
algorithms |
Machine learning algorithms |
Compute Quantities of Interest (GATE, GATEcv, URATE) with user defined functions
compute_qoi_user(user_hte, Tcv, Ycv, data, ngates, ...)compute_qoi_user(user_hte, Tcv, Ycv, data, ngates, ...)
user_hte |
A user-defined function to estimate heterogeneous treatment effects (HTE). The function should take the data as input and return an unit-level continuous score for treatment assignment. We assume those that have score less than 0 should not have treatment. The default is |
Tcv |
A vector of the unit-level binary treatment. |
Ycv |
A vector of the unit-level continuous outcome. |
data |
A data frame containing the variables of interest. |
ngates |
The number of gates to be used in the GATE function. |
... |
Additional arguments to be passed to the user-defined function. |
Tests whether treatment effects are nondecreasing across score groups.
consist.test(D, tau, Y, ngates = 5, nsim = 10000, centered = TRUE)consist.test(D, tau, Y, ngates = 5, nsim = 10000, centered = TRUE)
D |
Binary treatment indicator (0 or 1). |
tau |
Continuous score vector. |
Y |
Outcome vector. |
ngates |
Number of groups (at least 2). |
nsim |
Number of Monte Carlo draws (at least 2). |
centered |
Whether to center outcomes before estimation. |
Uses consist.test for inference.
A list with test statistic stat and p-value pval.
Michael Lingzhi Li, Technology and Operations Management, Harvard Business School [email protected], https://www.michaellz.com/;
Imai and Li (2022). “Statistical Inference for Heterogeneous Treatment Effects Discovered by Generic Machine Learning in Randomized Experiments”,
D = c(1,0,1,0,1,0,1,0) tau = c(0,0.1,0.2,0.3,0.4,0.5,0.6,0.7) Y = c(4,5,0,2,4,1,-4,3) consisttestlist <- consist.test(D,tau,Y,ngates=2) consisttestlist$stat consisttestlist$pvalD = c(1,0,1,0,1,0,1,0) tau = c(0,0.1,0.2,0.3,0.4,0.5,0.6,0.7) Y = c(4,5,0,2,4,1,-4,3) consisttestlist <- consist.test(D,tau,Y,ngates=2) consisttestlist$stat consisttestlist$pval
Tests whether treatment effects are nondecreasing across cross-validated score groups.
consistcv.test(D, tau, Y, ind, ngates = 5, nsim = 10000, centered = TRUE)consistcv.test(D, tau, Y, ind, ngates = 5, nsim = 10000, centered = TRUE)
D |
Binary treatment indicator (0 or 1). |
tau |
A matrix of scores with one column per fold. Column |
Y |
Outcome vector. |
ind |
Integer validation-fold labels starting at 1. |
ngates |
Number of groups (at least 2). |
nsim |
Number of Monte Carlo draws (at least 2). |
centered |
Whether to center outcomes before estimation. |
Uses consistcv.test for inference.
A list with test statistic stat and p-value pval.
Michael Lingzhi Li, Technology and Operations Management, Harvard Business School [email protected], https://www.michaellz.com/;
Imai and Li (2022). “Statistical Inference for Heterogeneous Treatment Effects Discovered by Generic Machine Learning in Randomized Experiments”,
D = c(1,0,1,0,1,0,1,0) tau = matrix(c(0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,-0.5,-0.3,-0.1,0.1,0.3,0.5,0.7,0.9),nrow = 8, ncol = 2) Y = c(4,5,0,2,4,1,-4,3) ind = c(rep(1,4),rep(2,4)) consisttestlist <- consistcv.test(D,tau,Y,ind,ngates=2) consisttestlist$stat consisttestlist$pvalD = c(1,0,1,0,1,0,1,0) tau = matrix(c(0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,-0.5,-0.3,-0.1,0.1,0.3,0.5,0.7,0.9),nrow = 8, ncol = 2) Y = c(4,5,0,2,4,1,-4,3) ind = c(rep(1,4),rep(2,4)) consisttestlist <- consistcv.test(D,tau,Y,ind,ngates=2) consisttestlist$stat consisttestlist$pval
Evaluate Heterogeneous Treatment Effects
estimate_hte( treatment, form, data, algorithms, n_folds = 5, split_ratio = 0, ngates = 5, preProcess = NULL, weights = NULL, trControl = caret::trainControl(method = "none"), tuneGrid = NULL, tuneLength = ifelse(trControl$method == "none", 1, 3), user_model = NULL, SL_library = NULL, meta_learner = "slearner", ... )estimate_hte( treatment, form, data, algorithms, n_folds = 5, split_ratio = 0, ngates = 5, preProcess = NULL, weights = NULL, trControl = caret::trainControl(method = "none"), tuneGrid = NULL, tuneLength = ifelse(trControl$method == "none", 1, 3), user_model = NULL, SL_library = NULL, meta_learner = "slearner", ... )
treatment |
Treatment variable |
form |
a formula object that takes the form |
data |
A data frame that contains the outcome |
algorithms |
List of machine learning algorithms to be used. |
n_folds |
Number of cross-validation folds. Default is 5. |
split_ratio |
Split ratio between train and test set under sample splitting. Default is 0. |
ngates |
The number of groups to separate the data into. The groups are determined by tau. Default is 5. |
preProcess |
caret parameter |
weights |
caret parameter |
trControl |
caret parameter |
tuneGrid |
caret parameter |
tuneLength |
caret parameter |
user_model |
A user-defined function to estimate heterogeneous treatment effects. |
SL_library |
A list of machine learning algorithms to be used in the super learner. |
meta_learner |
The type of meta-learner to use (e.g., "slearner", "tlearner"). Default is "slearner". |
... |
Additional arguments passed to |
An object of hte class
Evaluate Heterogeneous Treatment Effects
evaluate_hte(fit, ...)evaluate_hte(fit, ...)
fit |
Fitted model. Usually an output from |
... |
Additional arguments passed to the function. |
An object of hte class
Estimates grouped average treatment effects from a continuous score.
GATE(D, tau, Y, ngates = 5, centered = FALSE)GATE(D, tau, Y, ngates = 5, centered = FALSE)
D |
Binary treatment indicator (0 or 1). |
tau |
Continuous score vector. |
Y |
Outcome vector. |
ngates |
Number of groups (at least 2). |
centered |
Whether to center outcomes before estimation. |
Uses GATE for inference.
A list with group estimates gate and standard errors sd,
ordered by increasing score.
Michael Lingzhi Li, Technology and Operations Management, Harvard Business School [email protected], https://www.michaellz.com/;
Imai and Li (2022). “Statistical Inference for Heterogeneous Treatment Effects Discovered by Generic Machine Learning in Randomized Experiments”,
D = c(1,0,1,0,1,0,1,0) tau = c(0,0.1,0.2,0.3,0.4,0.5,0.6,0.7) Y = c(4,5,0,2,4,1,-4,3) gatelist <- GATE(D,tau,Y,ngates=2) gatelist$gate gatelist$sdD = c(1,0,1,0,1,0,1,0) tau = c(0,0.1,0.2,0.3,0.4,0.5,0.6,0.7) Y = c(4,5,0,2,4,1,-4,3) gatelist <- GATE(D,tau,Y,ngates=2) gatelist$gate gatelist$sd
Estimates grouped average treatment effects from cross-validated scores.
GATEcv(D, tau, Y, ind, ngates = 5, centered = FALSE)GATEcv(D, tau, Y, ind, ngates = 5, centered = FALSE)
D |
Binary treatment indicator (0 or 1). |
tau |
A matrix of scores with one column per fold. Column |
Y |
Outcome vector. |
ind |
Integer validation-fold labels starting at 1. |
ngates |
Number of groups (at least 2). |
centered |
Whether to center outcomes before estimation. |
Uses GATEcv for inference.
A list with group estimates gate and standard errors sd,
ordered by increasing score.
Michael Lingzhi Li, Technology and Operations Management, Harvard Business School [email protected], https://www.michaellz.com/;
Imai and Li (2022). “Statistical Inference for Heterogeneous Treatment Effects Discovered by Generic Machine Learning in Randomized Experiments”,
D = c(1,0,1,0,1,0,1,0) tau = matrix(c(0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,-0.5,-0.3,-0.1,0.1,0.3,0.5,0.7,0.9),nrow = 8, ncol = 2) Y = c(4,5,0,2,4,1,-4,3) ind = c(rep(1,4),rep(2,4)) gatelist <- GATEcv(D, tau, Y, ind, ngates = 2) gatelist$gate gatelist$sdD = c(1,0,1,0,1,0,1,0) tau = matrix(c(0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,-0.5,-0.3,-0.1,0.1,0.3,0.5,0.7,0.9),nrow = 8, ncol = 2) Y = c(4,5,0,2,4,1,-4,3) ind = c(rep(1,4),rep(2,4)) gatelist <- GATEcv(D, tau, Y, ind, ngates = 2) gatelist$gate gatelist$sd
Tests whether treatment effects are equal across score groups.
het.test(D, tau, Y, ngates = 5, centered = TRUE)het.test(D, tau, Y, ngates = 5, centered = TRUE)
D |
Binary treatment indicator (0 or 1). |
tau |
Continuous score vector. |
Y |
Outcome vector. |
ngates |
Number of groups (at least 2). |
centered |
Whether to center outcomes before estimation. |
Uses het.test for inference.
A list with test statistic stat and p-value pval.
Michael Lingzhi Li, Technology and Operations Management, Harvard Business School [email protected], https://www.michaellz.com/;
Imai and Li (2022). “Statistical Inference for Heterogeneous Treatment Effects Discovered by Generic Machine Learning in Randomized Experiments”,
D = c(1,0,1,0,1,0,1,0) tau = c(0,0.1,0.2,0.3,0.4,0.5,0.6,0.7) Y = c(4,5,0,2,4,1,-4,3) hettestlist <- het.test(D,tau,Y,ngates=2) hettestlist$stat hettestlist$pvalD = c(1,0,1,0,1,0,1,0) tau = c(0,0.1,0.2,0.3,0.4,0.5,0.6,0.7) Y = c(4,5,0,2,4,1,-4,3) hettestlist <- het.test(D,tau,Y,ngates=2) hettestlist$stat hettestlist$pval
Tests whether treatment effects are equal across cross-validated score groups.
hetcv.test(D, tau, Y, ind, ngates = 5, centered = TRUE)hetcv.test(D, tau, Y, ind, ngates = 5, centered = TRUE)
D |
Binary treatment indicator (0 or 1). |
tau |
A matrix of scores with one column per fold. Column |
Y |
Outcome vector. |
ind |
Integer validation-fold labels starting at 1. |
ngates |
Number of groups (at least 2). |
centered |
Whether to center outcomes before estimation. |
Uses hetcv.test for inference.
A list with test statistic stat and p-value pval.
Michael Lingzhi Li, Technology and Operations Management, Harvard Business School [email protected], https://www.michaellz.com/;
Imai and Li (2022). “Statistical Inference for Heterogeneous Treatment Effects Discovered by Generic Machine Learning in Randomized Experiments”,
D = c(1,0,1,0,1,0,1,0) tau = matrix(c(0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,-0.5,-0.3,-0.1,0.1,0.3,0.5,0.7,0.9),nrow = 8, ncol = 2) Y = c(4,5,0,2,4,1,-4,3) ind = c(rep(1,4),rep(2,4)) hettestlist <- hetcv.test(D,tau,Y,ind,ngates=2) hettestlist$stat hettestlist$pvalD = c(1,0,1,0,1,0,1,0) tau = matrix(c(0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,-0.5,-0.3,-0.1,0.1,0.3,0.5,0.7,0.9),nrow = 8, ncol = 2) Y = c(4,5,0,2,4,1,-4,3) ind = c(rep(1,4),rep(2,4)) hettestlist <- hetcv.test(D,tau,Y,ind,ngates=2) hettestlist$stat hettestlist$pval
A generic function to plot uniform and pointwise confidence intervals for HTE objects.
plot_CI(x, ...)plot_CI(x, ...)
x |
An object for which a plot is desired. |
... |
Further arguments passed to methods. |
A ggplot2 object displaying uniform and pointwise confidence intervals for heterogeneous treatment effects.
Plot the uniform confidence interval
## S3 method for class 'hte' plot_CI(x, alpha = 0.05, ...)## S3 method for class 'hte' plot_CI(x, alpha = 0.05, ...)
x |
An object of |
alpha |
Significance level. Default is 0.05. |
... |
Further arguments passed to the function. |
A plot of ggplot2 object.
Plot the GATE estimate
## S3 method for class 'hte' plot(x, ...)## S3 method for class 'hte' plot(x, ...)
x |
An table object. This is typically an output of |
... |
Further arguments passed to the function. |
A plot of ggplot2 object.
## S3 method for class 'summary.hte' print(x, ...)## S3 method for class 'summary.hte' print(x, ...)
x |
An object of |
... |
Other parameters. Currently not supported. |
No return value, called for side effects (prints summary tables to console).
## S3 method for class 'summary.test_hte' print(x, ...)## S3 method for class 'summary.test_hte' print(x, ...)
x |
An object of |
... |
Other parameters. |
No return value, called for side effects (prints test results to console).
Summarize Heterogeneity and Consistency Tests
## S3 method for class 'hte' summary(object, ...)## S3 method for class 'hte' summary(object, ...)
object |
An object of |
... |
Other parameters. |
An object of class summary.hte, which is a list containing:
A tibble with group average treatment effect estimates, including columns: group, algorithm, estimate, std.deviation, lower, upper, z.score, and p.value.
A tibble with uplift rate estimates for exceptional responders, including columns: algorithm, estimate, std.deviation, conf.low.uniform, z.score, and p.value. Returns NULL when cross-validation is used.
Summarize Heterogeneity and Consistency Tests
## S3 method for class 'test_hte' summary(object, ...)## S3 method for class 'test_hte' summary(object, ...)
object |
An object of |
... |
Other parameters. |
An object of class summary.test_hte, which is a list containing:
A tibble with consistency test results, including columns: algorithm, statistic, and p.value (for sample splitting).
A tibble with heterogeneity test results, including columns: algorithm, statistic, and p.value (for sample splitting).
A tibble with consistency test results for cross-validation.
A tibble with heterogeneity test results for cross-validation.
Note: The output contains either the first two or last two elements depending on whether cross-validation was used.
Conduct hypothesis tests
test_itr(model, nsim = 1000, centered = TRUE, ...)test_itr(model, nsim = 1000, centered = TRUE, ...)
model |
Fitted model. Usually an output from |
nsim |
Number of Monte Carlo simulations used to simulate the null distributions. Default is 1000. |
centered |
Whether to center outcomes before testing. |
... |
Further arguments passed to the function. |
An object of test_itr class
This function use individualized treatment rule to identify exceptional responders. The details of the methods for this design are given in Imai and Li (2023).
URATE(D, tau, Y)URATE(D, tau, Y)
D |
A vector of the unit-level binary treatment receipt variable for each sample. |
tau |
A vector of the unit-level continuous score. Conditional Average Treatment Effect is one possible measure. |
Y |
A vector of the outcome variable of interest for each sample. |
A list that contains the following items:
rate |
The estimated
vector of URATE of length |
sd |
The estimated vector of standard deviation of URATE. |
Michael Lingzhi Li, Technology and Operations Management, Harvard Business School [email protected], https://www.michaellz.com/;
Imai and Li (2022). “Statistical Inference for Heterogeneous Treatment Effects Discovered by Generic Machine Learning in Randomized Experiments”,
D <- c(1, 0, 1, 0, 1, 0, 1, 0) tau <- c(0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7) Y <- c(4, 5, 0, 2, 4, 1, -4, 3) ratelist <- URATE(D, tau, Y) ratelist$rate ratelist$sdD <- c(1, 0, 1, 0, 1, 0, 1, 0) tau <- c(0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7) Y <- c(4, 5, 0, 2, 4, 1, -4, 3) ratelist <- URATE(D, tau, Y) ratelist$rate ratelist$sd