How to: |
The linear regression equation estimates values by assuming that the dependent variable (the new calculated values) and the independent variable (the sort field values) are related by a function that represents a straight line:
y = mx + b
where:
FORECAST_LINEAR uses a technique called Ordinary Least Squares to calculate values for m and b that minimize the sum of the squared differences between the data and the resulting line.
The following formulas show how m and b are calculated.
where:
Trend values, as well as predicted values, are calculated using the regression line equation.
FORECAST_LINEAR(display, infield, interval, npredict)
where:
Keyword
Specifies which values to display for rows of output that represent existing data. Valid values are:
Note: You can show both types of output for any field by creating two independent COMPUTE commands in the same request, each with a different display option.
For date fields, the minimal component in the format determines how the number is interpreted. For example, if the format is YMD, MDY, or DMY, an interval value of 2 is interpreted as meaning two days. If the format is YM, the 2 is interpreted as meaning two months.
The following request calculates a regression line using the VIDEOTRK data source of QUANTITY by TRANSDATE. The interval is one day, and three predicted values are calculated.
TABLE FILE VIDEOTRK SUM QUANTITY COMPUTE FORTOT=FORECAST_LINEAR(MODEL_DATA,QUANTITY,1,3); BY TRANSDATE ON TABLE SET PAGE NOLEAD ON TABLE SET STYLE * GRID=OFF,$ ENDSTYLE END
The output is shown in the following image:
Note:
TRANSDATE is the independent variable (x) and QUANTITY is the dependent variable (y). The equation is used to calculate QUANTITY FORECAST trend and predicted values.
The following version of the request charts the data values and the regression line.
GRAPH FILE VIDEOTRK SUM QUANTITY COMPUTE FORTOT=FORECAST_LINEAR(MODEL_DATA,QUANTITY,1,3); BY TRANSDATE ON GRAPH PCHOLD FORMAT JSCHART ON GRAPH SET LOOKGRAPH VLINE END
The output is shown in the following image.