Skip to main content

lmdiag

Python Library providing Diagnostic Plots for Lineare Regression Models. (Like plot.lm in R.)

I built this, because I missed the diagnostics plots of R for a university project. There are some substitutions in Python for individual charts, but they are spread over different libraries and sometimes don’t show the exact same. My implementation tries to copycat the R-plots, but I didn’t reimplement the R-code: The charts are just based on available documentation.

Installation

Available in PyPi: https://pypi.org/project/lmdiag/

  • Using pip: pip install lmdiag

  • Using pipenv: pipenv install lmdiag

Usage

The plots need a fitted Linear Regression Model created by statsmodels as input.

Example

(See also the more extensive Example Notebook)

import numpy as np
import matplotlib.pyplot as plt
import statsmodels.api as sm
import lmdiag

%matplotlib inline  # In Jupyter

# Generate sample model
np.random.seed(20)
predictor = np.random.normal(size=30, loc=20, scale=3)
response = 5 + 5 * predictor + np.random.normal(size=30)
X = sm.add_constant(predictor)
lm = sm.OLS(response, X).fit()

# Plot chart matrix (and enlarge figure)
plt.figure(figsize=(10,7))
lmdiag.plot(lm);
https://raw.githubusercontent.com/dynobo/lmdiag/master/example.png

Methods

  • Draw matrix of all plots:

    lmdiag.plot(lm)

  • Draw individual plots:

    lmdiag.resid_fit(lm)

    lmdiag.q_q(lm)

    lmdiag.scale_loc(lm)

    lmdiag.resid_lev(lm)

  • Print useful descriptions for interpretations:

    lmdiag.info() (for all plots)

    lmdiag.info('<method name>') (for individual plot)

Development

Disclaimer

This is my very first public python library. Don’t expect everything to work smoothly. I’m happy to receive useful feedback or pull requests.

Certification

https://raw.githubusercontent.com/dynobo/lmdiag/master/badge.png

Packaging and Upload to PyPi

  • pipenv run rstcheck README.rst (check syntax)

  • rm -rf ./dist (delete old builds)

  • python setup.py sdist

  • python setup.py bdist_wheel

  • twine upload dist/*

  • Then new release on github…

Metadata

Release files for lmdiag 0.1.666666

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for lmdiag 0.1.666666
File Size Uploaded
lmdiag-0.1.666666.tar.gz 6.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for lmdiag 0.1.666666
File Interpreter ABI Platform
lmdiag-0.1.666666-py3-none-any.whl Python 3 none any Details

Total release size: 12.7 kB

Release files / lmdiag-0.1.666666.tar.gz

Download URL lmdiag-0.1.666666.tar.gz
Size 6.1 kB
Tags Source
SHA-256 checksum
How to use checksums
8ddd7a97756185d8f98670550818425cff8c8d0676e6ab38e2140b4d36744127
BLAKE2b-256 checksum
How to use checksums
fcbebaec5eed42c82556884b9ecb368dd94b13fbc0947eec0cb52c8686f8ae66
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / lmdiag-0.1.666666-py3-none-any.whl

Download URL lmdiag-0.1.666666-py3-none-any.whl
Size 6.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e0e44d7ac021aa257f6c8581ccff9476268696a5b8dda2122e84ba71e63bf741
BLAKE2b-256 checksum
How to use checksums
c3187d3f1ee1831199d289d3154df460afbcadc905a8f02051ae6c2d81aadc1e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

0.4.1

2 release files

0.4.0

2 release files

0.3.7

2 release files

0.3.0

2 release files

0.2.0

2 release files

This release

0.1.666666 This release

2 release files

0.1.5

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page