
Plot Best-Subset Optimization Diagnostic from a mosaic_subset_optimization Object
Source:R/plot_model_subset_optimization.R
plot_model_subset_optimization.RdRenders a four-panel diagnostic from a mosaic_subset_optimization
object produced by optimize_ensemble_subset. Each panel plots a
diagnostic against the candidate subset size N (top-N members by
likelihood): (1) the objective score, (2) \(R^2\) for cases and deaths,
(3) the bias ratio for cases and deaths (with a dotted reference line at
bias = 1), and (4) the effective sample size (ESS). The preliminary
(tier/diagnostics) subset size is marked with a dashed grey vertical line and
the optimizer-selected size with a solid black vertical line plus a point on
the score panel.
Usage
plot_model_subset_optimization(
subset_opt,
output_dir,
file_prefix = "subset_optimization",
title_label = NULL,
verbose = TRUE
)Arguments
- subset_opt
A
mosaic_subset_optimizationobject returned byoptimize_ensemble_subset. Its$evaluation_tablecarries the per-N diagnostics; the scalar fields$optimal_n,$diagnostics_n,$objective, and$central_methoddrive the markers and labels. The object is consumed directly; the diagnostics are not re-derived from the on-disk CSV.- output_dir
Character. Directory where plots are saved. Created if it does not exist.
- file_prefix
Character. Prefix used in output filenames:
<file_prefix>_diagnostic.pdfand<file_prefix>_diagnostic.png. Default"subset_optimization".- title_label
Character or
NULL. Leading label used in the plot title. WhenNULL(default) a title derived from the objective and central method is used.- verbose
Logical. Print progress messages. Default
TRUE.
Details
The PDF is rendered with grDevices::cairo_pdf when the cairo device is
available (capabilities("cairo")), so the proper glyphs \(R^2\),
\(\rightarrow\), and \(\Delta\) are encoded correctly. When cairo is
unavailable the function falls back to the default PDF device with
ASCII-safe labels (R2, ->, delta). The PNG is always
rendered with the standard raster device.
Semantic colors for the cases and deaths series come from
mosaic_colors and the panel theming from
theme_mosaic, both with graceful fallbacks if unavailable.
See also
optimize_ensemble_subset to compute the optimization;
plot_model_ensemble for the ensemble prediction plots.
Examples
if (FALSE) { # \dontrun{
subset_opt <- optimize_ensemble_subset(ensemble, likelihoods)
plot_model_subset_optimization(subset_opt, output_dir = "diagnostics")
} # }