From 58e27f568ed19c5ef0ded7062ef25c8e3e7e1b0e Mon Sep 17 00:00:00 2001 From: Hans Dembinski Date: Fri, 21 Jun 2024 19:12:51 +0200 Subject: [PATCH] ci fixes (#198) --- src/resample/bootstrap.py | 9 +++++---- src/resample/jackknife.py | 26 +++++++++++++++----------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/resample/bootstrap.py b/src/resample/bootstrap.py index 4033711..667b3ab 100644 --- a/src/resample/bootstrap.py +++ b/src/resample/bootstrap.py @@ -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) @@ -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 ----- diff --git a/src/resample/jackknife.py b/src/resample/jackknife.py index 40e2a61..efe3dc0 100644 --- a/src/resample/jackknife.py +++ b/src/resample/jackknife.py @@ -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__ = [ @@ -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) @@ -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) @@ -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)