Jupyter notebooks for Linear Models with R, Second Edition in Python

I have translated most of the R code in the book into Python. Sometimes the Python output is similar but not the same. In a few cases, there is no available Python package equivalent to that found with R. I have long experience with R but not so much with Python so any suggestions for more elegant Python would be welcome.

Read more about it in this blog post.

Here are the data as lmrcsv.zip as CSV files.

You will commonly need several Python packages including numpy, scipy, pandas, statsmodels, matplotlib, seaborn, scikit-learn and patsy. I recommend the Anaconda distribution of Python which includes these packages.

  1. Introduction notebook and output

  2. Estimation notebook and output

  3. Inference notebook and output

  4. Prediction notebook and output

  5. Explanation notebook and output. Uses match.py.

  6. Diagnostics notebook and output

  7. Problems with the Predictors notebook and output

  8. Problems with the Error notebook and output

  9. Transformation notebook and output

  10. Model Selection notebook and output

  11. Shrinkage Methods notebook and output

  12. Insurance Redlining - A Complete Example notebook and output

  13. Missing Data notebook and output

  14. Categorical Predictors notebook and output

  15. One Factor Models notebook and output

  16. Models with Several Factors notebook and output

  17. Experiments with Blocks notebook and output