python中qq-plot(或probplot)的逐点置信度包络

时间:2014-07-30 21:07:47

标签: python scipy statsmodels

我有一个到达时间列表,我使用scipy.stats.probplot绘制概率图(类似于qq-plot)。我的数据位于列表l中,我调用

scipy.stats.probplot(l, dist=stats.expon)

如何在绘图中添加逐点置信度包络。之前的SO answer显示了如何在R中执行此操作,但我需要在python中执行此操作。

我也试过了statsmodels,但它似乎比scipy等价物略少(例如它没有计算R ^ 2错误)。

1 个答案:

答案 0 :(得分:0)

我发布了一个稍微不同的例子,但它可能会 帮助你...

#!/usr/bin/env python

from scipy.stats import t
from numpy import average, std
from math import sqrt

if __name__ == '__main__':
    # data we want to evaluate: average height of 30 one year old male and
    # female toddlers. Interestingly, at this age height is not bimodal yet
    data = [63.5, 81.3, 88.9, 63.5, 76.2, 67.3, 66.0, 64.8, 74.9, 81.3, 76.2,
            72.4, 76.2, 81.3, 71.1, 80.0, 73.7, 74.9, 76.2, 86.4, 73.7, 81.3,
            68.6, 71.1, 83.8, 71.1, 68.6, 81.3, 73.7, 74.9]
    mean = average(data)
    # evaluate sample variance by setting delta degrees of freedom (ddof) to
    # 1. The degree used in calculations is N - ddof
    stddev = std(data, ddof=1)
    # Get the endpoints of the range that contains 95% of the distribution
    t_bounds = t.interval(0.95, len(data) - 1)
    # sum mean to the confidence interval
    ci = [mean + critval * stddev / sqrt(len(data)) for critval in t_bounds]
    print "Mean: %f" % mean
    print "Confidence Interval 95%%: %f, %f" % (ci[0], ci[1])