Skip to content

ci fixes #198

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/resample/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,9 @@ def variance(
>>> from resample.bootstrap import variance
>>> import numpy as np
>>> x = np.arange(10)
>>> round(variance(np.mean, x, size=10000, random_state=1), 1)
0.8
>>> v = variance(np.mean, x, size=10000, random_state=1)
>>> f"{v:.1f}"
'0.8'

"""
thetas = bootstrap(fn, sample, *args, **kwargs)
Expand Down Expand Up @@ -413,8 +414,8 @@ def confidence_interval(
>>> import numpy as np
>>> x = np.arange(10)
>>> a, b = confidence_interval(np.mean, x, size=10000, random_state=1)
>>> round(a, 1), round(b, 1)
(2.6, 6.2)
>>> f"{a:.1f} to {b:.1f}"
'2.6 to 6.2'

Notes
-----
Expand Down
26 changes: 15 additions & 11 deletions src/resample/jackknife.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
preferred, especially when the sample is small. The computational cost of the jackknife
increases quadratically with the sample size, but only linearly for the bootstrap. An
advantage of the jackknife can be the deterministic outcome, since no random sampling
is involved.
is involved, but this can be overcome by fixing the seed for the bootstrap.

The jackknife should be used to estimate the bias, since the bootstrap cannot (easily)
estimate bias. The bootstrap should be preferred when computing the variance.
"""

__all__ = [
Expand Down Expand Up @@ -222,10 +225,10 @@ def bias(
>>> from resample.jackknife import bias
>>> import numpy as np
>>> x = np.arange(10)
>>> round(bias(np.var, x), 1)
-0.9
>>> round(bias(lambda x: np.var(x, ddof=1), x), 1)
0.0
>>> b1 = bias(np.var, x)
>>> b2 = bias(lambda x: np.var(x, ddof=1), x)
>>> f"bias of naive sample variance {b1:.1f}, bias of corrected variance {b2:.1f}"
'bias of naive sample variance -0.9, bias of corrected variance 0.0'

"""
sample = np.atleast_1d(sample)
Expand Down Expand Up @@ -270,10 +273,10 @@ def bias_corrected(
>>> from resample.jackknife import bias_corrected
>>> import numpy as np
>>> x = np.arange(10)
>>> round(np.var(x), 1)
8.2
>>> round(bias_corrected(np.var, x), 1)
9.2
>>> v1 = np.var(x)
>>> v2 = bias_corrected(np.var, x)
>>> f"naive variance {v1:.1f}, bias-corrected variance {v2:.1f}"
'naive variance 8.2, bias-corrected variance 9.2'

"""
sample = np.atleast_1d(sample)
Expand Down Expand Up @@ -314,8 +317,9 @@ def variance(
>>> from resample.jackknife import variance
>>> import numpy as np
>>> x = np.arange(10)
>>> round(variance(np.mean, x), 1)
0.9
>>> v = variance(np.mean, x)
>>> f"{v:.1f}"
'0.9'

"""
# formula is (n - 1) / n * sum((fj - mean(fj)) ** 2)
Expand Down