Categories | Alphabetical | Classes | All Contents | [ < ] | [ > ]

LINFIT


Syntax | Return Value | Arguments | Keywords | Examples | Version History | See Also

The LINFIT function fits the paired data {xi, yi} to the linear model, y = A + Bx, by minimizing the chi-square error statistic.

This routine is written in the IDL language. Its source code can be found in the file linfit.pro in the lib subdirectory of the IDL distribution.

Syntax

Result = LINFIT( X, Y [, CHISQ=variable] [, COVAR=variable] [, /DOUBLE] [, MEASURE_ERRORS=vector] [, PROB=variable] [, SIGMA=variable] [, YFIT=variable] )

Return Value

The result is a two-element vector containing the linear model parameters [A, B].

Arguments

X

An n-element integer, single-, or double-precision floating-point vector.

Y

An n-element integer, single-, or double-precision floating-point vector.

Keywords

CHISQ

Set this keyword to a named variable that will contain the value of the chi-square goodness-of-fit.

COVAR

Set this keyword to a named variable that will contain the covariance matrix of the coefficients.

Note
The COVAR matrix depends only upon the independent variable X and (optionally) the MEASURE_ERRORS. The values do not depend upon Y. See section 15.4 of Numerical Recipes in C (Second Edition) for details.

DOUBLE

Set this keyword to force the computation to be done in double-precision arithmetic.

MEASURE_ERRORS

Set this keyword to a vector containing standard measurement errors for each point Y[i]. This vector must be the same length as X and Y.

Note
For Gaussian errors (e.g., instrumental uncertainties), MEASURE_ERRORS should be set to the standard deviations of each point in Y. For Poisson or statistical weighting, MEASURE_ERRORS should be set to SQRT(ABS(Y)).

PROB

Set this keyword to a named variable that will contain the probability that the computed fit would have a value of CHISQ or greater. If PROB is greater than 0.1, the model parameters are "believable". If PROB is less than 0.1, the accuracy of the model parameters is questionable.

SDEV

The SDEV keyword is obsolete and has been replaced by the MEASURE_ERRORS keyword. Code that uses the SDEV keyword will continue to work as before, but new code should use the MEASURE_ERRORS keyword. The definition of the MEASURE_ERRORS keyword is identical to that of the SDEV keyword.

SIGMA

Set this keyword to a named variable that will contain the 1-sigma uncertainty estimates for the returned parameters

Note
If MEASURE_ERRORS is omitted, then you are assuming that a straight line is the correct model for your data, and therefore, no independent goodness-of-fit test is possible. In this case, the values returned in SIGMA are multiplied by
SQRT(CHISQ/(N-M)), where N is the number of points in X, and M is the number of coefficients. See section 15.2 of Numerical Recipes in C (Second Edition) for details.

YFIT

Set this keyword equal to a named variable that will contain the vector of calculated Y values.

Examples

; Define two n-element vectors of paired data: 
X = [-3.20, 4.49, -1.66, 0.64, -2.43, -0.89, -0.12, 1.41, $ 
      2.95, 2.18, 3.72, 5.26] 
Y = [-7.14, -1.30, -4.26, -1.90, -6.19, -3.98, -2.87, -1.66, $ 
     -0.78, -2.61, 0.31, 1.74] 
 
; Define an n-element vector of Poisson measurement errors: 
measure_errors = SQRT(ABS(Y)) 
 
; Compute the model parameters, A and B, and print the result: 
result = LINFIT(X, Y, MEASURE_ERRORS=measure_errors) 
PRINT, result 

IDL prints:

-3.16574    0.829856 

Version History

Introduced: 4.0

See Also

COMFIT, CURVEFIT, GAUSSFIT, LADFIT, LMFIT, POLY_FIT, REGRESS, SFIT, SVDFIT


Categories | Alphabetical | Classes | All Contents | [ < ] | [ > ]