plot.GenericML {GenericML} | R Documentation |
Plot method for a "GenericML"
object
Description
Visualizes the estimates of the generic targets of interest: plots the point estimates as well as the corresponding confidence intervals. The generic targets of interest can be (subsets of) the parameters of the BLP, GATES, or CLAN analysis.
Usage
## S3 method for class 'GenericML'
plot(
x,
type = "GATES",
learner = "best",
CLAN_variable = NULL,
groups = "all",
ATE = TRUE,
limits = NULL,
title = NULL,
...
)
Arguments
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 |
ATE |
Logical. If |
limits |
A numeric vector of length two holding the limits of the y-axis of the plot. |
title |
The title of the plot. |
... |
Additional arguments to be passed down. |
Details
If you wish to retrieve the data frame that this plot method visualizes, please use setup_plot()
.
Value
An object of class "ggplot"
.
See Also
setup_plot()
,
GenericML()
,
get_BLP()
,
get_GATES()
,
get_CLAN()
,
setup_diff()
Examples
if(require("ranger")) {
## 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")
## specify quantile cutoffs (the 4 quartile groups here)
quantile_cutoffs <- c(0.25, 0.5, 0.75)
## specify the differenced generic targets of GATES and CLAN
diff_GATES <- setup_diff(subtract_from = "most",
subtracted = c(1,2,3))
diff_CLAN <- setup_diff(subtract_from = "least",
subtracted = c(3,2))
## perform generic ML inference
# small number of splits to keep computation time low
x <- GenericML(Z, D, Y, learners, num_splits = 2,
quantile_cutoffs = quantile_cutoffs,
diff_GATES = diff_GATES,
diff_CLAN = diff_CLAN,
parallel = FALSE)
## plot BLP parameters
plot(x, type = "BLP")
## plot GATES parameters "G1", "G4", "G4-G1"
plot(x, type = "GATES", groups = c("G1", "G4", "G4-G1"))
## plot CLAN parameters "G1", "G2", "G2-G1" of variable "V1":
plot(x, type = "CLAN", CLAN_variable = "V1",
groups = c("G1", "G2", "G1-G3"))
}