Reading a summary in Python
Every block of the table answers a different question.
import numpy as np
import statsmodels.api as sm
rng = np.random.default_rng(2)
x = rng.normal(size=(50, 2))
y = 2 + 3 * x[:, 0] - 1.5 * x[:, 1] + rng.normal(0, 0.5, size=50)
model = sm.OLS(y, sm.add_constant(x)).fit()
text = model.summary().as_text()
print(len(text.splitlines()), "lines of summary")
print(round(model.aic, 2), round(model.bic, 2))
print(round(model.mse_resid, 4), model.df_resid, model.df_model)
print(model.tvalues.round(2))
How it works
- The coefficient block is estimate, error, t and p.
- R-squared and F test the model as a whole.
- Durbin-Watson and Jarque-Bera flag assumption problems.
Keywords and builtins used here
aslenprintround
The run, in numbers
- Lines
- 14
- Characters to type
- 446
- Tokens
- 163
- Three-star pace
- 105 tpm
At the three-star pace of 105 tokens a minute, this run takes about 93 seconds.
Step 3 of 3 in Linear models, step 3 of 19 in Statistics with statsmodels.