Skip to main content

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

Detailed example on how to use the class for fitting and plotting the results 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.

Metadata

Release files for mahon 0.2.0

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

Source distribution (sdist)

Source distribution for mahon 0.2.0
File Size Uploaded Provenance Actions
mahon-0.2.0.tar.gz 21.6 kB Without provenance Details for mahon-0.2.0.tar.gz

Built distribution (wheel)

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

Total release size: 31.2 kB

Release files / mahon-0.2.0.tar.gz

Download URL mahon-0.2.0.tar.gz
Size 21.6 kB
Tags Source
SHA-256 checksum
How to use checksums
0ec230904f959fba6bcd1a9f9d5a51acbde6eaa7579c8597dc1f2474dc12e75b
BLAKE2b-256 checksum
How to use checksums
180c450fcbc3e4240e6e4021bb28a7f9d010ee3f8933113eb6a81432ea8aed27
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.27.1

Release files / mahon-0.2.0-py3-none-any.whl

Download URL mahon-0.2.0-py3-none-any.whl
Size 9.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3071149eda5d2ec4afdb7a962093fdc8b454eb277310ab27483cb962beebec49
BLAKE2b-256 checksum
How to use checksums
1bdc860801c586b664547419d8342d19a9933a6bbfe208cd43fa820de2b4d9f5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.27.1

Security for mahon 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files No provenance

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