Summarise ForestSearch Cross-Validation Diagnostics
Source:R/summarize_cv_results.R
summarize_cv_results.RdPost-hoc diagnostic summary of forestsearch_tenfold output,
aggregating the sim x fold grid captured in fold_summary into
publication-ready gt tables. Parallel to
summarize_bootstrap_results but focused on cross-validation
stability and GRF candidate-discovery behaviour.
Usage
summarize_cv_results(
cv_output,
original_sg = NULL,
original_grf_cuts = NULL,
create_plots = FALSE,
top_n = 15L
)Arguments
- cv_output
List of class
"fs_tenfold", as returned byforestsearch_tenfold. Must contain a non-emptyfold_summarydata frame.- original_sg
Character vector or
NULL. Original full-data subgroup definition (e.g.,fs$sg.harm). When supplied,original_agreementreports exact and partial-factor match rates against this definition.- original_grf_cuts
Character vector or
NULL. Original full-datagrf_cuts(e.g.,fs$grf_cuts). When supplied alongside agrf_cutscolumn infold_summary,original_agreementalso reports GRF-cut match rate.- create_plots
Logical. If
TRUEand ggplot2 is installed, produce bar-chart diagnostics (default:FALSE).- top_n
Integer. Maximum number of detail rows to retain in frequency tables (default:
15L). If the true number of distinct values exceedstop_n, a single"(N others)"row aggregates the tail so thatn_foldstotals remain honest. Set to a large value (e.g.,Inf) to disable truncation entirely. Plots usemin(top_n, 10L).
Value
An object of class "fs_cv_summary", a list with
components:
identification_summary,grf_cut_summary,cut_vs_subgroup_xtab,no_subgroup_decomposition,pconsistency_distribution,fold_numeric_summary,original_agreement,metrics_tablegttables (ordata.framefallback if gt is unavailable). Some may beNULLdepending on input columns and optional arguments.plotsNULLor a list ofggplotobjects.dataList of raw
data.frametabulations underlying the tables (identification,grf_cuts,cut_vs_subgroup,no_subgroup,pconsistency,fold_numeric_summary,original_agreement).n_sims,n_folds,total_pairsGrid dimensions.
has_grf_cuts,has_pconsistencyLogical. Whether the corresponding
fold_summarycolumns were available. Thefold_numeric_summaryslot adapts automatically to whichever numeric diagnostic columns are present and does not have a dedicated flag.
Diagnostic components
The returned object includes (as gt tables by default):
identification_summary: top identified subgroups across all sim x fold pairs, with counts and percentages.grf_cut_summary: top rawgrf_cutsstrings across training sets – how often GRF returned each output (and how often it returned none).NULLiffold_summary$grf_cutsis not available (e.g., objects from forestsearch prior to the GLM-extension branch).cut_vs_subgroup_xtab: cross-tabulation of uniquegrf_cutsstrings against identified subgroups. Reveals whether GRF's discovery aligns with the pipeline's final selection.no_subgroup_decomposition: tabulation of folds that identified no subgroup, broken into "GRF returned no cut" vs "GRF returned a cut but consistency rejected it".pconsistency_distribution: binned distribution of the consistency probability (Pcons) achieved by the identified subgroup on each fold, restricted to folds that identified a subgroup; includes median and IQR. Reveals whether identifying folds are scrapingpconsistency.threshold(e.g., Pcons just above 0.90) or are well above it.NULLiffold_summary$pconsistencyis not available. Rejected- candidate Pcons values are not surfaced – only the selected candidate's Pcons is captured infold_summary.fold_numeric_summary: tidy median / IQR / range table with one row per numeric diagnostic column present infold_summary(n_test,pconsistency,training_fs_hr,n_candidates_evaluated). Absent columns simply don't produce rows, so the table adapts to pre-feature-branch objects without error. Training-fold subgroup effects are on the effect measure's natural scale (HR for survival; OR, RR, IRR, RD, IRD, or MD for GLM, exponentiated at capture for ratio measures so the column is always on natural scale regardless of outcome type); they are in-sample estimates (optimistically biased) and are surfaced for diagnostic comparison across folds only.original_agreement: iforiginal_sgand/ororiginal_grf_cutsare supplied, fraction of folds matching the original full-data analysis (exact subgroup, partial shared factor, GRF-cut match, both).metrics_table: formatted version ofcv_output$sens_summaryandcv_output$find_summary(delegates tocv_metrics_tables).plots: ifcreate_plots = TRUE, bar charts of top identified subgroups and top GRF cuts.
Raw data.frame versions of each tabulation are available at
$data$* for custom post-processing.
Backward compatibility
The GRF-dependent slots (grf_cut_summary,
cut_vs_subgroup_xtab, no_subgroup_decomposition) require
a grf_cuts column in fold_summary; the
pconsistency_distribution slot requires a pconsistency
column. Both were added on the feature/glm-extension branch
(grf_cuts first, pconsistency later). Older objects
are detected and the affected slots return NULL without error.
Metadata fields has_grf_cuts and has_pconsistency
record which columns were present.
See also
forestsearch_tenfold for running repeated
K-fold CV; cv_metrics_tables for the underlying
metrics formatter; summarize_bootstrap_results for
the bootstrap analogue.
Examples
if (FALSE) { # \dontrun{
library(survival)
df <- survival::gbsg
df$grade3 <- as.integer(df$grade == "3")
df$time_months <- df$rfstime / 30.4375
fs <- forestsearch(
df.analysis = df,
confounders.name = c("age", "meno", "size", "grade3",
"nodes", "pgr", "er"),
outcome.name = "time_months",
event.name = "status",
treat.name = "hormon"
)
tf <- forestsearch_tenfold(fs.est = fs, sims = 100, Kfolds = 10)
# Basic diagnostic summary
cv_diag <- summarize_cv_results(tf)
cv_diag$identification_summary
cv_diag$grf_cut_summary
cv_diag$no_subgroup_decomposition
# With original-analysis comparison and plots
cv_diag_full <- summarize_cv_results(
tf,
original_sg = fs$sg.harm,
original_grf_cuts = fs$grf_cuts,
create_plots = TRUE
)
cv_diag_full$original_agreement
cv_diag_full$plots$identification
} # }