Python中qq图(或概率图)的逐点置信区间

4 投票
1 回答
1718 浏览
提问于 2025-04-18 15:24

我有一组到达时间的间隔数据,我正在使用scipy.stats.probplot来绘制一个概率图(这个图和qq图很像)。我的数据存放在一个列表l中,然后我调用了

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

我想在这个图上添加一个逐点的置信区间。之前有个StackOverflow的回答展示了如何在R语言中做到这一点,但我需要在Python中实现。

我也尝试过使用statsmodels,但它似乎功能稍微少于scipy的版本(比如它不计算R^2误差)。

1 个回答

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])

撰写回答