setup_plot | R Documentation |
GenericML()
plotExtract the relevant information for visualizing the point and interval estimates of the generic targets of interest. The generic targets of interest can be (subsets of) the parameters of the BLP, GATES, or CLAN analysis.
setup_plot( x, type = "GATES", learner = "best", CLAN_variable = NULL, groups = "all" )
x |
An object of the class |
type |
The analysis whose parameters shall be plotted. Either |
learner |
The learner whose results are to be returned. Default is |
CLAN_variable |
Name of the CLAN variable to be plotted. Only applicable if |
groups |
Character vector indicating the per-group parameter estimates that shall be plotted in GATES and CLAN analyses. Default is |
This function is used internally by plot.GenericML()
. It may also be useful for users who want to produce a similar plot, but who want more control over what information to display or how to display that information.
An object of class "setup_plot"
, which is a list with the following elements.
data_plot
A data frame containing point and interval estimates of the generic target specified in the argument type
.
data_BLP
A data frame containing point and interval estimates of the BLP analysis.
confidence_level
The confidence level of the confidence intervals. The confidence level is equal to 1 - 2 * significance_level
, which is the adjustment proposed in the paper.
plot.GenericML()
if(require("ranger") && require("ggplot2")) { ## generate data set.seed(1) n <- 150 # number of observations p <- 5 # number of covariates D <- rbinom(n, 1, 0.5) # random treatment assignment Z <- matrix(runif(n*p), n, p) # design matrix Y0 <- as.numeric(Z %*% rexp(p) + rnorm(n)) # potential outcome without treatment Y1 <- 2 + Y0 # potential outcome under treatment Y <- ifelse(D == 1, Y1, Y0) # observed outcome ## name the columns of Z colnames(Z) <- paste0("V", 1:p) ## specify learners learners <- c("random_forest") ## perform generic ML inference # small number of splits to keep computation time low x <- GenericML(Z, D, Y, learners, num_splits = 2, parallel = FALSE) ## the plot we wish to replicate plot(x = x, type = "GATES") ## get the data to plot the GATES estimates data <- setup_plot(x = x, type = "GATES") ## define variables to appease the R CMD check group <- estimate <- ci_lower <- ci_upper <- NULL ## replicate the plot(x, type = "GATES") # for simplicity, we skip aligning the colors ggplot(mapping = aes(x = group, y = estimate), data = data$data_plot) + geom_hline(aes(yintercept = 0), color = "black", linetype = "dotted") + geom_hline(aes(yintercept = data$data_BLP["beta.1", "estimate"], color = "ATE"), linetype = "dashed") + geom_hline(aes(yintercept = data$data_BLP["beta.1", "ci_lower"], color = paste0(100*data$confidence_level, "% CI (ATE)")), linetype = "dashed") + geom_hline(yintercept = data$data_BLP["beta.1", "ci_upper"], linetype = "dashed", color = "red") + geom_point(aes(color = paste0("GATES with ", 100*data$confidence_level, "% CI")), size = 3) + geom_errorbar(mapping = aes(ymin = ci_lower, ymax = ci_upper)) }
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.