IStatistics.Trend

Syntax

Trend(KnownYs: Array; KnownXs: Array; NewXs: Array; HasConstant: Boolean): Array;

Parameters

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:

Description

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.

Example

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

Sub UserProc;
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 values Y");
    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("Forecasted values Y for new values X (nx)" );
    For i := 0 To 3 Do
        d0 := res[i];
        Debug.WriteLine(d0.ToString);
    End For;
End Sub UserProc;

Executing the example shows the calculation results in the console window:

Unit execution started

Calculated values for the existing Y values

42019.8717948718

67395.9557109557

92772.0396270396

118148.123543124

143524.207459207

168900.291375291

194276.375291375

219652.459207459

245028.543123543

270404.627039627

295780.710955711

321156.794871795

Predicted Y values for the new X (nx) values

346532.878787879

371908.962703963

397285.046620047

422661.130536131

Unit execution finished

See also:

IStatistics