# \donttest{
if (require("ggplot2", quietly = TRUE)) {
# Generate toy data and customize plots.
n <- 500
K <- 1
reward <- matrix(1 + rnorm(n * K), n, K)
scores <- reward + matrix(rnorm(n * K), n, K)
cost <- 1
# Fit Qini curves.
qini.avg <- maq(reward, cost, scores, R = 200, target.with.covariates = FALSE)
qini <- maq(reward, cost, scores, R = 200)
# In some settings we may want to plot using one of R's many plot libraries.
# The plot method invisibly returns the plot data we can use for this purpose.
df.qini.baseline <- plot(qini.avg)
df.qini <- plot(qini, add = TRUE, col = 2)
# Make an alternate plot style, using, for example, ggplot.
ggplot(df.qini, aes(x = spend, y = gain)) +
geom_ribbon(aes(ymin = gain - 1.96 * std.err,
ymax = gain + 1.96 * std.err),
fill = "lightgray") +
geom_line(linewidth = 2) +
ylab("Policy value") +
xlab("Fraction treated") +
geom_line(data = df.qini.baseline, aes(x = spend, y = gain), lty = 2)
}
# }
Run the code above in your browser using DataLab