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

REGRESS


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

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

REGRESS fits the function:

yi = const + a0x0, i + a1x1, i + ... + aNterms-1xNterms-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.

Syntax

Result = REGRESS( X, Y, [, CHISQ=variable] [, CONST=variable] [, CORRELATION=variable] [, /DOUBLE] [, FTEST=variable] [, MCORRELATION=variable] [, MEASURE_ERRORS=vector] [, SIGMA=variable] [, STATUS=variable] [, YFIT=variable] )

Return Value

REGRESS returns a 1 x Nterm array of coefficients. If the DOUBLE keyword is set, or if X or Y are double-precision, then the result will be double precision, otherwise the result will be single precision.

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

The Weights argument is obsolete, and has been replaced by the MEASURE_ERRORS keyword. Code that uses the Weights argument will continue to work as before, but new code should use the MEASURE_ERRORS keyword instead. Note that the definition of the MEASURE_ERRORS keyword is different from that of the Weights argument. Using the Weights argument, SQRT(1/Weights[i]) represents the measurement error for each point Y[i]. Using the MEASURE_ERRORS keyword, the measurement error for each point is represented as simply MEASURE_ERRORS[i]. Also note that the RELATIVE_WEIGHTS keyword is not necessary when using the MEASURE_ERRORS keyword.

Yfit, Const, Sigma, Ftest, R, Rmul, Chisq, Status

The Yfit, Const, Sigma, Ftest, R, Rmul, Chisq, and Status arguments are obsolete, and have been replaced by the YFIT, CONST, SIGMA, FTEST, CORRELATION, MCORRELATION, CHISQ, and STATUS keywords, respectively. Code that uses these arguments will continue to work as before, but new code should use the keywords instead.

Keywords

CHISQ

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

CONST

Set this keyword to a named variable that will contain the constant term of the fit.

CORRELATION

Set this keyword to a named variable that will contain the vector of linear correlation coefficients.

DOUBLE

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

FTEST

Set this keyword to a named variable that will contain the F-value for the goodness-of-fit test.

MCORRELATION

Set this keyword to a named variable that will contain the multiple linear correlation coefficient.

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(Y).

RELATIVE_WEIGHT

This keyword is obsolete. Code using the Weights argument and RELATIVE_WEIGHT keyword will continue to work as before, but new code should use the MEASURE_ERRORS keyword, for which case the RELATIVE_WEIGHT keyword is not necessary. Using the Weights argument, it was necessary to specify the RELATIVE_WEIGHT keyword if no weighting was desired. This is not the case with the MEASURE_ERRORS keyword-when MEASURE_ERRORS is omitted, REGRESS assumes you want no weighting.

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 the regression model 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.

STATUS

Set this keyword to a named variable that will contain the status of the operation. Possible status values are:

Note
If STATUS is not specified, any error messages will be output to the screen.

YFIT

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

Examples

; Create two vectors of independent variable data: 
X1 = [1.0, 2.0, 4.0, 8.0, 16.0, 32.0] 
X2 = [0.0, 1.0, 2.0, 3.0, 4.0, 5.0] 
; Combine into a 2x6 array 
X = [TRANSPOSE(X1), TRANSPOSE(X2)] 
 
; Create a vector of dependent variable data: 
Y = 5 + 3*X1 - 4*X2 
 
; Assume Gaussian measurement errors for each point: 
measure_errors = REPLICATE(0.5, N_ELEMENTS(Y)) 
 
; Compute the fit, and print the results: 
result = REGRESS(X, Y, SIGMA=sigma, CONST=const, $ 
   MEASURE_ERRORS=measure_errors) 
PRINT, 'Constant: ', const 
PRINT, 'Coefficients: ', result[*] 
PRINT, 'Standard errors: ', sigma 

IDL prints:

Constant:    4.99999 
Coefficients:    3.00000    -3.99999 
Standard errors:    0.0444831    0.282038 

Version History

Introduced: Original

See Also

CURVEFIT, GAUSSFIT, LINFIT, LMFIT, POLY_FIT, SFIT, SVDFIT


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