Skip to content

cristobal-sifon/lnr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

64 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Linear regression functions

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages