Skip to main content

lnr

Linear regression tools in python


This code incorporates various prescriptions for linear regression of measurements with uncertainties on both the dependent and independent variables which may be correlated. It also incorporates automatic conversions to logarithmic space in order to fit a power law, if so requested. See Hogg, Bovy & Lang (2010) for considerations on fitting a line to data.

Each function has a detailed help page but, briefly, the available functions are:

lnr.bces(x1, x2, **kwargs)

Bivariate Correlated Errors and intrinsic Scatter (BCES, Akritas & Bershady, 1996). Python code translated from FORTRAN code by Christina Bird and Matthew Bershady.

lnr.kelly(x1, x2, **kwargs)

Python wrapper around the IDL Bayesian linear regression code by Brandon Kelly (2007), that accounts for correlated uncertainties in both variables and intrinsic scatter. Requires pIDLy and an IDL license.

lnr.mle(x1, x2, **kwargs)

Maximum likelihood estimator including intrinsic scatter.

lnr.mcmc(x1, x2, **kwargs)

Perform an MCMC analysis, accounting for intrinsic scatter and using appropriate priors for each parameter (see, e.g., this post, or this one. The MCMC sampling is performed with emcee.

There are additional, auxiliary functions:

lnr.to_log(x, **kwargs)
lnr.to_linear(logx, **kwargs)

convert a given set of measurements and uncertainties between linear and log space, and

lnr.plot(t, a, b, **kwargs)

can be used to plot the best-fit linear relation along with a shaded region representing the best-fit uncertainties. Since this function can take a matplotlib axis as a keyword argument, it can be easily embedded within a larger plotting function that includes, for instance, the data points from which the relation is derived.


Installation

Clone this package with

git clone https://github.com/cristobal-sifon/lnr.git

(you may also fork it to your own github account and then clone your fork). Then, simply type

python setup.py install [--user]

where the --user flag is recommended so that the installation takes place in the home directory and does not require root privileges.

After this, just open a python terminal and type

>>> import lnr

and all the modules described above will be available. Then type, e.g.,

>>> help(lnr.bces)

to get more details.


(c) Cristóbal Sifón Last modified 2018-01-07

Release files for lnr 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 lnr 0.2.0
File Size Uploaded
lnr-0.2.0.tar.gz 14.1 kB Details

Release files / lnr-0.2.0.tar.gz

Download URL lnr-0.2.0.tar.gz
Size 14.1 kB
Tags Source
SHA-256 checksum
How to use checksums
e3e84febf84f32d34de573d13f4b31f4fe725b1e780eb4a1900f36233843d734
BLAKE2b-256 checksum
How to use checksums
bfb7242956abb9a9c1f1cff15624f70c2799852086242d6c7c6c8cdc2ebe5930
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.12

Release history Release notifications | RSS feed

This release

0.2.0 This release

1 release file

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