REGRESS

The REGRESS function performs a multiple linear regression fit and returns an Nterm -element column vector of coefficients.

REGRESS fits the function:

y i  =  const + a 0 x 0, i + a 1 x 1, i + ... + a Nterms-1 x Nterms-1, i

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

Calling Sequence

Result = REGRESS( X, Y, Weights [, Yfit, Const, Sigma, Ftest, R, Rmul, Chisq, Status] )

Arguments

X

An Nterms by Npoints array of independent variable data, where Nterms is the number of coefficients (independent variables) and Npoints is the number of samples.

Y

An Npoints -element vector of dependent variable points.

Weights

An Npoints -element vector of weights for each equation. For instrumental (Gaussian) weighting, set Weights i  = 1.0/standard_deviation( Y i ) 2 . For statistical (Poisson) weighting, Weights i  = 1.0/ Y i . For no weighting, set Weights i  = 1.0, and set the RELATIVE_WEIGHT keyword.

Yfit

A named variable that will contain an Npoints -elements vector of calculated values of Y .

Const

A named variable that will contain the constant term.

Sigma

A named variable that will contain the vector of standard deviations for the returned coefficients.

Ftest

A named variable that will contain the value of F for test of fit.

R

A named variable that will contain the vector of linear correlation coefficients.

Rmul

A named variable that will contain the multiple linear correlation coefficient.

Chisq

A named variable that will contain a reduced, weighted chi-squared.

Status

A named variable that will contain the status of the internal array inversion computation. Status will contain 0 (zero) if the array was successfully inverted. Status will contain the integer 1 (one) if the array was not successfully inverted because it is singular. Status will contain the integer 2 (two) if there is a possibility that the result of the inversion--and the resulting coefficients returned by REGRESS--is inaccurate due to the use of a small pivot element.

Keywords

RELATIVE_WEIGHT

If this keyword is set, the input weights (the W vector) are assumed to be relative values, and not based on known uncertainties in the Y vector. Set this keyword in the case of no weighting.

Example

X = [[0.0, 0.0], $ ; Create a two by six array of independent variable data.

     [2.0, 1.0], $

     [2.5, 2.0], $

     [1.0, 3.0], $

     [4.0, 6.0], $

     [7.0, 2.0]]

Y = [5.0, 10.0, 9.0, 0.0, 3.0, 27.0] ; Create an Npoints-element vector of dependent variable data.

weights = REPLICATE(1.0, N_ELEMENTS(Y)) ; Create an Npoints-element vector of uniform weights.

result = REGRESS(X, Y, weights, yfit, const, /RELATIVE_WEIGHT)
; Compute the fit using multiple linear regression

PRINT, const, result[0], result[1] ; Print the coefficients of the regression model.

IDL prints:

5.00000 4.00000 -3.00000

See Also

CURVEFIT , GAUSSFIT , LMFIT , POLY_FIT , POLYFITW , SFIT , SVDFIT