Linear Regression for data set with correlated or uncorrelated uncertainties in both axes.
Project description
CEREsFit
The goal of CEREsFit (Correlated Errors Regression Estimate Fit) is to provide a python package that allows to calculate linear regressions on data sets with correlated uncertainties. The calculations follow the methodology published by Mahon (1996). Typos and 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 ceresfit
Usage
Below is an example on how to use the package.
>>> import numpy as np
>>> from ceresfit 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.9983613298400896, 0.06844666435449052)
>>> my_reg.intercept
(0.05545398718611372, 0.11812746374874884)
>>> my_reg.mswd
2.5105964767071143
Detailed example on how to use the class for fitting and plotting the results can be found in these Jupyter notebooks.
Development & Contributing
This project is developed using Rye. After cloning, you can simply run
rye sync
in the project folder and you should be good to go.
Code auto formatting is implemented using
pre-commit
hooks.
For local formatting and linting, please use
rye fmt
rye lint
For running tests, use:
rye test
rye run test_docs
The first of these commands runs pytest
,
the second checks the documentation tests using xdoctest
.
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file ceresfit-0.3.1.tar.gz
.
File metadata
- Download URL: ceresfit-0.3.1.tar.gz
- Upload date:
- Size: 128.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 761b5f677763070bd83155f613d4a32cd891f61d4a0b3b69732fdc7e155f6863 |
|
MD5 | c646ba2698c40da9b5bde6ee446c7067 |
|
BLAKE2b-256 | 01e6f27fb60a558ae0af867df7fe6109efa1cd7bd4c8a88946849f094df59809 |
File details
Details for the file ceresfit-0.3.1-py3-none-any.whl
.
File metadata
- Download URL: ceresfit-0.3.1-py3-none-any.whl
- Upload date:
- Size: 10.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3b66e42bc51ce55a8a39bd4492b4f2124f2d3942da22c37d7916e6023c4a5015 |
|
MD5 | a54db509b06239e04f2709150ff8a7a8 |
|
BLAKE2b-256 | 23da9b6a99051f703d59100b1bc7b133f4eef18ec0dc39e5cdd26a18b9e84136 |