Created
August 16, 2012 20:16
-
-
Save phobson/3373257 to your computer and use it in GitHub Desktop.
Testing several scenarios with the new probplot functionality
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot as plt | |
import scipy.stats as stats | |
import statsmodels.api as sm | |
# longley dataset | |
data = sm.datasets.longley.load() | |
data.exog = sm.add_constant(data.exog) | |
model = sm.OLS(data.endog, data.exog) | |
mod_fit = model.fit() | |
res = mod_fit.resid | |
# T-dist | |
pp = sm.ProbPlot(res, dist=stats.t, distargs=(4,)) | |
for line in ['r', 'q', '45', 's']: | |
fig, (ax1, ax2, ax3) = plt.subplots(nrows=3, ncols=1) | |
pp.qqplot(ax1, line=line) | |
pp.ppplot(ax2, line=line) | |
pp.probplot(ax3, line=line) | |
fig.suptitle('T+distargs with line='+line) | |
plt.show() | |
pp = sm.ProbPlot(res, dist=stats.t, distargs=(4,), loc=3, scale=10) | |
for line in ['r', 'q', '45', 's']: | |
fig, (ax1, ax2, ax3) = plt.subplots(nrows=3, ncols=1) | |
pp.qqplot(ax1, line=line) | |
pp.ppplot(ax2, line=line) | |
pp.probplot(ax3, line=line) | |
fig.suptitle('T+distargs+log+scale with line='+line) | |
plt.show() | |
pp = sm.ProbPlot(res, dist=stats.t, fit=True) | |
for line in ['r', 'q', '45', 's']: | |
fig, (ax1, ax2, ax3) = plt.subplots(nrows=3, ncols=1) | |
pp.qqplot(ax1, line=line) | |
pp.ppplot(ax2, line=line) | |
pp.probplot(ax3, line=line) | |
fig.suptitle('T+fit with line='+line) | |
plt.show() | |
# Normal dist | |
pp = sm.ProbPlot(res, dist=stats.norm) | |
for line in ['r', 'q', '45', 's']: | |
fig, (ax1, ax2, ax3) = plt.subplots(nrows=3, ncols=1) | |
pp.qqplot(ax1, line=line) | |
pp.ppplot(ax2, line=line) | |
pp.probplot(ax3, line=line) | |
fig.suptitle('Norm with line='+line) | |
plt.show() | |
pp = sm.ProbPlot(res, dist=stats.norm, loc=res.mean(), scale=res.std()) | |
for line in ['r', 'q', '45', 's']: | |
fig, (ax1, ax2, ax3) = plt.subplots(nrows=3, ncols=1) | |
pp.qqplot(ax1, line=line) | |
pp.ppplot(ax2, line=line) | |
pp.probplot(ax3, line=line) | |
fig.suptitle('Norm+log+scale with line='+line) | |
plt.show() | |
pp = sm.ProbPlot(res, dist=stats.norm, fit=True) | |
for line in ['r', 'q', '45', 's']: | |
fig, (ax1, ax2, ax3) = plt.subplots(nrows=3, ncols=1) | |
pp.qqplot(ax1, line=line) | |
pp.ppplot(ax2, line=line) | |
pp.probplot(ax3, line=line) | |
fig.suptitle('Norm+fit with line='+line) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment