Inference

conf_int and pvalues.

conf_int and pvalues are the usual printout. Tiny n makes p-values noisy — that is part of the lesson.

Goal

Print the 95% interval for the slope.

import pandas as pd
import statsmodels.api as sm
df = pd.DataFrame({'units': [12, 9, 3, 7, 11, 8], 'shillings': [126, 94.5, 31.5, 73.5, 115.5, 84]})
fit = sm.OLS(df['shillings'], sm.add_constant(df['units'])).fit()
print(fit.conf_int().round(3))
print(fit.pvalues.round(4).to_dict())
import pandas as pd
import statsmodels.api as sm
fit = sm.OLS([2, 4, 6, 8], sm.add_constant([1, 2, 3, 4])).fit()
print(fit.tvalues.round(3).to_dict())
import pandas as pd
import statsmodels.api as sm
print(sm.OLS([1, 2, 3], sm.add_constant([1, 2, 3])).fit().nobs)
import pandas as pd
import statsmodels.api as sm
print(sm.OLS([1, 3, 2], sm.add_constant([0, 1, 2])).fit().df_resid)