Skip to main content

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

Project description

lmdiag
=======

**Python Library providing Diagnostic Plots for Lineare Regression Models.** (Like `plot.lm <https://www.rdocumentation.org/packages/stats/versions/3.5.0/topics/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 <https://www.statsmodels.org/dev/generated/statsmodels.regression.linear_model.OLS.fit.html>`_ created by statsmodels as input.

Example
........
(See also the more extensive `Example Notebook <https://github.com/dynobo/lmdiag/blob/master/example.ipynb>`_)

::

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);


.. image:: 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
..............
.. image:: https://raw.githubusercontent.com/dynobo/lmdiag/master/badge.png

Packaging and Upload to PyPi
............................

- ``rm -rf ./dist`
- ``python setup.py sdist``
- ``python setup.py bdist_wheel``
- ``twine upload dist/*``


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.1.5.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

lmdiag-0.1.5-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: lmdiag-0.1.5.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for lmdiag-0.1.5.tar.gz
Algorithm Hash digest
SHA256 93bef92d78e547a8ac48ad126afeb86f4aeec597c582de4d6b100ddc78956a49
MD5 d9a51a7288551f6410732d5462b6c292
BLAKE2b-256 467ebff0c0b98d3e5a6a74dc2bbcf0d815fb6cb6fce669f022e0e862681c843b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lmdiag-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 a5628174c5ba5d9f10a8c0ee0bdc9dcf55940d272a90f40d841592620068f59d
MD5 6ec9763407253a22cf9427df0c2d8989
BLAKE2b-256 df394daa6c97038a4b7cd3109408191295bafeb9443a5492faf0b1b154f087bd

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