Create a new Visualizer
.
Usage
create_visualizer(
.viz_fun,
.name = NULL,
.rmd_options = list(),
.rmd_show = TRUE,
...
)
Arguments
- .viz_fun
The visualization function.
- .name
(Optional) The name of the
Visualizer
.- .rmd_options
(Optional) List of options to control the aesthetics of the
Visualizer
's visualization in the knitted R Markdown report. Currently, possible options are "height" and "width" (in inches). The argument must be specified by position or typed out in whole; no partial matching is allowed for this argument.- .rmd_show
If
TRUE
(default), show the resulting visualization in the R Markdown report; ifFALSE
, hide output in the R Markdown report.- ...
Arguments to pass into
.viz_fun()
.
Details
When visualizing or running the Experiment
(see
Experiment$visualize()
or Experiment$run()
), the named
arguments fit_results
, eval_results
, and
vary_params
are automatically passed into the Visualizer
function .viz_fun()
and serve as placeholders for the
Experiment$fit()
results, the Experiment$evaluate()
results, and the name of the varying parameter, respectively.
To visualize the performance of a method(s) fit and/or its evaluation
metrics then, the Visualizer
function .viz_fun()
should
take in the named arguments fit_results
and/or
eval_results
. See Experiment$fit()
or
fit_experiment()
for details on the format of fit_results
.
See Experiment$evaluate()
or evaluate_experiment()
for
details on the format of eval_results
. If the Visualizer
is used for Experiments
with varying parameters,
vary_params
should be used as a stand in for the name of this
varying parameter.
Examples
# create an example Visualizer function
power_plot_fun <- function(fit_results, vary_params = NULL, col = "X1") {
if (!is.null(vary_params)) {
# deal with the case when we vary across a parameter that is vector-valued
if (is.list(fit_results[[vary_params]])) {
fit_results[[vary_params]] <- list_col_to_chr(fit_results[[vary_params]],
name = vary_params,
verbatim = TRUE)
}
}
plt <- ggplot2::ggplot(fit_results) +
ggplot2::aes(x = .data[[paste(col, "p-value")]],
color = as.factor(.method_name)) +
ggplot2::geom_abline(slope = 1, intercept = 0,
color = "darkgray", linetype = "solid", size = 1) +
ggplot2::stat_ecdf(size = 1) +
ggplot2::scale_x_continuous(limits = c(0, 1)) +
ggplot2::labs(x = "t", y = "P( p-value \u2264 t )",
linetype = "", color = "Method")
if (!is.null(vary_params)) {
plt <- plt + ggplot2::facet_wrap(~ .data[[vary_params]])
}
return(plt)
}
# create Visualizer using the default arguments (i.e., col = "X1")
power_plot1 <- create_visualizer(.viz_fun = power_plot_fun,
.name = "Power Plot (X1)")
# create Visualizer using non-default arguments (i.e., col = "X2")
power_plot2 <- create_visualizer(.viz_fun = power_plot_fun,
.name = "Power Plot (X2)",
# additional named parameters to pass to power_plot_fun()
col = "X2")
# create Visualizer from a function in the built-in Visualizer library
pred_err_plot <- create_visualizer(.viz_fun = plot_pred_err,
.name = "Prediction Error Plot",
# additional named parameters to pass to plot_pred_err()
truth_col = "y", estimate_col = "predictions")
# change figure height/width when displaying Visualizer in Rmd report
pred_err_plot <- create_visualizer(.viz_fun = plot_pred_err,
.name = "Prediction Error Plot",
.rmd_options = list(height = 8, width = 12),
# additional named parameters to pass to plot_pred_err()
truth_col = "y", estimate_col = "predictions")