image_output_1.png
from statsmodels.graphics.gofplots import ProbPlot

import matplotlib.pyplot as plt

import numpy as np

import pandas as pd

import seaborn as sns

import statsmodels.api as sm

df = pd.read_csv('../input/ehresp_2014.csv', usecols=['erbmi', 'euexfreq', 'euwgt', 'euhgt', 'ertpreat'])

df = df[df['erbmi'] > 0]

x = df[['euexfreq', 'euwgt', 'euhgt', 'ertpreat']]
y = df['erbmi']
x = sm.add_constant(x)
model = sm.OLS(y, x).fit()

# statsmodels Q-Q plot on model residuals
QQ = ProbPlot(model.resid)
fig = QQ.qqplot(alpha=0.5, markersize=5, line='s')
plt.title('QQ plot');

model_norm_resid = model.get_influence().resid_studentized_internal
model_norm_resid_abs_sqrt = np.sqrt(np.abs(model_norm_resid))

model_leverage = model.get_influence().hat_matrix_diag
plt.xlim(xmin=-0.0005, xmax=0.013)

model.summary()

model2 = sm.GLM(y, x, family=sm.families.Gaussian()).fit()

fig = plt.figure(figsize=(12, 8))
fig = sm.graphics.plot_partregress_grid(model, fig=fig)