# LinearRegression

Calculate a vector/matrix with calculated linear regression values.

 vector vector::LinearRegression();   matrix matrix::LinearRegression(   ENUM_MATRIX_AXIS  axis=AXIS_NONE      // axis along which regression is calculated    );

Parameters

axis

[in]  Specifying the axis along which the regression is calculated. ENUM_MATRIX_AXIS enumeration value (AXIS_HORZ — horizontal axis, AXIS_VERT — vertical axis).

Return Value

Vector or matrix with calculated linear regression values.

Note

Linear regression is calculated using the standard regression equation: y (x) =  a * x + b, where a is the line slope, while b is its Y axis shift.

Example:

 #include    #define GRAPH_WIDTH  750 #define GRAPH_HEIGHT 350   //+------------------------------------------------------------------+ //| Script program start function                                    | //+------------------------------------------------------------------+ void OnStart()   {    vector vector_a;    vector_a.CopyRates(_Symbol,_Period,COPY_RATES_CLOSE,1,100);    vector vector_r=vector_a.LinearRegression();   //--- switch off chart show    ChartSetInteger(0,CHART_SHOW,false);   //--- arrays for drawing a graph    double x[];    double y1[];    double y2[];    ArrayResize(x,uint(vector_a.Size()));    ArrayResize(y1,uint(vector_a.Size()));    ArrayResize(y2,uint(vector_a.Size()));    for(ulong i=0; i

ENUM_MATRIX_AXIS

Enumeration for specifying the axis in all statistical functions for matrices.

ID

Description

AXIS_NONE

The axis is not specified. Calculation is performed over all matrix elements, as if it were a vector (see the Flat method).

AXIS_HORZ

Horizontal axis

AXIS_VERT

Vertical axis