Version 1.8 (1996 July 17)
LFIT is a general interactive tool for performing simple linear least-squares fits to X and Y data, with or without uncertainties. Below is a brief description of how to run LFIT. It is assumed that the user is at least conversant in the general theory and practice of least-squares fitting (e.g., as described by Bevington or in Numerical Recipes).
LFIT wants data in the form of ASCII tables organized into columns with no blank lines. A typical file of (x,y,sigma-y) data pairs might look like
2.00 3.45 0.01 14.5 3.00 4.53 0.02 16.7 4.00 5.39 0.01 -18.6 ...where the columns are separated by one or more spaces, and the data values are valid floating-point numbers. TABS or commas (,) are not recognized by LFIT as "separator" characters.
Data files must contain at least 2 columns (for a minimal unweighted LSF) up to a maximum of 20 columns. Data files may contain no more than 2048 lines of data, and (x,y,sigma-y) data sets must be contiguous (i.e., you cannot combine columns of numbers).
Data files may contain headers at the very top of the file. As part of the data entry dialog described below, you can specify how many lines at the top of a file to skip before reading in the data. However, there may be no header lines anywhere else in the file.
[Index]
If LFIT is installed on your machine, it should be in the directory
/usr/local/pkg/bin/lfitIf so, then to run LFIT, go to the directory with your data files and type:
lfitYou will see the welcome message with the latest release number and date:
LFIT - Interactive Linear Least Squares (Version 1.8 - 1996 July 17)and receive the first prompt:
LickMongo Terminal Type <1:14> [11] ?The default LickMongo terminal type is an X11 workstation window. You can accept the default by just hitting the Enter key (any item in []'s is the default response). If you are on another device (like a PC running em4010), you will need to type in here another device code. See the LickMongo Manual for the valid device codes.
If you are running X-windows, hitting Enter will pop up an X11 graphics window. You may resize this window using the mouse at this time.
[Index]
The next prompt asks for the name of the ASCII file with the data to be examined:
Input File Name ?Input data files are organized like SM or LickMongo files: ASCII format with the data organized into columns of numbers separated by spaces or TABs. If there are multiple TABs, LFIT's parser can sometimes get confused, so it is recommended that you strip out TAB characters before running (or to not use TABs to start with).
Files must have a MINIMUM of 2 data columns, one each for X and Y. Often a third column will have the uncertainty (SigmaY) of the Y data. You cannot have blank entries in a column, so if your data arrays have blanks, either edit them out before running LFIT, or make a third SigmaY column in which the valid data have SigmaY=1.0, and the "blank" lines have SigmaY=0.0 You may have up to 10 columns in a file, with the data (X,Y,SigmaY) in any order.
There is no default filename, so you have to type in the full filename at the prompt:
Input File Name ? fene.datand hit the Enter key. If the file you want is not in the current working directory, you also have to include the full directory path.
Note that if you want out now, typing "abort" followed by Enter at this prompt will quit LFIT and return you to the Unix prompt.
The next question it asks if there are any non-data or "header" lines at the top of the file that need to be skipped before getting to the data lines:
Does the File contain header lines to skip <y|n> [n] ?LFIT can only handle files with one set of header lines at the very top. Files which contain multiple data sets separated vertically by headers or line breaks must be broken into separate files before running LFIT.
If the file can be read, the header lines (if any) will be skipped and the first line of the file printed on the screen. For example:
First Line of the File: 1 9.40 1.0 1 5881.8999 -0.0041You will then be asked for the columns containing the X, Y data:
X Data Column Number <1:6> [1] ? 2 Y Data Column Number <1:6> [2] ? 5and then you will be asked for the column with the Y error (SigmaY):
Y Error Column (0=unweighted) <0:6> [6] ?If you are doing an unweighted fit, entering 0 will set all data weights to 1.0, otherwise it will use the contents of the data column indicated as SigmaY, and weight the data points by the inverse-square of the errors (i.e., points with smaller sigmas have greater statistical weight).
[Index]
Once the data are read into internal working arrays and you will be presented with the fitting options menu:
** FITTING OPTIONS: 1 -- Line Fit 2 -- Polynomial Fit 3 -- Legendre Polynomials 0 -- QUIT -------------------------------There are presently two possiblities:
[Index]
To fit a line through the data, enter 1 at the prompt above. You will be presented with 4 line fitting options:
** Line Fitting Options: 1 -- Linear (Y vs X) 2 -- Linear/Log (Log Y vs X) 3 -- Power Law (Log Y vs Log X) 4 -- Exponential (Ln Y vs X) 0 -- QUIT ---------------------- Linear Fit Option <0:4> [1] ?The four options are as follows:
Y(X) = A + B*Xwhere B is the slope and A is the Y-intercept.
Log Y(X) = A + B*XThis is the linearized form of the semi-log relation:
Y(X) = a * 10B*Xwhere
a = 10Ais the coefficient of the exponential.
Log Y(X) = A + B*Log Xwhere B is now the power-law slope, and A is just the offset. This is the linearized form of the power-law relation:
Y(X) = a*XBwhere
a = 10Ais the coefficient of the power-law.
Y(X) = a * exp(B*X)where
a = exp(A)is the exponential coefficient. This fitting form would be appropriate if analyzing cooling data for a CCD Dewar or radioactive decay data. In this case, the slope, B, is the inverse of the e-folding parameter.
[Index]
To fit a polynomial to the data of the form:
Y(X) = A(0) + A(1)*X + A(2)*X2 + A(3)*X3 + ...select Option 2 at the FITTING OPTION prompt. You will then be asked for the order of the fit:
Polynomial Order <1:9> [1] ?Order=1 is the same as doing a line fit. Order=2 is a quadratic, Order=3 is a cubic, and so forth. The maximum fit order is 9, however you can change the fit order interactively to refine your fit later after looking at the residuals.
[Index]
After selecting the fitting function, LFIT will compute the best fit using linear least squares. Note that even if fitting a polynomial function, the fit is still "linear" in the sense that the function is linear in the fit coefficients (in the more formal language of numerical analysis, the fit is computed by solving a system of "linear equations of condition" in which the unknowns are the fit coefficients, not the data themselves which are known). When the best fit has been computed, the results are first printed on the terminal screen.
For example, here I have fit a 3rd order polynomial to a set of wavelength calibration lamp data, where Y is the laboratory wavelength, and X is the central pixel of the lines. In this case I have done an unweighted fit, with the goal of finding the dispersion formula for this spectrograph, giving the wavelength associated with each pixel, X.
** Polynomial Fit: Y(x) = 5863.30 +/- 0.417506 +( 1.98894 +/- 6.031907E-03)*X +( 5.663378E-05 +/- 2.405902E-05)*X^2 -( 4.335774E-08 +/- 2.647130E-08)*X^3 Reduced Chi-Squared: 0.229757 Unbiased Mean Variance: 0.229757 Unbiased Mean Deviation: 0.479330The fit coefficients are given with their formal uncertaintes, written in an equation form. In this example, the starting wavelength found is 5863.3+/-0.42 Angstroms, the linear dispersion is 1.989+/-0.006 Ang/pixel, plus 2nd and 3rd order dispersion terms.
The three last parameters give some idea of the quality of the fit:
[Index]
After printing the results, it also displays the best-fit graphically, plotting the plot the data, any error bars (if doing a weighted fit), and the best fit line. After the fit is displayed, the graphics cursor is activated and the program enters the Interactive Fitting Mode. When the mouse (or graphics pointer if on a graphics terminal of some kind) is on the plot, you have the following cursor key commands. Note that on a workstation, if your mouse pointer is in the text window, these commands will not work.
LFIT Cursor Commands: Key Function --------------------------------------------- P Refresh the current plot R Toggle between Data and Residuals X Change plotting limits H Hardcopy (PostScript) of current plot O Change polynomial order and re-fit S Sigma-reject data points and re-fit E Edit data points with cursor & re-fit F Compute the best fit L Change line fitting function G Get other data from current data file N Open a new data file A Change axes of linear fitting > Dump results to an ascii file Q Quit interactive fitting ! OOPS! Restore Original Data ? Print this help list <ESC> ABORT, exiting the program ---------------------------------------------Particularly useful commands for examining and refining your fit are:
If you are satisfied with the fit, typing "Q" will exit interactive mode and return you to the LFIT menus. Note that there are a number of commands to allow you to toggle between viewing the best fit and the residuals, editing (removing or restoring) outlying data from the fit, auto-reject points based on their deviation from the fit it units of the computed unbiased mean deviation (see above), changing the plotting scale, changing the fitting function (e.g., changing the polynomial order), making a hardcopy, dumping to an ASCII results file, and so forth. Experiment around with these to find the best way to use them with your data (and individual tastes in fitting).
[Index]
Once you quit interactive mode (Q), you are given the following options menu:
** Clean-Up Options: 1 -- Change Fit Params 2 -- New Data/Same File 3 -- Open a New File 0 -- QUIT ---------------------------- Option <0:3> [0] ?The options are as follows:
[Index]
Caltech undergraduate alumni who took the infamous Ph3 any time after about 1984 will notice a number of affinities between "ffit" and LFIT, but in fact LFIT predates "ffit" by about 4 years. The first version of LFIT was LFIT.FOR written on a Dec10 at Caltech in October 1979, when I was taking Ph3. This was before any IBM PC computers showed up in the undergrad labs (after 1983). The original fitting algorithms were based on the routines in Bevington (1st edition), as described in Don Skelton's Primer on Data Analysis. LFIT.FOR was ported to a VAX11/780 computer in the Caltech Astronomy department in 1982, where it first broke free of the Tek4010 and used an early version of Tim Pearson's PGPLOT package on a combination of VT100/Retrographics and Grinnell image displays. After moving to UCSC/Lick Observatory in 1983 for graduate school, LFIT was further modified to use Mongo (later LickMongo) for the graphics, especially on VT100/Retro and GraphOn Tek401x emulators. It was ported to SunOS and X-Windows at Ohio State in 1991. Many of the routines from Bevington were replaced by modifications of code from the first edition of Numerical Recipes by then. Finally, it was ported to RedHat Linux in 2000 (which required little modification at that point), where it is now maintained as part of the OSUSpec package of routines.
Astute users will notice that LFIT does not have a terrifically sophisticated user interface. This reflects the origins of the program in the pre-windows days where we were working on Tektronix 4014 graphics terminals (the real green-tube versions, not the later emulators). Maybe someday it will become more GUI-like, but that won't be anytime soon...