估计python中分布参数的置信区间 [英] Estimate confidence intervals for parameters of distribution in python
问题描述
是否有一个内置函数可以为python软件包中的参数估计提供置信区间,或者这是我需要手动实现的功能?我正在寻找类似于matlabs gevfit http://www.mathworks.com/help/的东西stats/gevfit.html .
Is there a built in function that will provide the confidence intervals for parameter estimates in a python package or is this something I will need to implement by hand? I am looking for something similar to matlabs gevfit http://www.mathworks.com/help/stats/gevfit.html.
推荐答案
引导程序可用于估计任何函数的置信区间( np.mean
, st.genextreme.fit
等),还有一个Python库: scikits.bootstrap 代码>
.
The bootstrap can be used to estimate confidence intervals of any function (np.mean
, st.genextreme.fit
, etc.) of a sample, and there is a Python library: scikits.bootstrap
.
此处提供了问题作者相关的问题中的数据:
Here for the data from the question author's related question:
import numpy as np, scipy.stats as st, scikits.bootstrap as boot
data = np.array([ 22.20379411, 22.99151292, 24.27032696, 24.82180626,
25.23163221, 25.39987272, 25.54514567, 28.56710007,
29.7575898 , 30.15641696, 30.79168255, 30.88147532,
31.0236419 , 31.17380647, 31.61932755, 32.23452568,
32.76262978, 33.39430032, 33.81080069, 33.90625861,
33.99142006, 35.45748368, 37.0342621 , 37.14768791,
38.14350221, 42.72699534, 44.16449992, 48.77736737,
49.80441736, 50.57488779])
st.genextreme.fit(data) # just to check the parameters
boot.ci(data, st.genextreme.fit)
结果是
(-0.014387281261850815, 29.762126238637851, 5.8983127779873605)
array([[ -0.40002507, 26.93511496, 4.6677834 ],
[ 0.19743722, 32.41834882, 9.05026202]])
引导程序在我的计算机上需要大约三分钟的时间;默认情况下, boot.ci
使用10,000个引导程序迭代( n_samples
),请参见
The bootstrap takes about three minutes on my machine; by default, boot.ci
uses 10,000 bootstrap iterations (n_samples
), see code or help(boot.ci)
, and st.genextreme.fit
is not superfast.
The confidence intervals from boot.ci
do not match the ones from MATLAB's gevfit
exactly. E.g., MATLAB gives a symmetric one [-0.3032, 0.3320] for the first parameter (0.0144).
这篇关于估计python中分布参数的置信区间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!