Skip to main content
 首页 » 编程设计

python之估计 python 中分布参数的置信区间

2024年10月24日12birdshome

是否有一个内置函数可以为 python 包中的参数估计提供置信区间,或者这是我需要手动实现的东西?我正在寻找类似于 matlabs gevfit http://www.mathworks.com/help/stats/gevfit.html 的东西.

请您参考如下方法:

bootstrap 可用于估计样本的任何函数(np.mean、st.genextreme.fit 等)的置信区间,并且有Python 库:scikits.bootstrap。

此处为问题作者相关 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]]) 

Bootstrap 在我的机器上大约需要三分钟;默认情况下,boot.ci 使用 10,000 次引导迭代 (n_samples),请参阅 code 或 help(boot.ci),以及 st .genextreme.fit 不是超快的。

来自 boot.ci 的置信区间与来自 MATLAB 的 gevfit 的置信区间不完全匹配。例如,MATLAB 为第一个参数 (0.0144) 给出一个对称的 [-0.3032, 0.3320]。