Skip to main content

Diagnostic Plots for Lineare Regression Models. Similar to plot.lm in R.

Project description

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.

Fitted Model from Linearmodels <https://bashtage.github.io/linearmodels/doc/index.html> should also work, however, that’s not tested very well.

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.

‘Programming Language :: Python :: 3.6’,

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…

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lmdiag-0.3.7.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

lmdiag-0.3.7-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file lmdiag-0.3.7.tar.gz.

File metadata

  • Download URL: lmdiag-0.3.7.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.4.2 requests/2.21.0 setuptools/41.1.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.7.5

File hashes

Hashes for lmdiag-0.3.7.tar.gz
Algorithm Hash digest
SHA256 ba4e886900b8807b2b3d4cefd39fc54ea6ff9529cf383d7ae4e55012d456250d
MD5 a59729b7ffce253ba7d07e5e10918c83
BLAKE2b-256 f0508839a91a33a95a177607015c862ca7284c7e49bc0d6e360b7e60bb0d006e

See more details on using hashes here.

File details

Details for the file lmdiag-0.3.7-py3-none-any.whl.

File metadata

  • Download URL: lmdiag-0.3.7-py3-none-any.whl
  • Upload date:
  • Size: 7.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.4.2 requests/2.21.0 setuptools/41.1.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.7.5

File hashes

Hashes for lmdiag-0.3.7-py3-none-any.whl
Algorithm Hash digest
SHA256 b739b30322ac52b27c28a3e672c7faa0161254ae5badea09ff4aaeff55b77d4b
MD5 996b88959f0b14d99175d74531c3432a
BLAKE2b-256 db768b15c0e5065156fa776fe117877a18ff91f2218fb35d79d70b9b5de25a59

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page