| 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.1.1 |
| Built: | 2026-05-21 06:57:16 UTC |
| Source: | https://github.com/cran/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. |
This function calculates statistics related to the test of treatment effect consistency across groups.
consist.test(D, tau, Y, ngates = 5, nsim = 10000)consist.test(D, tau, Y, ngates = 5, nsim = 10000)
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. |
ngates |
The number of groups to separate the data into. The groups are determined by |
nsim |
Number of Monte Carlo simulations used to simulate the null distributions. Default is 10000. |
The details of the methods for this design are given in Imai and Li (2022).
A list that contains the following items:
stat |
The estimated statistic for the test of consistency |
pval |
The p-value of the null hypothesis (that the treatment effects are consistent) |
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=5) 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=5) consisttestlist$stat consisttestlist$pval
This function calculates statistics related to the test of treatment effect consistency across groups under cross-validation.
consistcv.test(D, tau, Y, ind, ngates = 5, nsim = 10000)consistcv.test(D, tau, Y, ind, ngates = 5, nsim = 10000)
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. |
ind |
A vector of integers (between 1 and number of folds inclusive) indicating which testing set does each sample belong to. |
ngates |
The number of groups to separate the data into. The groups are determined by |
nsim |
Number of Monte Carlo simulations used to simulate the null distributions. Default is 10000. |
The details of the methods for this design are given in Imai and Li (2022).
A list that contains the following items:
stat |
The estimated statistic for the test of consistency under cross-validation. |
pval |
The p-value of the null hypothesis (that the treatment effects are consistent) |
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
This function estimates the Grouped Average Treatment Effects (GATEs) where the groups are determined by a continuous score. The details of the methods for this design are given in Imai and Li (2022).
GATE(D, tau, Y, ngates = 5)GATE(D, tau, Y, ngates = 5)
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. |
ngates |
The number of groups to separate the data into. The groups are determined by |
A list that contains the following items:
gate |
The estimated
vector of GATEs of length |
sd |
The estimated vector of standard deviation of GATEs. |
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=5) 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=5) gatelist$gate gatelist$sd
This function estimates the Grouped Average Treatment Effects (GATEs) under cross-validation where the groups are determined by a continuous score. The details of the methods for this design are given in Imai and Li (2022).
GATEcv(D, tau, Y, ind, ngates = 5)GATEcv(D, tau, Y, ind, ngates = 5)
D |
A vector of the unit-level binary treatment receipt variable for each sample. |
tau |
A matrix where the |
Y |
A vector of the outcome variable of interest for each sample. |
ind |
A vector of integers (between 1 and number of folds inclusive) indicating which testing set does each sample belong to. |
ngates |
The number of groups to separate the data into. The groups are determined by |
A list that contains the following items:
gate |
The estimated
vector of GATEs under cross-validation of length |
sd |
The estimated vector of standard deviation of GATEs under cross-validation. |
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
This function calculates statistics related to the test of heterogeneous treatment effects across groups.
het.test(D, tau, Y, ngates = 5)het.test(D, tau, Y, ngates = 5)
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. |
ngates |
The number of groups to separate the data into. The groups are determined by |
The details of the methods for this design are given in Imai and Li (2022).
A list that contains the following items:
stat |
The estimated statistic for the test of heterogeneity. |
pval |
The p-value of the null hypothesis (that the treatment effects are homogeneous) |
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=5) 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=5) hettestlist$stat hettestlist$pval
This function calculates statistics related to the test of heterogeneous treatment effects across groups under cross-validation.
hetcv.test(D, tau, Y, ind, ngates = 5)hetcv.test(D, tau, Y, ind, ngates = 5)
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. |
ind |
A vector of integers (between 1 and number of folds inclusive) indicating which testing set does each sample belong to. |
ngates |
The number of groups to separate the data into. The groups are determined by |
The details of the methods for this design are given in Imai and Li (2022).
A list that contains the following items:
stat |
The estimated statistic for the test of heterogeneity under cross-validation. |
pval |
The p-value of the null hypothesis (that the treatment effects are homogeneous) |
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, ...)test_itr(model, nsim = 1000, ...)
model |
Fitted model. Usually an output from |
nsim |
Number of Monte Carlo simulations used to simulate the null distributions. Default is 1000. |
... |
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