Last Update: March 22, 2022
My online video tutorials are hosted at YouTube channel.
For learning this concept, you can view my online video tutorials: Normality in Error Term: Q-Q Plot and Jarque-Bera Test in Python (Spyder) and Normality in Error Term: Q-Q Plot and Jarque-Bera Test in Python (Jupyter).
Videos Code
1. Packages
import statsmodels.api as sm
import statsmodels.formula.api as smf
import statsmodels.stats.api as sms
import scipy.stats as st
import matplotlib.pyplot as plt
2. Data
houseprices_object = sm.datasets.get_rdataset(dataname="HousePrices",
package="AER", cache=True)
houseprices = houseprices_object.data
print(houseprices.iloc[:, 0:3].head())
print(houseprices_object.__doc__)
3. Model
mlr = smf.ols(formula="price ~ lotsize + bedrooms",
data=houseprices).fit()
4. Normality
res = mlr.resid
Q-Q Plot
fig = sm.qqplot(data=res, line="q", dist=st.norm)
plt.title("Normal Q-Q Plot")
plt.show()
Jarque-Bera Test
jbtest = sms.jarque_bera(res)
print("JB:", jbtest[0], "JBpv:", jbtest[1])
Courses
My online courses are hosted at Teachable website.
For more details on this concept, you can view my Linear Regression in Python Course.