API Reference¶
Top-level API¶
Run bootstrap estimation.
Parameters¶
data : array-like or pandas Series/DataFrame
Observed sample.
statistic : callable
(array) -> float. If vectorized=True, must accept
(array_2d, axis=1) -> array_1d.
method : str
One of: bca, percentile, basic, studentized, poisson, bernoulli,
bayesian, subsampling, mbb, cbb, stationary, tapered, sieve,
wild, cluster, strata.
ci_method : str or None
CI construction for generator-based methods that do not define a
specialized interval: "percentile" or "basic". Defaults to
"percentile". Bayesian, Bernoulli, and subsampling intervals are
not configurable through this parameter.
vectorized : bool
For percentile, basic, and BCa methods, call statistic as
statistic(batch, axis=1). Other methods reject this option.
n_jobs : int
Parallelism for jackknife in BCa (effective only for n >= 2000).
Other Parameters¶
weighted_statistic : callable
Required for custom Bayesian-bootstrap statistics. Called as
weighted_statistic(data, weights) for each Dirichlet draw.
subsample_size : int
Number of observations in each subsample.
rate : float
Convergence-rate exponent for subsampling. 0.5 means root-n.
prob : float
Inclusion probability for Bernoulli subsampling; strictly between 0 and 1.
n_inner : int
Number of inner resamples per outer sample for the studentized method.
Defaults to 100.
Source code in src/bootstrapx/api.py
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 | |
Container for bootstrap estimation results.
Source code in src/bootstrapx/api.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | |
to_dict(*, include_distribution=False)
¶
Return a compact summary mapping of the bootstrap result.
The potentially large bootstrap distribution is excluded by default.
Set include_distribution=True when it is needed for serialization
or downstream analysis. Arrays and extra metadata are copied so
callers cannot mutate the result through the returned dictionary.
Source code in src/bootstrapx/api.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | |
to_frame()
¶
Return a one-row pandas DataFrame with the result summary.
The bootstrap distribution is intentionally omitted to keep the frame
compact. Use :meth:to_dict with include_distribution=True when
the complete distribution is required.
Source code in src/bootstrapx/api.py
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | |
Experiment comparisons¶
Bootstrap an effect between control and treatment samples.
The observed effect and every resampled effect are calculated as
effect(statistic(control), statistic(treatment)). Independent samples
are resampled separately. With paired=True, both samples use the same
resampled indices. Supplying cluster IDs resamples complete clusters within
each arm and is mutually exclusive with paired analysis.
Parameters¶
control, treatment : array-like
Finite one-dimensional samples, or numeric matrices with
allow_2d=True. Matrix rows are observations and columns are jointly
observed features, always resampled together. Their order defines the
direction of every built-in effect. DataFrames are converted to NumPy;
matrix DataFrames must have unique column labels; two DataFrames must
have identical labels and order.
statistic : callable
Scalar function applied separately to each arm, array -> float.
For matrix input, receives a 2-D array and must still return one scalar.
effect : {"difference", "ratio", "relative_lift"} or callable
Transformation of the two arm statistics. A callable receives
(control_statistic, treatment_statistic) and returns one scalar.
Difference is treatment - control; ratio is
treatment / control; relative lift is
(treatment - control) / control.
method : {"percentile", "basic", "bca"}
Confidence-interval construction. BCa is not automatically more
accurate in finite samples. Ratio metrics with skewed data, correlated
numerator/denominator components, or few clusters can materially
undercover; compare methods against domain-relevant simulations and
treat results with few independent units cautiously.
paired : bool
Resample corresponding rows together. The samples must have equal
length and cluster IDs cannot be supplied.
Pairing is positional: pandas indices are not used to align samples.
allow_2d : bool
Explicitly enable multicolumn input for composite scalar metrics.
Defaults to False, preserving the one-dimensional input contract.
Both arms must have the same dimensionality and feature count.
control_cluster_ids, treatment_cluster_ids : array-like or None
One cluster identifier per row. Both arrays are required for clustered
analysis; complete clusters are resampled independently within each
experiment arm. Labels must be scalar, non-missing, finite when numeric,
and mutually comparable within each arm. Mixed string/numeric labels
are rejected rather than coerced into one type.
control_unit_ids, treatment_unit_ids : array-like or None
Optional globally consistent identifiers for one-row-per-unit input.
Both are required together and must be unique within each arm.
Independent arms must be disjoint; paired arms must match in row order.
Cannot be combined with cluster IDs. No IDs are stored in the result.
Omitting IDs leaves correspondence/assignment validation to the caller.
metric_name, effect_unit : str or None
Optional non-empty reporting labels, for example "revenue/order"
and "USD/order" for a difference. Labels do not transform values or
verify the metric definition. Ratios/lifts are dimensionless.
n_resamples : int
Number of bootstrap effects.
batch_size : int or None
Number of resamples processed per technical batch. Changing it does
not change a seeded bootstrap distribution.
confidence_level : float
Requested interval level strictly between zero and one.
random_state : int, numpy.random.Generator, or None
Reproducible random-state source.
Returns¶
TwoSampleBootstrapResult Arm estimates, observed effect, interval, standard error, bootstrap distribution, and experiment-design metadata.
Notes¶
Ratio and relative-lift effects are rejected if the observed or any resampled control statistic is zero. Near-zero denominators are allowed because any fixed tolerance would depend on measurement units, but they can produce unstable intervals. No invalid replicates are silently discarded.
Source code in src/bootstrapx/comparison.py
488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 | |
Result of a control/treatment bootstrap comparison.
Source code in src/bootstrapx/comparison.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | |
theta_hat
property
¶
Alias for the observed effect estimate.
to_dict(*, include_distribution=False)
¶
Return a compact, mutation-safe comparison summary.
Source code in src/bootstrapx/comparison.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | |
to_frame()
¶
Return a one-row pandas DataFrame without the full distribution.
Source code in src/bootstrapx/comparison.py
97 98 99 100 101 102 103 104 105 106 | |
Composite metric helper¶
Added in 0.6.0. See Composite metrics.
Compute sum(sample[:, numerator]) / sum(sample[:, denominator]).
Column positions are non-negative integers. This is not the mean of
row-wise ratios, and it does not compare experiment arms: use it as the
statistic in bootstrap_two_sample(..., allow_2d=True). The callable
receives a numeric NumPy matrix, including when the original input is a
DataFrame. A zero total denominator or non-finite value raises an error;
no observations or replicates are discarded or stabilized.
Source code in src/bootstrapx/stats/metrics.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | |
Source code in src/bootstrapx/stats/confidence.py
28 29 30 31 32 33 34 35 36 37 38 39 | |
BootstrapResult.to_dict() excludes the potentially large bootstrap
distribution by default. Pass include_distribution=True when the full array
is required. BootstrapResult.to_frame() returns a compact one-row pandas
DataFrame.
TwoSampleBootstrapResult follows the same compact-export policy and adds arm
estimates, effect/design metadata, sample sizes, and optional cluster counts.
Integrations¶
Bases: BaseCrossValidator
Bootstrap cross-validator compatible with scikit-learn's CV API.
Generates n_splits bootstrap train/test splits. Each training set
is a bootstrap resample of size n (with replacement); the test set
contains the out-of-bag (OOB) observations not selected for training.
Parameters¶
n_splits : int, default=200 Number of bootstrap iterations. random_state : int or np.random.Generator or None Seed for reproducibility.
Notes¶
- Usable with
cross_val_score,cross_validate,GridSearchCV. - OOB test set size ≈ 0.368 × n per split (Poisson approximation).
- Independent rows only: non-None
groupsare rejected. This splitter does not provide group-aware or time-series-safe validation. - For the 0.632 bootstrap estimator, average
0.368 * train_score + 0.632 * oob_scoreacross splits.
Source code in src/bootstrapx/compat/sklearn_cv.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | |
Accessor registered as pd.Series.bootstrap.
Source code in src/bootstrapx/compat/pandas_accessor.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | |
bca(statistic, n_resamples=9999, confidence_level=0.95, random_state=None)
¶
Shortcut for method='bca'.
Source code in src/bootstrapx/compat/pandas_accessor.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | |
ci(statistic, *, method='bca', n_resamples=9999, confidence_level=0.95, random_state=None, **kwargs)
¶
Run bootstrap and return a :class:~bootstrapx.BootstrapResult.
Source code in src/bootstrapx/compat/pandas_accessor.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | |
percentile(statistic, n_resamples=9999, confidence_level=0.95, random_state=None)
¶
Shortcut for method='percentile'.
Source code in src/bootstrapx/compat/pandas_accessor.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | |
Accessor registered as pd.DataFrame.bootstrap.
Applies bootstrap column-wise and returns a summary DataFrame.
Source code in src/bootstrapx/compat/pandas_accessor.py
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | |
ci(statistic, *, method='bca', n_resamples=9999, confidence_level=0.95, random_state=None, **kwargs)
¶
Alias for :meth:summary.
Source code in src/bootstrapx/compat/pandas_accessor.py
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | |
summary(statistic, *, method='bca', n_resamples=9999, confidence_level=0.95, random_state=None, **kwargs)
¶
Return a DataFrame with bootstrap CI summary for each column.
Returns¶
pd.DataFrame
Index: column names of the original DataFrame.
Columns: theta_hat, ci_low, ci_high, se, method.
Source code in src/bootstrapx/compat/pandas_accessor.py
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | |