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

2024-05-16 22:13:09 发布

您现在位置:Python中文网/ 问答频道 /正文

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


Tags: 函数功能comhtmlwwwstatshelp内置
2条回答

bootstrap可以用来估计样本中任何函数(np.meanst.genextreme.fit,等等)的置信区间,并且有一个Python库:^{}。在

以下是作者相关问题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)

结果是

^{pr2}$

在我的机器上引导大约需要3分钟;默认情况下,boot.ci使用10000次引导迭代(n_samples),请参见code或{},并且{}不是超快速的。在

来自boot.ci的置信区间与来自MATLAB的^{}的置信区间不完全匹配。E、 g.,MATLAB给出了第一个参数(0.0144)的对称值[-0.3032,0.3320]。在

看看scipy和{},以防你还没有。如果你对MATLAB有一定的了解,那么切换应该相对容易一些。我从this SO response获取了这段简短片段:

import numpy as np
import scipy as sp
import scipy.stats

def mean_confidence_interval(data, confidence=0.95):
    a = 1.0*np.array(data)
    n = len(a)
    m, se = np.mean(a), scipy.stats.sem(a)
    h = se * sp.stats.t.ppf((1+confidence)/2., n-1)
    return m, m-h, m+h

你应该能够定制你喜欢的回报。与MATLAB gevfit函数一样,它默认使用95%的置信区间。在

相关问题 更多 >