LINREG

Purpose:

Determines the least squares fit of a line to a series.

Syntax:

LINREG(series, info)

(s, slope, intercept, Se, report) = LINREG(

series, info)

series

-

A series or multi-column table.

info

-

Optional. An integer, the display fit statistics flag:

0:

OFF, no information is displayed and the regression line is plotted immediately (default).

1:

ON, the line's slope, y-intercept, and standard error are displayed in a message box and after the OK button is pressed, the line is plotted.

Returns:

An interval (regularly spaced) series, the regression line in the form y = mx + b. If info is 1, the slope m, the y-intercept b, and the standard error are displayed in a message box.

 

(s, slope, intercept, Se, report) = LINREG(series, info) returns the regression line, slope, intercept, standard error and regression equation in separate variables.

Example:

linreg(gline(100, .01, 1.0, 1.0)^3, 1)

 

displays the slope and y-intercept of the regression line and after the OK button is pressed, plots the line that best fits the data.

Example:

W1: gline(100, .01, 1.0, 1.0)^3

W2: linreg(w1);overplot(w1)

 

Linear Regression on Interval Series

 

Similar to above, except the regression line is computed in W2 and returned without reporting.

Remarks:

If the input is an XY series, LINREG returns an XY series where the X values are the same as the X values of the input series. For example:

 

W1: xy(grand(1000,1), exp(gnorm(1000,1)+2));setplotstyle(1);setsym(14)

W2: linreg(W1);setplotstyle(0);setsym(0)

W3: w1;overp(w2);setlinewidth(4, 2)

 

Linear Regression on XY Series

W1 generates a random XY series.

 

W2 computes the linear regression line as an XY series.

 

W3 contains the original input data overplotted with the regrssion line.

 

 

See PFIT to fit a polynomial with error statistics.

 

See LINREG2 to fit a line to separate X and Y series.

 

See LFIT to fit a line using only the endpoints.

 

See LINFIT to fit linear combination of arbitrary basis functions to a series using the method of least squares.

 

See DETREND to remove a regression line or piecewise continuous regression line from a series.

See Also:

DETREND

LFIT

LINFIT

LINREG2

PFIT

POLYFIT

POLYGRAPH