Determines the least squares fit of a line to a series.
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:
|
An interval (regularly spaced) series,
the regression line in the form
(s, slope, intercept, Se, report) = LINREG(series, info) returns the regression line, slope, intercept, standard error and regression equation in separate variables.
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.
W1: gline(100, .01, 1.0, 1.0)^3
W2: linreg(w1);overplot(w1)

Similar to above, except the regression line is computed in W2 and returned without reporting.
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)

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.