The REGRESS function performs a multiple linear regression fit and returns an Nterm -element column vector of coefficients.
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.
Result = REGRESS( X, Y, Weights [, Yfit, Const, Sigma, Ftest, R, Rmul, Chisq, Status] )
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.
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.
A named variable that will contain the vector of standard deviations for the returned coefficients.
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.
X = [[0.0, 0.0], $ ; Create a two by six array of independent variable data.
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.