Skip to main content

Linear regression of data sets with correlated and uncorrelated uncertainties.

Project description

Mahon linear regression

pypi tests Coverage Status pre-commit.ci status License: MIT Code style: black

The goal of this project is to provide a python package that allows to calculate linear regressions on data sets with uncertainties. Linear regressions can be performed for correlated and uncorrelated uncertainties. The calculations follow the methodology published by Mahon (1996). Typographical errors that were made in that work have been corrected. A method to allow calculating a linear regression through a fixed point, avoiding previously made errors, is also provided.

Installation

The package can be installed from pypi via:

pip install mahon

Usage

Below is an example on how to use the package.

>>> import numpy as np
>>> from mahon import LinReg

>>> # some data
>>> xdata = np.array([1, 2, 3.1, 4.9])
>>> ydata = np.array([1.1, 1.9, 3, 5.5])

>>> # some uncertainty and correlation
>>> xunc = 0.05 * xdata
>>> yunc = 0.073 * ydata
>>> rho = np.zeros_like(xdata) + 0.5

>>> # do regression
>>> my_reg = LinReg(xdata, xunc, ydata, yunc, rho)

>>> # print out the parameters and their uncertainties
>>> my_reg.slope
(0.9983617286559998, 0.0684389236571533)
>>> my_reg.intercept
(0.05545339135826666, 0.11811730191506546)
>>> my_reg.mswd
2.5105964767246842

A detailed example for correlated and uncorrelated uncertainties, and fixed point linear regressions can be found in this Jupyter notebook.

Development & Contributing

If you would like to contribute, clone the GitHub repo and then install the package locally from within the folder via:

pip install -e .[dev]

If you also want to install the full test environment, run:

pip install -e .[dev,test]

Code auto formatting is implemented using pre-commit hooks. Full testing of the package can be done with nox.

Please feel free to raise issues on GitHub and open pull requests if you have a feature to be added. Tests and adequate docstrings should be provided along with your new code.

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

mahon-0.1.0.tar.gz (13.4 kB view details)

Uploaded Source

Built Distribution

mahon-0.1.0-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file mahon-0.1.0.tar.gz.

File metadata

  • Download URL: mahon-0.1.0.tar.gz
  • Upload date:
  • Size: 13.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.27.1

File hashes

Hashes for mahon-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6423d37d08110e12181b0627593253319028730d225b1b29f2a2c599dfe447de
MD5 687d3addcced7f79b998725d82d17b6d
BLAKE2b-256 685d7d7b7c306780acb691aba509cc3792c4a39b79b2722e7d001ea81e41cc9d

See more details on using hashes here.

File details

Details for the file mahon-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: mahon-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.27.1

File hashes

Hashes for mahon-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 593007562b4b808f2722af4df359b87f1979396ae5ba9f4005317a9a23023102
MD5 1d2c05f5f33a95c21136e45891f4ecfc
BLAKE2b-256 a5ba16c4ab20851f80890425c7682aa63f87384f5037cab988ffc11159363eef

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