cleverly.inference.run_bootstrap#

cleverly.inference.run_bootstrap(data: Resamplable, refit: Callable[[Any], Mapping[str, tuple[float, float]]], *, n_replicates: int, resampling: Literal['auto', 'iid', 'cluster'] = 'auto', random_state: int | None = None, n_jobs: int = 1) → BootstrapResult[source]#

Run n_replicates full-refit bootstrap replicates.

Parameters:
dataCausalData or LongitudinalData

Validated study data to resample.

refitcallable()

Maps a resampled container of the same type to a mapping of estimand name to (estimate, standard error) (RefitFn). Replicates that raise are dropped and counted rather than aborting the run: with weak overlap a resample can easily end up with an empty treatment arm in some stratum.

n_replicatesint

How many replicates to draw.

resampling{“auto”, “iid”, “cluster”}

"auto" resamples clusters when the data has them, and rows otherwise. "iid" always resamples rows. "cluster" requires cluster ids and is refused without them. Any other value is refused.

random_stateint or None

Seed for the replicate draws.

n_jobsint

Number of joblib workers.

Returns:
BootstrapResult

The replicate estimates and standard errors, and how many replicates failed.

Raises:
TypeError

When a replicate’s refit returns anything but (estimate, standard error) pairs.