【问题标题】:boot() equivalent in python?python中的boot()等价物?
【发布时间】:2018-09-06 09:56:00
【问题描述】:

在 python 中是否有 boot and boot.ci 的等价物? 在R 我会这样做

library(boot)
result <- boot(data,bootfun,10000)
boot.ci(result)

【问题讨论】:

  • 您可能想查看scikits.bootstrap 包。但是,如果您解释 R 的 bootboot.ci 做什么(或至少链接到适当的 R 资源),这可能会对这个问题的潜在回答者有所帮助

标签: python statistics-bootstrap


【解决方案1】:

我可以指出 python 中特定的引导程序用法。我假设您正在 python 中寻找类似的引导方法,就像我们在 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)

这里使用的具体包是bootstrapped.bootstrapbootstrapped.stats_functions。你可以探索更多关于这个模块here

【讨论】:

    【解决方案2】:

    还可以通过pip 获得resample 包。这是 Github 页面:https://github.com/dsaxton/resample

    关于您的示例,您可以执行以下操作(还有一个 ci_method 参数,您可以调整百分位数、BCA 或学生化引导间隔):

    from resample.bootstrap import bootstrap_ci
    
    bootstrap_ci(a=data, f=bootfun, b=10000)
    

    【讨论】:

      猜你喜欢
      • 2013-02-06
      • 2012-03-22
      • 2016-12-27
      • 2013-12-13
      • 2021-06-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多