---
title: "Procedure-level re-selection after Cox-Lasso selection"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Procedure-level re-selection after Cox-Lasso selection}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(collapse = TRUE, comment = "#>")
```
```{r smoke-data, include=FALSE}
set.seed(2026)
n_smoke <- 140
p_smoke <- 6
X_smoke <- matrix(rnorm(n_smoke * p_smoke), n_smoke, p_smoke)
colnames(X_smoke) <- paste0("x", seq_len(p_smoke))
beta_smoke <- c(1.0, -0.8, 0.6, 0, 0, 0)
T_smoke <- rexp(n_smoke, rate = 0.05 * exp(drop(X_smoke %*% beta_smoke)))
C_smoke <- rexp(n_smoke, rate = 0.025)
time_smoke <- pmin(T_smoke, C_smoke)
status_smoke <- as.integer(T_smoke <= C_smoke)
library(selSurv)
fit_smoke <- coxlasso_fit(X_smoke, time_smoke, status_smoke, lambda_choice = "1se")
```


## Why this is a separate analysis

A fixed-support model-based bootstrap keeps the support selected in the observed data fixed throughout bootstrap analysis. Procedure-level re-selection instead repeats Cox-Lasso selection and subsequent refitting in each bootstrap sample and therefore describes the repeated data-adaptive procedure.

In `coxlasso_boot(inference = "conditional")`, the term `conditional` means that the observed selected support is retained as the working model; it does not denote formal conditioning on the complete selection event. Re-selection is therefore exposed separately through `coxlasso_boot_reselect()`.

## Available procedures

The interface supports `fixed_support`, `reselect_fixed_lambda`, `reselect_cv_min`, `reselect_cv_1se`, and `reselect_aic`. The first three form the main comparison; CV-1SE and AIC are tuning sensitivities.

## Interpretation of zeroes and failures

For a coordinate that is not selected in a bootstrap sample, the coefficient is recorded as zero on the original p-dimensional scale. A failed non-empty Cox refit is different: it is recorded as missing and contributes to the refit-success diagnostic rather than being treated as non-selection.

## Small reproducible example

```{r example, eval=FALSE}
set.seed(2026)
n <- 100
p <- 6
X <- matrix(rnorm(n * p), n, p)
colnames(X) <- paste0("x", seq_len(p))
beta <- c(0.8, -0.6, 0.4, 0, 0, 0)
T <- rexp(n, rate = 0.06 * exp(drop(X %*% beta)))
C <- rexp(n, rate = 0.04)
time <- pmin(T, C)
status <- as.integer(T <= C)

library(selSurv)
fit <- coxlasso_boot_reselect(
  X, time, status,
  B = 50,
  methods = c("fixed_support", "reselect_fixed_lambda", "reselect_cv_min"),
  seed = 2026,
  nfolds = 5,
  standardize = TRUE
)
fit_summary <- summary(fit)
fit_summary$diagnostics
fit_summary$intervals
```

For publication-scale analyses, use a larger `B`; small values are appropriate only for demonstrating the interface.


```{r reselection-smoke, include=FALSE}
rs_smoke <- coxlasso_boot_reselect(
  X_smoke, time_smoke, status_smoke,
  B = 3L,
  methods = c("fixed_support", "reselect_fixed_lambda", "reselect_cv_min"),
  conf_level = 0.95,
  seed = 2026,
  nfolds = 3L,
  standardize = TRUE
)
rs_smoke_summary <- summary(rs_smoke)
stopifnot(!is.null(rs_smoke_summary$diagnostics), !is.null(rs_smoke_summary$intervals))
```

## Reproducibility mode

`rng_mode = "independent_streams"` is the normal default and makes results for a named method invariant to the order in which methods are requested. `rng_mode = "legacy_nki70"` is retained only to reproduce the archived NKI70 production analysis and is not recommended for new analyses.
