LINFIT

The LINFIT function fits the paired data { xi , yi } to the linear model, y = A + Bx, by minimizing the Chi-square error statistic. The result is a two-element vector containing the model parameters [A, B].

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.

Calling Sequence

Result = LINFIT( X, Y )

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 Chi-square error statistic as the sum of squared errors between yi and A + B xi . If individual standard deviations are supplied, then the Chi-square error statistic is computed as the sum of squared errors divided by the standard deviations.

DOUBLE

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

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

An n -element integer, single-, or double-precision floating-point vector that specifies the individual standard deviations for { xi , yi } used for weighting, where the weight is defined as 1/SDEV 2 . If SDEV is not set, no weighting is used.

SIGMA

Set this keyword to a named variable that will contain a two-element vector of probable uncertainties for the model parameters.

Example

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 standard deviations with a constant value of 0.85

sdev = REPLICATE(0.85, N_ELEMENTS(X))

Compute the model parameters, A and B.

PRINT, LINFIT(X, Y, SDEV=sdev)

IDL prints:

[-3.44596, 0.867329]

See Also

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