Skip to main content

Various linear regression modules

Project description

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

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

lnr-0.2.0.tar.gz (14.1 kB view details)

Uploaded Source

File details

Details for the file lnr-0.2.0.tar.gz.

File metadata

  • Download URL: lnr-0.2.0.tar.gz
  • Upload date:
  • Size: 14.1 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for lnr-0.2.0.tar.gz
Algorithm Hash digest
SHA256 e3e84febf84f32d34de573d13f4b31f4fe725b1e780eb4a1900f36233843d734
MD5 1d7132a53068640ed770f65f36a2bbb8
BLAKE2b-256 bfb7242956abb9a9c1f1cff15624f70c2799852086242d6c7c6c8cdc2ebe5930

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page