Learn R Programming

whatifbandit (version 0.3.0)

plot.multiple.mab: Plot Generic For multiple.mab Objects

Description

Uses ggplot2::ggplot() to plot the results of multiple Multi-Arm-Bandit trials.

Usage

# S3 method for multiple.mab
plot(
  x,
  type,
  quantity,
  cdf = NULL,
  level = 0.95,
  save = FALSE,
  path = NULL,
  ...
)

Value

Minimal ggplot object, that can be customized and added to with + (to change scales, labels, legend, theme, etc.).

Arguments

x

A multiple.mab class object created by multiple_mab_simulation().

type

String; Type of plot requested; valid types are:

  • summary: Shows the number of times each arm was selected as the highest chance of being the best.

  • hist: Shows histograms for each treatment condition's proportion of success across trials or number of obersvations assigned.

  • estimate: Shows proportion of success AIPW estimates using specified normal or empirical confidence intervals.

quantity

The quantities to plot when type = "hist", accepts either 'estimate' to plot the distributuons of the AIPW estimates, or 'assignment' to plot the distributions of the number of observations assigned to each treatment across the repeated trials.

cdf

String; specifies the type of CDF to use when analyzing the estimates. valid CDFs are the 'empirical' CDF, the 'normal' CDF. Used when type = estimate. The 'normal' CDF uses the fact that the AIPW estimates are asymptotically normal, while the empirical CDF (eCDF) estimates the CDF from the sample of AIPW estimates.

level

Numeric value of length 1; indicates confidence interval Width (i.e 0.90, 0.95, 0.99). Defaults to 0.95.

save

Logical; Whether or not to save the plot to disk; FALSE by default.

path

String; File directory to save file.

...

Arguments to pass to ggplot2::geom_* function (e.g. color, linewidth, alpha, bins etc.). In the case of type = "hist", additional arguments must be passed in to distinct lists, one named geom which are passed to ggplot2::geom_* and one named facet which are passed to ggplot2::facet_grid.

Details

This function provides minimalist plots to quickly view the results of the procedure and has the ability to be customized through the ... in the call and + afterwords. However, all the data necessary is provided in the output of multiple_mab_simulation() for extreme customization or professional plots, it is highly recommended to start completely from scratch and not use the generic.

Examples

Run this code
# Objects returned by `single_mab_simulation()` have a `mab` class.
# This class has a plot generic has several minimal plots to examine the trials
# quickly
#
#
data(tanf)
tanf <- tanf[1:20, ]
# Simulating a few trials

seeds <- sample.int(100, 5)
conditions <- as.character(unique(tanf$condition))
x <- multiple_mab_simulation(
  data = tanf,
  assignment_method = "Batch",
  period_length = 10,
  whole_experiment = TRUE,
  blocking = FALSE,
  perfect_assignment = TRUE,
  algorithm = "Thompson",
  prior_periods = "All",
  control_augment = 0,
  data_cols = c(
    condition_col = "condition",
    id_col = "ic_case_id",
    success_col = "success"
  ),
  verbose = FALSE,
  times = 5,
  seeds = seeds,
  keep_data = FALSE
)

# View number of times each treatment was the best.
plot(x, type = "summary")

# View a histogram of the AIPW estimates for each treatment.
plot(x, type = "hist", quantity = "estimate")

# Plotting AIPW confidence intervals using the empirical cdf, from the simulated
# trials.
plot(x, type = "estimate", cdf = "empirical")

# Changing the title, like any ggplot2 object.
plot(x, type = "summary") + ggplot2::labs(title = "Your New Title")

# Changing the bin width of the histograms.
plot(x, type = "hist", quantity = "assignment", geom = list(binwidth = 0.05))

Run the code above in your browser using DataLab