Table of Contents
tablsqfit - general purpose least squares fitting program
tablsqfit takes a least squares
fit (minimized ChiSquared) of a set of datapoints (x(i),y(i)) where a functional
form y=f(x;a1,a2,...,an) is assumed. The functional form to be fitted has to
be specified by name at this stage. A number of options are possible.
inputfile is an ascii file in a tabular format, where on every line there
must be an assigned column for the X- and Y-coordinates. An optional column
can be assigned to the errors in Y (the DY-coordinates). If no DY-column is
assigned, it is assumed that the errors in Y are all the same and equal
to 1. Lines starting with the ’#’ symbol are comment lines. Certain models
(see fit= below) allow multiple X or Y columns. For fit=line a proper goodness-of-fit
is also computed in a second fit an error column (dycol=) is given.
most linear functions the non-linear version of this program will also work
fine, and has the added power that certain parameters can be fixed, and
error estimates are returned. See tabnllsqfit(1NEMO)
parameters are recognized in any order if the keyword is also given:
Here is an example of creating an on-the-fly
table with a straight line, with some added noise and random weights between
1 and 2:
- (ascii) input file, a table of values from which data is taken. No default.
- The column(s) from which the (independant) X-values are taken.
The first column is called 1 by definition [default: 1].
- The column(s)
from which the (dependant) Y-values are taken [default: 2].
column from which the DX-values (errors in X) are taken. Currently only
a straight line fit can use this option. See below.
- Optional column
from which the DY-values (errors in Y) are taken. The inverse square of the
errors are uses as weights for those fits where these are used [default:
- Range in X-values for which the fit is done.
If only one number is given, the other one is considered zero. [default:
no entry, i.e. all].
- Model name what to fit. Currently implemented
are line, plane, poly, ellipse, peak, zero, imageshift, area, gauss1d,
and gauss2d. [default: line].
- Highest order of the polynomial
fit (fit=poly) or dimension of the hyper-plane fit (fit=plane). 0 would
fit a constant. 0 and 1 would have the same meaning in both the plane and
poly cases [Default: 0].
- Optional output filename (only active
under certain options) where the data and residuals are stored. Column 1,
2 and 3 will contain the X, Y and residuals F(X)-Y respectively. A future
release will also store the errors (if it was given, see keyword dycol
above) in the 4th column. [default: empty, no output file created].
- A positive number will delete points more than sigma_factor from the fit,
and fit again. [Default: -1].
- Optional estimate for parameters of
- Maximum number of lines allocated if the
input file was being read from a pipe. If not, the routine file_lines(3NEMO)
is used to allocate space for the table. [Default: 10000].
fitting mode in which mpfit(3NEMO)
is used. 0=no errors. 1=only errors in
X used (dxcol=), 2=only errors in Y used (dycol=), 3=errors in both X
and Y used. See also linreg(1NEMO)
- Output results in simple tabular
format. Default: false.
% nemoinp 1:100 | tabmath - - "%1+rang(0,10),ranu(1,2)" seed=123 | tablsqfit
a = 0.974146 uncertainty: 0.039389
b = 1.755022 uncertainty: 2.291149
x0 = -1.801599 uncertainty: 2.353083
y0 = 1.755022 uncertainty: 2.291149
goodness-of-fit: 1.000000 (no Y errors supplied [dycol=])
The fitted line is written either as y=ax+b or alternatively with their
(x0,y0) intercepts as x/x0 + y/y0=1.
Numerical Recipies in
Craig B. Markwardt)
Data analysis recipes:
Fitting a model to data P (Hogg, Bovy & Lang 2010)
5-Aug-87 V1.0 created PJT
18-May-88 V1.4 various new options PJT
31-May-88 V2.0 ’float’-> ’double’ for NumRec PJT
14-nov-91 V2.4 ellips fit and various others PJT
13-Mar-92 V2.5 added imageshift option PJT
15-nov-93 V2.6 added nmax= PJT
13-jun-94 V2.7 code overhaul to add line/poly PJT
8-jun-95 V2.8 added option fit=peak PJT
26-jan-98 V2.9 added goodness-of-fit for fit=line PJT
4-feb-98 V2.9a compute r (corr.coeff.) for line fit PJT
14-aug-00 V3.0 added tab= PJT
8-aug-01 V3.1c added area, using natof, error in ellipse PJT
24-feb-03 V3.4: added fit=zero PJT
21-nov-05 V3.4b: added fit=gauss1d,gauss2d PJT
9-dec-09 V4.0: added xcol= and mpfit= PJT
Table of Contents