Trend(KnownYs: Array; KnownXs: Array; NewXs: Array; HasConstant: Boolean): Array;
KnownYs. The range of Y values that are already known in ratio y=mx+b. Values contained in data array must be greater than zero. 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 (i.e. an interval with a row height or a column width).
KnownXs. The range of X values that are already known for the ratio y=mx+b.
NewXs. New X values for which the Trend method returns corresponding Y values. Like KnownXs, NewXs must have a column or a row for each independent variable. Thus, if KnownYs has a single column, KnownXs and NewXs should have the same number of columns. If KnownYs is represented by one row, KnownXs and NewXs must have the same number of rows.
HasConstant. Boolean value that indicates whether the constant b must be equal to zero:
True. b is computed in a standard way;
False. b is regarded as zero, and m values are selected to satisfy y=mx.
The Trend method returns values for a linear trend.It approximates the KnownYs array and the KnownXs array using a straight line (the least-squares method). It returns Y values based on this straight line for the specified NewXs array.
Sub Main;
Var
st: Statistics;
d0: Double;
x, y, nx: Array Of Double;
res: Array Of Double;
i: Integer;
Begin
y := New Double[12];
x := New Double[12];
nx := New Double[4];
x[00] := 1; y[00] := 33100;
x[01] := 2; y[01] := 47300;
x[02] := 3; y[02] := 69000;
x[03] := 4; y[03] := 102000;
x[04] := 5; y[04] := 150000;
x[05] := 6; y[05] := 220000;
x[06] := 7; y[06] := 220100;
x[07] := 8; y[07] := 247300;
x[08] := 9; y[08] := 269000;
x[09] := 10; y[09] := 270020;
x[10] := 11; y[10] := 275210;
x[11] := 12; y[11] := 276030;
nx[0] := 13;
nx[1] := 14;
nx[2] := 15;
nx[3] := 16;
st := New Statistics.Create;
res := st.Trend(y,x,x,True);
Debug.WriteLine("Calculated values corresponding to existing Y values");
For i := 0 To res.Length - 1 Do
d0 := res[i];
Debug.WriteLine(d0.ToString);
End For;
res := st.Trend(y,x,nx,True);
Debug.WriteLine("Predicted Y values for new X values (nx)" );
For i := 0 To 3 Do
d0 := res[i];
Debug.WriteLine(d0.ToString);
End For;
End Sub Main;
Executing this example shows the calculation results in the console window:
Module execution started
Calculated values for the existing Y values
42019.871794871789
67395.955710955706
92772.03962703963
118148.12354312354
143524.20745920745
168900.29137529139
194276.3752913753
219652.45920745921
245028.54312354312
270404.62703962706
295780.71095571097
321156.79487179487
Predicted Y values for the new X (nx) values
346532.87878787878
371908.96270396269
397285.0466200466
422661.13053613051
Module execution finished
See also: