A mini course for Ordinary Least Squares using statsmodels and Python. Part 1

This is Part 1 of a course in ordinary least squares for Python programmers using statsmodels with Python methods for graphics, standard errors, average marginal effects, and average margins.

Part 1 includes annotated regression output, goodness of fit, coefficient interpretation, post-regression analysis, heteroskedasticity, and predictions. Part 1 includes a cheat sheet for calculating marginal effects for various functional forms. Part 1 also includes the derivation of OLS in matrix form, finite sample properties, and the OLS variance-co-variance matrix. Finally, Part 1 includes a solution for Stata-like Average Marginal Effects for quantitative regressors, interactions, and quadratics. Average Marginal Effects and Average Margins are not natively supported by statsmodels.

There are three appendices in Part 1 for general reference.

  • A marginal effects cheat sheet for various functional forms includes derivations of the marginal effects for commonly used functional forms.

  • OLS in matrix form includes the derivation of the OLS equations in matrix form, the finite sample properties of OLS, and the OLS variance-covariance matrix.

  • The equivalence of OLS and maximum likelihood estimation. The model coefficients estimated by OLS are identical to those estimated using Maximum Likelihood Estimation (MLE) because maximizing the likelihood function is equivalent to minimizing the sum of the squared residuals for OLS.

This appendix derives the likelihood function for OLS and shows that the OLS and maximum likelihood parameter estimates are identical. This section also derives the maximized log-likelihood, which appears in regression output.

An ideal companion to any course with a significant OLS component. Important topics are clearly explained and illustrated with practical examples.

See also Part 2. Part 2 focuses on categorical independent variables.

This is a free download.

Send comments and suggestions to talk@mlbridgeresearch.com or contact me on LinkedIn: www.linkedin.com/in/thomasmckennon59983316a.

Date Published: 10.2023
Pages: 140
Version: v2 (final)