# Moving Linear Regression Using the MLINREG Function Teradata

The Moving Linear Regression (MLINREG) function provides a moving projection of what the next value in a series might be based on the values of two other variables. The operation of the MLINREG is to project or forecast the next value based on the data received using the dependent and independent variables as a guide.

No one should ever assume that MLINREG can predict the exact future value. The MLINREG uses extensive mathematics to predict the next value thru trending the existing data.

The syntax for MLINREG is:

The MLINREG command uses the first parameter as the column containing a numeric value to use as the dependent variable. The dependent variable is used to establish a pattern in the data.

The second parameter used by the MLINREG is the width number. It represents the number of rows included in the summation. Valid values are from 3 to 4096. If the number of rows is less than the width defined then the calculation will be based on the rows present.

The third parameter is entered as the column containing a numeric value to use as the independent variable. The independent variable is used to provide the projection for the next value to forecast.

The following SELECT uses MLINREG with three different width values to demonstrate the smoothing effect as the number increases:

20 Rows Returned Notice that the first two values are NULL. This will always be the case regardless of the value specified as the width. It takes at least two values to predict the third value. The output of the MLINREG varies dramatically based on the linearity of both variables. So, the higher the value used for the width, the smoother the value curve of the output. Likewise, the smaller the number used for width, the more erratic the curve.

The default sort is ascending (ASC) on the first parameter as the independent variable column and is performed on the dependent variable's data values.