Search code examples
pythonstatsmodels

Confidence interval in normal Q-Q plot using `statsmodels`


I would like to do draw 95% confidence interval in python using statsmodels, but qqplot() doesn't have this option.

If it's not possible, math equation is also acceptable so that I can simply add it to the plot on my own.

import numpy as np
import statsmodels.api as sm
import matplotlib.pyplot as plt

data = np.random.normal(5, 10, 100)
fig = sm.ProbPlot(data, fit=True).qqplot()
plt.show()

There is an implementation in R that I found on the internet, but I am not familiar with R...

enter image description here


Solution

  • The pingouin package has a function to create a qqplot with confidence interval lines. This would do the trick:

    import numpy as np
    import pingouin as pg
    
    data = np.random.normal(5, 10, 100)
    ax = pg.qqplot(data, dist='norm', confidence=.95)
    

    enter image description here