boot() 相当于 python?
boot() equivalent in python?
在python中是否有等同于boot and boot.ci的东西?
在 R
我会做
library(boot)
result <- boot(data,bootfun,10000)
boot.ci(result)
我可以在 python 中指出具体的 bootstrap 用法。我假设您正在寻找 python
中 bootstrapping 的类似方法,就像我们在 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.bootstrap
和bootstrapped.stats_functions
。您可以探索有关此模块的更多信息 here
还有 resample
包可以通过 pip
获得。这是 Github 页面:https://github.com/dsaxton/resample。
关于您的示例,您可以执行以下操作(还有一个 ci_method
参数,您可以针对百分位数、BCA 或 Studentized bootstrap 区间进行调整):
from resample.bootstrap import bootstrap_ci
bootstrap_ci(a=data, f=bootfun, b=10000)
在python中是否有等同于boot and boot.ci的东西?
在 R
我会做
library(boot)
result <- boot(data,bootfun,10000)
boot.ci(result)
我可以在 python 中指出具体的 bootstrap 用法。我假设您正在寻找 python
中 bootstrapping 的类似方法,就像我们在 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.bootstrap
和bootstrapped.stats_functions
。您可以探索有关此模块的更多信息 here
还有 resample
包可以通过 pip
获得。这是 Github 页面:https://github.com/dsaxton/resample。
关于您的示例,您可以执行以下操作(还有一个 ci_method
参数,您可以针对百分位数、BCA 或 Studentized bootstrap 区间进行调整):
from resample.bootstrap import bootstrap_ci
bootstrap_ci(a=data, f=bootfun, b=10000)