Plot ROC/PR curves or some summary thereof across experimental replicates.
Arguments
- fit_results
A tibble, as returned by
fit_experiment().- eval_results
A list of result tibbles, as returned by
evaluate_experiment().- eval_name
Name of
Evaluatorcontaining results to plot. IfNULL, the data used for plotting is computed from scratch viaeval_fun.- eval_fun
Character string, specifying the function used to compute the data used for plotting if
eval_name = NULL. Ifeval_nameis notNULL, this argument is ignored.- eval_fun_options
List of named arguments to pass to
eval_fun.- vary_params
A vector of
DGPorMethodparameter names that are varied across in theExperiment.- curve
Either "ROC" or "PR" indicating whether to plot the ROC or Precision-Recall curve.
- show
Character vector with elements being one of "boxplot", "point", "line", "bar", "errorbar", "ribbon", "violin", indicating what plot layer(s) to construct.
- ...
Arguments passed on to
plot_eval_constructoreval_id(Optional) Character string. ID used as the suffix for naming columns in evaluation results tibble. If
eval_summary_constructor()was used to construct theEvaluator, this should be the same as theeval_idargument ineval_summary_constructor(). Only used to assign default (i.e., "auto") aesthetics in ggplot.x_str(Optional) Name of column in data frame to plot on the x-axis. Default "auto" chooses what to plot on the x-axis automatically.
y_str(Optional) Name of column in data frame to plot on the y-axis if
showis anything but "boxplot". Default "auto" chooses what to plot on the y-axis automatically.y_boxplot_str(Optional) Name of column in data frame to plot on the y-axis if
showis "boxplot". Default "auto" chooses what to plot on the y-axis automatically.err_sd_str(Optional) Name of column in data frame containing the standard deviations of
y_str. Used for plotting the errorbar and ribbon ggplot layers. Default "auto" chooses what column to use for the standard deviations automatically.color_str(Optional) Name of column in data frame to use for the color and fill aesthetics when plotting. Default "auto" chooses what to use for the color and fill aesthetics automatically. Use
NULLto avoid adding any color and fill aesthetic.linetype_str(Optional) Name of column in data frame to use for the linetype aesthetic when plotting. Used only when
show = "line". Default "auto" chooses what to use for the linetype aesthetic automatically. UseNULLto avoid adding any linetype aesthetic.facet_formula(Optional) Formula for
ggplot2::facet_wrap()orggplot2::facet_grid()if need be.facet_typeOne of "grid" or "wrap" specifying whether to use
ggplot2::facet_wrap()orggplot2::facet_grid()if need be.plot_by(Optional) Name of column in
eval_tibto use for subsetting data and creating different plots for each unique value. Default "auto" chooses what column to use for the subsetting automatically. UseNULLto avoid creating multiple plots.add_ggplot_layersList of additional layers to add to a ggplot object via
+.boxplot_args(Optional) Additional arguments to pass into
ggplot2::geom_boxplot().point_args(Optional) Additional arguments to pass into
ggplot2::geom_point().line_args(Optional) Additional arguments to pass into
ggplot2::geom_line().bar_args(Optional) Additional arguments to pass into
ggplot2::geom_bar().errorbar_args(Optional) Additional arguments to pass into
ggplot2::geom_errorbar().ribbon_args(Optional) Additional arguments to pass into
ggplot2::geom_ribbon().violin_args(Optional) Additional arguments to pass into
ggplot2::geom_violin().facet_args(Optional) Additional arguments to pass into
ggplot2::facet_grid()orggplot2::facet_wrap().interactiveLogical. If
TRUE, returns interactiveplotlyplots. IfFALSE, returns staticggplotplots.
Value
If interactive = TRUE, returns a plotly object if
plot_by is NULL and a list of plotly objects if
plot_by is not NULL. If interactive = FALSE, returns
a ggplot object if plot_by is NULL and a list of
ggplot objects if plot_by is not NULL.
See also
Other prediction_error_funs:
eval_pred_curve_funs,
eval_pred_err_funs,
plot_pred_err()
Examples
# generate example fit_results data
fit_results <- tibble::tibble(
.rep = rep(1:2, times = 2),
.dgp_name = c("DGP1", "DGP1", "DGP2", "DGP2"),
.method_name = c("Method"),
# true response
y = lapply(1:4,
FUN = function(x) {
as.factor(sample(0:1, size = 100, replace = TRUE))
}),
# predicted class probabilities
class_probs = lapply(1:4, FUN = function(x) runif(n = 100, min = 0, max = 1))
)
# generate example eval_results data
eval_results <- list(
ROC = summarize_pred_curve(
fit_results, truth_col = "y", prob_cols = "class_probs", curve = "ROC"
),
PR = summarize_pred_curve(
fit_results, truth_col = "y", prob_cols = "class_probs", curve = "PR"
)
)
# create summary ROC/PR plots using pre-computed evaluation results
roc_plt <- plot_pred_curve(eval_results = eval_results,
eval_name = "ROC", curve = "ROC",
show = c("line", "ribbon"))
pr_plt <- plot_pred_curve(eval_results = eval_results,
eval_name = "PR", curve = "PR",
show = c("line", "ribbon"))
# or alternatively, create the same plots directly from fit results
roc_plt <- plot_pred_curve(fit_results = fit_results,
show = c("line", "ribbon"), curve = "ROC",
eval_fun_options = list(truth_col = "y",
prob_cols = "class_probs"))
pt_plt <- plot_pred_curve(fit_results = fit_results,
show = c("line", "ribbon"), curve = "PR",
eval_fun_options = list(truth_col = "y",
prob_cols = "class_probs"))
# can customize plot (see plot_eval_constructor() for possible arguments)
roc_plt <- plot_pred_curve(eval_results = eval_results,
eval_name = "ROC", curve = "ROC",
show = c("line", "ribbon"),
plot_by = ".dgp_name")
