Is there an equivalent of boot and boot.ci in python?
In R
I would do
library(boot)
result <- boot(data,bootfun,10000)
boot.ci(result)
Is there an equivalent of boot and boot.ci in python?
In R
I would do
library(boot)
result <- boot(data,bootfun,10000)
boot.ci(result)
There's now also a bootstrap
function in the scipy.stats
module scipy.stats.bootstrap
from scipy import stats
results = stats.bootstrap(data, bootfun, n_resamples=10000)
ci = results.confidence_interval
The confidence interval is returned as a named tuple of low, high values.
I can point to specific bootstrap usage in python. I am assuming you are looking for similar methods for bootstrapping in python
as we do in R
.
import numpy as np
import bootstrapped.bootstrap as bs
import bootstrapped.stats_functions as bs_stats
mean = 100
stdev = 10
population = np.random.normal(loc=mean, scale=stdev, size=50000)
# take 1k 'samples' from the larger population
samples = population[:1000]
print(bs.bootstrap(samples, stat_func=bs_stats.mean))
>> 100.08 (99.46, 100.69)
print(bs.bootstrap(samples, stat_func=bs_stats.std))
>> 9.49 (9.92, 10.36)
The specific packages used here are bootstrapped.bootstrap
and bootstrapped.stats_functions
. You can explore more about this module here
There's now also a bootstrap
function in the scipy.stats
module scipy.stats.bootstrap
from scipy import stats
results = stats.bootstrap(data, bootfun, n_resamples=10000)
ci = results.confidence_interval
The confidence interval is returned as a named tuple of low, high values.
There's also the resample
package available via pip
. Here's the Github page: https://github.com/dsaxton/resample.
Regarding your example you could do the following (there's also a ci_method
argument you can tweak for either the percentile, BCA or Studentized bootstrap interval):
from resample.bootstrap import bootstrap_ci
bootstrap_ci(a=data, f=bootfun, b=10000)
© 2022 - 2024 — McMap. All rights reserved.
boot
andboot.ci
do (or at least link to appropriate R resources) – Panoply