The causalTree function builds a regression model and returns an rpart object, which is the object derived from rpart package, implementing many ideas in the CART (Classification and Regression Trees), written by Breiman, Friedman, Olshen and Stone. Like rpart, causalTree builds a binary regression tree model in two stages, but focuses on estimating heterogeneous causal effect.
This repository was forked from Professor Athey's Github. This fork of the repository is used for didactic purposes and will generally not be up to date with the latest version.
To install this package in R, run the following commands:
install.packages("devtools")
library(devtools)
install_github("walterwzhang/causalTree")
Example usage:
library(causalTree)
set.seed(1234)
CF_fit <- causalForest(y~ x1 + x2 + x3 + x4, data = simulation.1, treatment = simulation.1$treatment,
num.trees = 100, verbose = FALSE)
CF_predictions <- predict(CF_fit, simulation.2)
summary(CF_predictions)
- Remember to set the seed before each
causalForest
run to attain replicable results. - For console output for each tree built set the parameter
verbose
toTRUE
incasualForest
. - For more details, please check out briefintro.pdf.
If the installation of the package with install_github()
fails.
- Make sure a prior version of causalTree is not installed.
- Quit the R/RStudio Session
- Check to see if the causalTree library is still there and delete the folder if it is. (e.g. delete the folder C:\Users\user_name\Documents\R\win-library\3.3\causalTree on a windows computer)
- Open R/RStudio, load devtools, and try re-installing this package with
install_github()
Susan Athey, Guido Imbens. Recursive Partitioning for Heterogeneous Causal Effects. [link]