knitr::opts_chunk$set(echo = TRUE)

tSneClstGRF is a R package that generates an interactive shiny interface for easily visualizing and exploring heterogeneous causal effect modeled by causal forest proposed in Athey et al. (2018).

Installation

To install this package from the github repository, use:

if(!require(devtools)) install.packages("devtools") # If not already installed
devtools::install_github("jiongyi-cao/tSneClstGRF")

Usage

A basic workflow of tSneClstGRF contains major three steps:

The following is an illustration using the replication from Athey, S., & Wager, S. (2019). Estimating treatment effects with causal forests: An application.

library(grf)
library(tSneClstGRF)
#load dataset
data(nslm)
X <- nslm[,-c(29,30,31)]
attach(nslm)
## Replication from Athey & Stefan's GRF application
Y.forest = regression_forest(X, Y, clusters = school.id)
Y.hat = predict(Y.forest)$predictions
W.forest = regression_forest(X, W, clusters = school.id)
W.hat = predict(W.forest)$predictions

cf.raw = causal_forest(X, Y, W,
                       Y.hat = Y.hat, W.hat = W.hat,
                       clusters = school.id)
varimp = variable_importance(cf.raw)
selected.idx = which(varimp > mean(varimp))

cf = causal_forest(X[,selected.idx], Y, W,
                   Y.hat = Y.hat, W.hat = W.hat,
                   clusters = school.id,
                   #samples.per.cluster = 50,
                   tune.parameters = "all")

#read causal forest object
my_cf <- read.cf(cf)
#run t-SNE Clustering algorithm
tsne_obj <- run.analsis(my_cf,3000)
#generate shiny application
create.shiny(tsne_obj$result)

References

Athey Susan, Julie Tibshirani, and Stefan Wager. Generalized Random Forests. Annals of Statistics (forthcoming), 2018

Athey, S., & Wager, S. Estimating treatment effects with causal forests: An application.,2019



jiongyi-cao/tSneClstGRF documentation built on June 2, 2022, 11:40 p.m.