Linest(
KnownYs: Array;
KnownXs: Array;
HasConstant: Boolean;
ReturnStatistics: Boolean): Array;
Linest(
KnownYs: System.Array;
KnownXs: System.Array;
HasConstant: boolean;
ReturnStatistics: boolean): System.Array;
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:
True. The constant is calculated.
False. b is assumed to be zero.
ReturnStatistics. Determines whether to return additional regressive statistics. Available values:
True. The method returns regressive statistics.
False. Regressive statistics are not calculated.
The Linest method estimates statistics for a series using the least squares method.
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:
y. Dependent value. Function of independent valuex;
m. Coefficients corresponding to each independent variable x;
b. Constant.
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:
|
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:
If there is only one column in the KnownYs array, each column of the KnownXs array is regarded as a separate variable.
If there is only one row in the KnownYs array, each row of the KnownXs array is regarded as a separate variable.
The KnownXs array can contain one or more variable sets. If only one variable is used, KnownYs and KnownXs can have any form, provided that they have the same dimension. If several variables are used, KnownYs must be a vector (that is, an interval with a row height or a column width).
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[4, 1];
x[0, 0] := 10; x[2, 0] := -5;
x[1, 0] := 0.9; x[3, 0] := 7.7;
// Call the method
st := New Statistics.Create;
res := st.Linest(y, x, True, False);
// 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.
Imports Prognoz.Platform.Interop.Stat;
…
Public Shared Sub UserProcLinest();
Var
st: Statistics;
d0: double;
i: integer;
y, x, res: System.Array;
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[1, 4];
x[0, 0] := 10; x[0, 2] := -5;
x[0, 1] := 0.9; x[0, 3] := 7.7;
// Call the method
st := New Statistics.Create();
res := st.Linest(y, x, True, False);
// Show results in console window
If st.Status <> 0 Then
System.Diagnostics.Debug.WriteLine(st.Errors);
Else
For i := 0 To res.Length - 1 Do
d0 := res[i] As double;
System.Diagnostics.Debug.WriteLine(d0);
End For;
End If;
End Sub;
After executing the example the console window shows the result of method calculation.
See also: