Creates Kaplan-Meier survival difference band plots comparing the identified
ForestSearch subgroup (sg.harm) and its complement against the ITT population.
This function wraps plotKM.band_subgroups() from the weightedsurv
package, automatically extracting subgroup definitions from ForestSearch
results.
plot_km_band_forestsearch(
df,
fs.est = NULL,
sg_cols = NULL,
sg_labels = NULL,
sg_colors = NULL,
itt_color = "azure3",
outcome.name = "tte",
event.name = "event",
treat.name = "treat",
xlabel = "Time",
ylabel = "Survival differences",
yseq_length = 5,
draws_band = 1000,
tau_add = NULL,
by_risk = 6,
risk_cex = 0.75,
risk_delta = 0.035,
risk_pad = 0.015,
ymax_pad = 0.11,
show_legend = TRUE,
legend_pos = "topleft",
legend_cex = 0.75,
ref_subgroups = NULL,
verbose = FALSE
)Invisibly returns a list containing:
The modified data frame with subgroup indicators
Character vector of subgroup column names used
Character vector of subgroup labels used
Character vector of colors used
The subgroup definition extracted from fs.est
The reference subgroups list (if provided)
Data frame. The analysis dataset containing all required variables including subgroup indicator columns.
A forestsearch object containing the identified subgroup,
or NULL if using pre-defined subgroup indicators.
Character vector. Names of columns in df containing
subgroup indicators (0/1). These columns must already exist in df.
If NULL and fs.est is provided, columns will be created
automatically. Default: NULL
Character vector. Subsetting expressions for each subgroup,
corresponding to sg_cols. These are passed to
plotKM.band_subgroups() which evaluates them as R expressions
(e.g., "age < 65", "er <= 0", "Qrecommend == 1").
Must be same length as sg_cols.
Default: NULL (auto-generated as "colname == 1").
Character vector. Colors for each subgroup curve,
corresponding to sg_cols. Must be same length as sg_cols.
Default: NULL (uses default color palette).
Character. Color for ITT population band.
Default: "azure3".
Character. Name of time-to-event column.
Default: "tte".
Character. Name of event indicator column.
Default: "event".
Character. Name of treatment column.
Default: "treat".
Character. X-axis label. Default: "Time".
Character. Y-axis label. Default: "Survival differences".
Integer. Number of y-axis tick marks.
Default: 5.
Integer. Number of bootstrap draws for confidence band.
Default: 1000.
Numeric. Time horizon for the plot. If NULL,
auto-calculated from data. Default: NULL.
Numeric. Interval for risk table. Default: 6.
Numeric. Character expansion for risk table text.
Default: 0.75.
Numeric. Vertical spacing for risk table.
Default: 0.035.
Numeric. Padding for risk table. Default: 0.015.
Numeric. Y-axis maximum padding. Default: 0.11.
Logical. Whether to display the legend.
Default: TRUE.
Character. Legend position (e.g., "topleft", "bottomright").
Default: "topleft".
Numeric. Character expansion for legend text.
Default: 0.75.
Named list. Optional additional reference subgroups to include. Each element should be a list with:
Character. R expression to define subgroup (e.g., "age < 65")
Character. Display label (optional, defaults to subset_expr)
Character. Color for the curve
The function automatically creates indicator columns from the expressions.
Default: NULL.
Logical. Print diagnostic messages. Default: FALSE.
When fs.est is provided, the subgroup definition is extracted from:
fs.est$grp.consistency$out_sg$sg.harm_label - Human-readable labels
fs.est$sg.harm - Technical factor names (fallback)
fs.est$df.est$treat.recommend - Subgroup membership indicator
This function simplifies the workflow of creating KM survival difference band plots for ForestSearch-identified subgroups. It can work in two modes:
Mode 1: With ForestSearch result (fs.est provided)
Extracts the subgroup definition from the ForestSearch result
Creates binary indicator columns (Qrecommend, Brecommend) in df
Generates appropriate labels from the subgroup definition
Calls plotKM.band_subgroups() with configured parameters
Mode 2: With pre-defined columns (sg_cols provided)
Uses existing indicator columns in df
Requires sg_labels and sg_colors to match sg_cols
The sg.harm subgroup (Qrecommend) represents patients with questionable
treatment benefit (where treat.recommend == 0 in ForestSearch output).
The complement (Brecommend) represents patients recommended for treatment.
forestsearch for running the subgroup analysis
plot_sg_weighted_km for weighted KM plots
plot_sg_results for comprehensive subgroup visualization