IStatistics.Linest

Syntax

Linest(
    KnownYs: Array;
    KnownXs: Array;
    HasConstant: Boolean;
    ReturnStatistics: Boolean): Array;

Parameters

KnownYs. Set of known y-values. The values must be positive;

KnownXs. Set of known x-values.

HasConstant. Determines if the constant b equals to zero. Available values:

ReturnStatistics. Determines whether to return additional regressive statistics. Available values:

Description

The Linest method estimates statistics for a series using the least squares method.

Comments

This method calculates a straight line that approximates the available data in the best way, and returns the array that describes this straight line.

Equation of straight line: y = mx + b, where:

If several ranges of x-values are available, the equation of straight line looks like follows:  y = m1x1 + m2x2 + … + b.

 y, x and m can be vectors.

The Linest method returns the following array: {mn;mn-1;…;m1;b}. If additional regressive statistics are estimated,  Linest returns the following array: {mn;mn-1;…;m1;b;sen;sen-1;…;se1;seb;r2;sey;F;df;ssreg;ssresid}.

Additional regressive statistics:

Value Description
se1,se2,…,sen Standard values of errors for the coefficients m1,m2,…,mn.
seb Standard value of error for the constant b (seb is not calculated if HasConstant is False).
r2 Coefficient of determination. Compares actual values of y and the values obtained from the equation of straight line. Comparison results are used to calculate the coefficient of determination normalized from 0 to 1:
  • If r2 = 1, there is a perfect correlation with the model: that is, there is no difference between actual and estimated values of y.

  • If r2 = 1, the regression equation fails to predict the values of y.

sey Standard error for estimate of y.
F F-statistic or F-experimental value. F-statistic is used to determine whether the observed correlation between a dependent variable and an independent variable is random rather than not.
df Degrees of freedom. Degrees of freedom help to find F-critical values. To determine reliability of the model, compare values with the F statistics returned by the Linest method.
ssreg Regression sum of squares.
ssresid Sum of squared residuals.

Working with parameters:

Example

To execute the example, add a link to the Stat system assembly.

Sub UserProcLinest;
Var
    st: Statistics;
    d0: double;
    i: Integer;
    y, x, res: Array Of Double;
Begin
    // Define the range of known values of y
    y := New Double[4];
    y[0] := 1; y[2] := 5;
    y[1] := 9; y[3] := 7;
    // Define the range of known values of x
    x := New Double[41];
    x[00] := 10; x[20] := -5;
    x[10] := 0.9; x[30] := 7.7;
    // Call the method
    st := New Statistics.Create;
    res := st.Linest(y, x, TrueFalse);
    // Show results in console window
    If st.Status <> 0 Then
        Debug.WriteLine(st.Errors);
    Else
        For i := 0 To res.Length - 1 Do
            d0 := res[i];
            Debug.WriteLine(d0.ToString);
        End For;
    End If;
End Sub UserProcLinest;

After executing the example the console window shows the result of method calculation.

See also:

IStatistics