|
10 | 10 | preferred, especially when the sample is small. The computational cost of the jackknife
|
11 | 11 | increases quadratically with the sample size, but only linearly for the bootstrap. An
|
12 | 12 | advantage of the jackknife can be the deterministic outcome, since no random sampling
|
13 |
| -is involved. |
| 13 | +is involved, but this can be overcome by fixing the seed for the bootstrap. |
| 14 | +
|
| 15 | +The jackknife should be used to estimate the bias, since the bootstrap cannot (easily) |
| 16 | +estimate bias. The bootstrap should be preferred when computing the variance. |
14 | 17 | """
|
15 | 18 |
|
16 | 19 | __all__ = [
|
@@ -222,10 +225,10 @@ def bias(
|
222 | 225 | >>> from resample.jackknife import bias
|
223 | 226 | >>> import numpy as np
|
224 | 227 | >>> x = np.arange(10)
|
225 |
| - >>> round(bias(np.var, x), 1) |
226 |
| - -0.9 |
227 |
| - >>> round(bias(lambda x: np.var(x, ddof=1), x), 1) |
228 |
| - 0.0 |
| 228 | + >>> b1 = bias(np.var, x) |
| 229 | + >>> b2 = bias(lambda x: np.var(x, ddof=1), x) |
| 230 | + >>> f"bias of naive sample variance {b1:.1f}, bias of corrected variance {b2:.1f}" |
| 231 | + 'bias of naive sample variance -0.9, bias of corrected variance 0.0' |
229 | 232 |
|
230 | 233 | """
|
231 | 234 | sample = np.atleast_1d(sample)
|
@@ -270,10 +273,10 @@ def bias_corrected(
|
270 | 273 | >>> from resample.jackknife import bias_corrected
|
271 | 274 | >>> import numpy as np
|
272 | 275 | >>> x = np.arange(10)
|
273 |
| - >>> round(np.var(x), 1) |
274 |
| - 8.2 |
275 |
| - >>> round(bias_corrected(np.var, x), 1) |
276 |
| - 9.2 |
| 276 | + >>> v1 = np.var(x) |
| 277 | + >>> v2 = bias_corrected(np.var, x) |
| 278 | + >>> f"naive variance {v1:.1f}, bias-corrected variance {v2:.1f}" |
| 279 | + 'naive variance 8.2, bias-corrected variance 9.2' |
277 | 280 |
|
278 | 281 | """
|
279 | 282 | sample = np.atleast_1d(sample)
|
@@ -314,8 +317,9 @@ def variance(
|
314 | 317 | >>> from resample.jackknife import variance
|
315 | 318 | >>> import numpy as np
|
316 | 319 | >>> x = np.arange(10)
|
317 |
| - >>> round(variance(np.mean, x), 1) |
318 |
| - 0.9 |
| 320 | + >>> v = variance(np.mean, x) |
| 321 | + >>> f"{v:.1f}" |
| 322 | + '0.9' |
319 | 323 |
|
320 | 324 | """
|
321 | 325 | # formula is (n - 1) / n * sum((fj - mean(fj)) ** 2)
|
|
0 commit comments