4

I have a list of inter-arrival times and I am using scipy.stats.probplot to draw a probability plot (which is similar to a qq-plot). My data is in a list l and I call

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

How can I add a pointwise confidence envelope to the plot. A previous SO answer showed how to do this in R but I need to do it in python.

I tried statsmodels as well but it seems to have slightly less functionality than the scipy equivalent (for example it doesn't compute the R^2 error).

Community
  • 1
  • 1
Simd
  • 19,447
  • 42
  • 136
  • 271

1 Answers1

0

I have posted a slightly different example, but it might help you...

#!/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])
divyaSharma
  • 133
  • 2
  • 11
  • 1
    Your example surely applies to the mean of the distribution, but the question was about the quantiles in the qq plot. Obviously the interval of confidence is wider for the lowest and highest quantiles. – user_na Aug 08 '18 at 14:57