Selection-adjusted bootstrap CI for dina_subgroup()
Source:R/dina_subgroup_bootstrap.R
dina_subgroup_bootstrap.RdPerforms selection-adjusted inference for the harm subgroup discovered
by dina_subgroup(). For each of n_boot bootstrap resamples of the
input data frame, the function refits DINA via dina() and re-runs
the subgroup search via dina_subgroup(), then reports three classes
of output:
Usage
dina_subgroup_bootstrap(
df,
outcome,
treatment,
covariates,
family = c("gaussian", "binomial", "poisson", "cox"),
status = NULL,
m_diff,
n_min = 60L,
n_min.frac = 0.1,
direction = c("both", "left", "right"),
sg_focus = "maxSG",
effect_neighborhood = 0.1,
alpha = 0.05,
n_boot = 200L,
parallel = c("none", "boots"),
seed = NULL,
verbose = FALSE,
fit = NULL,
sg = NULL,
refit = TRUE,
refit_strata = NULL,
refit_confounders = "none",
...
)Arguments
- df
data frame containing the outcome, treatment, and covariate columns.
- outcome
character(1); name of the response column in
df. Forfamily = "cox"this is the event/censoring time column.- treatment
character(1); name of the binary treatment indicator column.
- covariates
character vector; names of the covariate columns to search over. All must be numeric.
- family
one of
"gaussian","binomial","poisson","cox".- status
character(1) or
NULL; forfamily = "cox"only, the event indicator column name.- m_diff
scalar harm threshold on the natural-parameter scale.
- n_min
positive integer, or
NULL; minimum subgroup size. Default60L. Passingn_min = NULLopts into the sample-size-adaptive floormax(60, ceiling(n_min.frac * nrow(df))), matchingdina_subgroup(). When supplying a pre-computedsg, use the samen_min(orn_min.frac) it was found with, since the resolved value must matchsg$n_min.- n_min.frac
numeric in (0, 1); fraction of
nrow(df)used for the adaptiven_minfloor whenn_min = NULL. Default0.10. Ignored whenn_minis supplied.- direction
one of
"both"(default),"left","right".- sg_focus
character; subgroup selection criterion, forwarded to
dina_subgroup()for both the original-data point estimate and every bootstrap iteration. Accepts the same set asdina_subgroup(): one of"maxSG"(default),"minSG","eff","effMaxSG","effMinSG","maxeff","maxeffCons"(canonical"hr","hrMaxSG","hrMinSG"and the alias"maxcons"also accepted)."maxeff"and"maxeffCons"were previously rejected here even thoughdina_subgroup()andforestsearch()both accept them. On this path all five of"eff","hr","maxcons","maxeff"and"maxeffCons"rank identically – seedina_subgroup()andfs_focus_tag().- effect_neighborhood
numeric in
[0, 1); relative tolerance for the"effMaxSG"/"effMinSG"effect band, forwarded todina_subgroup(). Default0.10. Ignored for the non-band foci.- alpha
confidence level for the percentile CI. Default
0.05(percentile endpoints at thealpha/2and1 - alpha/2quantiles).- n_boot
positive integer; number of bootstrap iterations. Default
200L. Warns ifn_boot < 100.- parallel
one of
"none"(default) or"boots". When"boots", bootstrap iterations dispatch viaforeach::foreach() %dofuture%against the activefuture::plan().- seed
optional integer seed for reproducibility of the bootstrap indices. Default
NULL.- verbose
logical; if
TRUE, print a progress message every 10 iterations (serial mode) or a start summary (parallel mode). DefaultFALSE.- fit
optional precomputed DINA fit (
"dina"or"dina_bagged") on the originaldf. When supplied (andsgisNULL), the function reuses it for the original-data point estimate instead of refitting, then runs only the subgroup search. Itsfamilymust matchfamily. DefaultNULL.- sg
optional precomputed
"dina_subgroup"result on the originaldf. When supplied, it is used directly as the point estimate with no refit and no re-search;fitis then ignored. Its storedm_diff,n_min,alpha,family, and row count must match the corresponding arguments /df, or an error is raised. Supplying the upstreamsgis the recommended way to guarantee the bootstrap's point estimate is identical to a standalonedina_subgroup()result. DefaultNULL.- refit
logical; if
TRUE(default), also fit the standard within-subgroup treatment-effect model (Cox for survival, GLM otherwise) viadina_subgroup_refiton the original data, and bootstrap it within the fixed discovered signature. Reported alongside the DINA effect. Skipped (with a warning) if the original-data subgroup is not found or the within-subgroup fit errors.- refit_strata
NULL(default) or a character vector of column names entered as Coxstrata()terms in the within-subgroup model. Cox family only.- refit_confounders
adjustment set for the within-subgroup model:
"none"(default, unadjusted),NULL(automatic: the DINAcovariateswith the subgroup-defining covariate omitted), or a character vector of column names. Seedina_subgroup_refit.- ...
further arguments forwarded to
dina()for each per-iteration DINA fit (e.g.,n_folds,cens_type,cens_params,propensity_method,baseline_method).
Value
An object of class "dina_subgroup_bootstrap", a list with
components:
- point
the
"dina_subgroup"object computed on the original (unbootstrapped) data.- effect_ci
named length-2 numeric vector (
lower,upper) giving the bootstrap percentile CI on the fixed-subgroup linear functionala*^T beta_b, wherea* = (1, x_bar_S)is the covariate-mean vector of the original-data subgroup andbeta_bis each bootstrap iteration's DINA coefficient vector. This is the meaningful effect-uncertainty CI; width reflects sampling variance ofbeta-hat.- effect_dist
numeric vector of length
n_bootcontaininga*^T beta_bfor each iteration (NAfor iterations whose DINA fit failed).- refit
the
"dina_subgroup_refit"object (standard within-subgroup model on the original data), orNULLifrefit = FALSE, no subgroup was found, or the fit failed.- refit_effect_ci
named length-2 numeric vector (
lower,upper); bootstrap percentile CI on the within-subgroup standard-model treatment effect, refit within the FIXED discovered signature on each resample. Conditional on the signature; comparable toeffect_ci.(NA, NA)ifrefitwas not performed.- refit_effect_dist
numeric vector of length
n_bootof per-iteration within-signature standard-model treatment effects (NAwhere not computed or the fit failed).- n_subgroup_ci, threshold_ci
named length-2 numeric vectors giving percentile CIs for the structural quantities of bootstrap-selected subgroups, restricted to iterations that selected the same
(covariate, direction)as the original-data subgroup. Subgroup-size and boundary-location stability diagnostics.- n_modal_match
integer; number of bootstrap iterations whose selection matched the original-data
(covariate, direction). Denominator for the stability CIs.- selection_frequency
a
tableof(covariate, direction)selection counts across found iterations. Covariate-selection stability diagnostic.- boot_results
data frame with one row per bootstrap iteration; columns
found,covariate,direction,threshold,n_subgroup,mean_tau_hat,failed. Themean_tau_hatcolumn records the bootstrap-selected subgroup's boundary value (pinned nearm_diffby the search rule) and is retained for diagnostic transparency rather than as a meaningful effect estimate.- n_boot, n_boot_found, n_boot_failed
convergence diagnostics.
- alpha, m_diff, n_min, sg_focus, effect_neighborhood, family
echoed inputs.
- call
the matched call.
Details
An effect CI on
a*^T beta_b, wherea* = (1, x_bar_S)is held FIXED from the original-data subgroupS*andbeta_bis each iteration's DINA coefficient vector. This is the bootstrap analog of the Wald CI returned bydina_subgroup()– conditional on the discovered subgroup definition, with width reflecting sampling variance ofbeta-hat.Stability CIs on the bootstrap-selected
n_subgroupandthreshold, restricted to iterations that selected the same(covariate, direction)as the original-data subgroup.A selection-frequency table counting how often each
(covariate, direction)was chosen. The covariate-selection stability diagnostic.
Each bootstrap iteration calls dina() (single-pass, sandwich
variance) under the hood, not dina_bagged().
If you have already run dina() and dina_subgroup() on the original
data, pass those objects via fit and/or sg so the original-data
point estimate reuses them rather than being recomputed here. This
guarantees the reported point estimate matches your standalone result
exactly; otherwise the internal refit uses its own cross-fitting fold
assignment, which at a boundary-case m_diff can disagree with the
upstream fit on whether a subgroup qualifies.
Why the bootstrap target is the fixed-subgroup effect
A naive bootstrap of dina_subgroup()'s mean_tau_hat is
uninformative. Under the default sg_focus = "maxSG" the search
selects the largest subgroup whose mean tau-hat exceeds m_diff,
so the chosen subgroup lies at the boundary by construction: adding
one more patient would push the mean below m_diff. Each bootstrap
iteration's selected subgroup is similarly pinned, so the bootstrap
distribution of mean_tau_hat clusters tightly above m_diff
and the resulting CI quantifies threshold-grid granularity
rather than effect uncertainty. (Under the band foci
"effMaxSG" / "effMinSG" the per-iteration subgroup is instead
anchored to the maximum effect rather than the m_diff boundary,
but the same caveat applies: mean_tau_hat is a selection-pinned
quantity, not an effect estimate.) The fixed-subgroup linear
functional a*^T beta_b instead targets the clinically
meaningful estimand "treatment effect for patients whose
covariates lie in the discovered subgroup". Because DINA's
beta-hat is cross-fit (and hence asymptotically unbiased even
for data-driven contrasts), the percentile distribution of
a*^T beta_b gives a non-parametric CI that complements the
sandwich Wald CI of dina_subgroup().
Two complementary effect estimates
When refit = TRUE (default), the function reports two treatment
effects for the discovered subgroup, on the same natural-parameter
scale:
the DINA effect (
effect_ci): the BLP-analoga*^T beta, a projection of the cross-fitted CATE surface averaged over the subgroup; andthe within-subgroup standard-model effect (
refit_effect_ci): the treatment coefficient from a plain Cox model (or GLM) fit on the subgroup, refit within the FIXED discovered signature on each resample. This is the contrast a clinical-trial reader usually expects.
The two coincide only under correct linearity; reporting both is
informative. Crucially, both CIs are conditional on the
discovered signature treated as pre-specified – neither corrects for
the data-driven selection of the signature. A selection-adjusted
(de-biased) interval requires the more involved bias-corrected
bootstrap of Leon et al. (2024, Section 3.2) and is not provided
here; selection stability is instead summarized by
selection_frequency.
Performance
With parallel = "boots", each bootstrap iteration runs in a worker
via foreach::foreach() %dofuture%. Set future::plan() to a
parallel backend (e.g., future::multisession) before calling, and
reset to "sequential" afterwards. Workers run from the installed
package; devtools::install() is required after code edits before
the parallel branch will see them.
See also
dina_subgroup() for the underlying threshold search;
dina() for the per-iteration DINA fit;
dina_subgroup_refit for the standard within-subgroup
model reported when refit = TRUE.
Examples
if (FALSE) { # \dontrun{
set.seed(1)
n <- 400
df_demo <- data.frame(
w = stats::rbinom(n, 1, 0.5),
x1 = stats::runif(n, -1, 1),
x2 = stats::runif(n, -1, 1)
)
tau_x <- 0.4 + 1.2 * df_demo$x1
df_demo$y <- 0.5 * df_demo$x1 + df_demo$w * tau_x + stats::rnorm(n)
bs <- dina_subgroup_bootstrap(
df = df_demo,
outcome = "y",
treatment = "w",
covariates = c("x1", "x2"),
family = "gaussian",
m_diff = 0.5,
n_boot = 50L,
seed = 1L
)
print(bs)
} # }