REGRESS Function
Standard Library function that fits a curve to data using the multiple linear regression method.
Usage
result = REGRESS(x, y, wt[, yf, a0, sig, ft, r, rm, c])
Input Parameters
x—An array containing the independent values. Must be two-dimensional of size m by n, where m is the number of coefficients to be computed, and n is the number of data points.
y—A vector containing the dependent values. Must have n elements.
wt—A vector of weighting factors for determining the weighting of the multiple linear regression. Must have n elements.
Output Parameters
yf—(optional) An array containing the calculated values of y. It contains n number of elements
a0—(optional) The constant term (offset) of the output function.
sig—(optional) Vector containing standard deviations for the coefficients.
ft—(optional) The value of F in the standard F Test for the goodness of fit.
r—(optional) A vector containing the linear correlational coefficients.
rm—(optional) The multiple linear correlation coefficient.
c—(optional) Value of X2 in the Chi-Squared test for the goodness of fit.
Returned Value
result—A column vector containing the coefficients ( a1 to am ) of the function in x.
Keywords
None.
Discussion
REGRESS performs a multiple linear regression fit to a dataset with a specified function which is linear in the coefficients. The general function is given by:
f(x) = a0 + a1x1 + a2x2 + ... amxm
Weighting is useful when you want to correct for potential errors in the data you are fitting to a curve. The weighting factor,
wt,
adjusts the parameters of the curve so that the error at each point of the curve is minimized. For more information, see the
"Weighting Factor" on page 272.
Example
; Create the data.
x = FLTARR(3, 9)
x(0, *) = [0., 1., 2., 3., 4., 10., 13., 17., 20.]
x(1, *) = [0., 3., 6., 9., 12., 15., 18., 19., 20.]
x(2, *) = [0., 4., 8., 12., 13., 14., 15., 18., 20.]
y = [5., 4., 3., 2., 2., 4., 5., 8., 9.]
wt = FLTARR(9) + 1.0
; Perform multiple linear regression with no weighting.
coeff = REGRESS(x, y, wt, yf, a0, sig, ft, r, rm, c)
; Plot the fitted data.
PLOT, yf, Title='REGRESS EXAMPLE'
; Print all the output parameters.
PRINT, 'Fitted function:'
PRINT, ' f(x) = ',a0,' +', coeff(0, 0),' x1 +', $
coeff(0, 1),' x2 +', coeff(0, 2),' x3'
PRINT, 'Standard deviations for coefficients: ', sig
PRINT, 'F Test value:', ft
PRINT, 'Linear correlation coefficients: ', r
PRINT, 'Multiple linear correlation coefficient: ', rm
PRINT, 'Chi-squared value: ', c
; PV-WAVE prints:
; f(x) = 4.88039 + 0.736371 x1 + -0.476869 x2 + -0.0464314 x3
; Standard deviations for coefficients: 0.135938 0.284764
; 0.246748
; F Test value: 94.8390
; Linear correlation coefficients: 0.810984 0.546753 0.469676
; Multiple linear correlation coefficient: 0.991327
; Chi-squared value: 0.165797
See Also
The REGRESS function is adapted from the program REGRES in Data Reduction and Error Analysis for the Physical Sciences, by Philip Bevington, McGraw-Hill, New York, 1969.