Usage for linfit

Return to directory of Todd's CASA extensions

Basic linear function fitter with error bars in the y-axis data points. Uses scipy.optimize.leastsq(). Accepts either lists or arrays. See also spectralindex. For linear fits with uncertainties in both axes, see orthogonalDistanceRegression.

Usage:

```lf = au.linfit()
lf.linfit(x, y, yerror, pinit=[0.57, 3.4], plot=False, plotfile=None, xlabel=None,
ylabel=None, title=None, residual=False, excludeXrange=[], returnResiduals=False)
```
• Input:
• x, y: x and y axis values
• yerror: uncertainty in the y-axis values
• pinit contains the initial guess of [slope, intercept]
• residual: if True, show the residual of the fit in second panel
• excludeXrange: exclude a range of x-axis values when doing the fit e.g. [109,116] to avoid 109-116 GHz points
• returnResiduals: if True, return [slope,intercept,data-fit]
• Output:
• The fit result as: [slope, y-intercept], or [slope, y-intercept, data-fit]

Example:

```CASA<5> lf = au.linfit()
CASA<6> x = [1,2,3,4,5]
CASA<7> y = [.43,.96,1.24,1.67,1.86]
CASA<8> yerror = [0.1,0.1,0.1,0.2,0.2]
CASA<9> lf.linfit(x, y, yerror, xlabel='my x label', ylabel='my y label', title='test', plotfile='test.png', plot=True)
Out[9]: array([ 0.31652522,  0.30612593])
```

-- ToddHunter - 2012-09-10
• test.png:

Topic attachments
I Attachment Action Size Date Who Comment
png test.png manage 24 K 2012-09-10 - 16:27 ToddHunter
This topic: ALMA > TWikiUsers > ToddHunter > CasaExtensions > Linfit
Topic revision: 2014-09-02, ToddHunter
Copyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding NRAO Public Wiki? Send feedback