8

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)
HappyPy
  • 9,839
  • 13
  • 46
  • 68
  • 2
    You might want to look at the [scikits.bootstrap](https://pypi.python.org/pypi/scikits.bootstrap) package. But it would probably be helpful to potential answerers to this question if you explain what R's `boot` and `boot.ci` do (or at least link to appropriate R resources) – Mark Dickinson Mar 27 '18 at 20:58

2 Answers2

2

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

CodeHunter
  • 2,017
  • 2
  • 21
  • 47
1

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)
dsaxton
  • 995
  • 2
  • 10
  • 23