# bootstrap()


Bootstrap confidence interval for a Kaplan-Meier summary statistic.


Usage

``` python
bootstrap(
    surv,
    statistic,
    *,
    by=None,
    weights=None,
    n_boot=1000,
    conf_level=0.95,
    ci_type="percentile",
    seed=None,
    tau=None,
    p=None,
    times=None,
)
```


Resamples subjects with replacement, fits a Kaplan-Meier estimator on each resample, and extracts the statistic of interest. The bootstrap distribution is then used to construct a confidence interval.


## Parameters


`surv: Surv`  
A [Surv](Surv.md#greenwood.Surv) response (right-censored or counting-process).

`statistic: str | Callable[[KaplanMeier], float]`  
The quantity to bootstrap. Pass a string for built-in statistics:

- `"median"`: median survival time.
- `"rmst"`: restricted mean survival time (requires `tau=`).
- `"quantile"`: survival quantile (requires `p=`).
- `"survival"`: survival probability at a fixed time (requires `times=`).
- `"median_diff"`: difference in median survival between two groups (requires `by=`).
- `"rmst_diff"`: difference in RMST between two groups (requires `by=` and `tau=`).
- `"survival_diff"`: difference in survival probability at a fixed time between two groups (requires `by=` and `times=`).

Alternatively, pass a callable that takes a fitted [KaplanMeier](KaplanMeier.md#greenwood.KaplanMeier) and returns a float.

`by: Any = None`  
Grouping variable for two-sample comparisons. Required for `"_diff"` statistics. Must define exactly two groups.

`weights: Any = None`  
Optional case weights passed through to each bootstrap KM fit.

`n_boot: int = ``1000`  
Number of bootstrap replicates (default 1000).

`conf_level: float = ``0.95`  
Confidence level (default 0.95).

`ci_type: str = ``"percentile"`  
Confidence interval type: `"percentile"` (default), `"normal"`, or `"bca"` (bias-corrected and accelerated).

`seed: int | None = None`  
Random seed for reproducibility.

`tau: float | None = None`  
Upper time limit for RMST statistics.

`p: float | None = None`  
Quantile level for `"quantile"` statistic.

`times: float | None = None`  
Time point for `"survival"` and `"survival_diff"` statistics.


## Returns


`BootstrapResult`  
Point estimate, standard error, confidence interval, and the full bootstrap distribution.
