Fitted: Array;
Fitted: System.Array;
The Fitted property returns an array of modeling series values.
Values are available after method calculation.
To execute the example, add a link to the Stat system assembly.
Sub UserProc;
Var
slr: SmLinearRegress;
Factors: ISlSeries;
res: Integer;
Serie, Factor, Weights: Array Of Double;
Period: IStatPeriod;
AR, MA: Array Of Integer;
ARMA: ISlARMA;
Stat: Double;
Begin
slr := New SmLinearRegress.Create;
// Set explained series
Serie := New Double[20];
Serie[00] := 6209; Serie[01] := 6385;
Serie[02] := 6752; Serie[03] := 6837;
Serie[04] := 6495; Serie[05] := 6907;
Serie[06] := 7349; Serie[07] := 7213;
Serie[08] := 7061; Serie[09] := 7180;
Serie[10] := 7132; Serie[11] := 7137;
Serie[12] := 7473; Serie[13] := 7722;
Serie[14] := 8088; Serie[15] := 7486;
Serie[16] := 7832; Serie[17] := 9064;
Serie[18] := 9380; Serie[19] := 9746;
slr.Explained.Value := Serie;
// Set explanatory series
Factor := New Double[30];
Factor[00] := 4110; Factor[01] := 4280;
Factor[02] := 4459; Factor[03] := 4545;
Factor[04] := 4664; Factor[05] := 4861;
Factor[06] := 5195; Factor[07] := 5389;
Factor[08] := 5463; Factor[09] := 5610;
Factor[10] := 5948; Factor[11] := 6218;
Factor[12] := 6521; Factor[13] := 6788;
Factor[14] := 7222; Factor[15] := 7486;
Factor[16] := 7832; Factor[17] := 8153;
Factor[18] := 8468; Factor[19] := 9054;
Factor[20] := 9907; Factor[21] := 10333;
Factor[22] := 10863; Factor[23] := 11693;
Factors := slr.Explanatories;
Factors.Add.Value := Factor;
// Set weight series
Weights := New Double[20];
Weights[00] := 1; Weights[01] := 1.5;
Weights[02] := 0; Weights[03] := 1;
Weights[04] := 1; Weights[05] := 0;
Weights[06] := 1.5; Weights[07] := 0;
Weights[08] := 1; Weights[09] := 1;
Weights[10] := 1; Weights[11] := 1;
Weights[12] := 1; Weights[13] := 1;
Weights[14] := 1; Weights[15] := 1;
Weights[16] := 0; Weights[17] := 2;
Weights[18] := 1; Weights[19] := 1.5;
slr.UseWeights := True;
slr.Weights := Weights;
// Set parameters of autoregression and moving average
ARMA := slr.ARMA;
AR := New Integer[1];
AR[0] := 1;
ARMA.OrderAR := AR;
MA := New Integer[1];
MA[0] := 1;
ARMA.OrderMA := MA;
// Set sample period parameters
Period := slr.ModelPeriod;
Period.FirstPoint := 4;
Period.LastPoint := 20;
// Set forecast parameters
slr.Forecast.LastPoint := 30;
//Run calculation and output results
res := slr.Execute;
If res <> 0 Then
Debug.WriteLine(slr.Errors);
Else
Debug.WriteLine("=== Model series ===");
Print(slr.Fitted);
Debug.WriteLine("=== Forecast ===");
Print(slr.Forecast.Value);
Debug.WriteLine("=== Residual series ===");
Print(slr.Residuals);
Debug.WriteLine("=== Fisher statistic ===");
Stat := slr.SummaryStatistics.Fstat;
Debug.WriteLine(Stat);
Debug.WriteLine("=== Fisher statistics probability === ");
Stat := slr.SummaryStatistics.ProbFstat;
Debug.WriteLine(Stat);
End If;
End Sub UserProc;
// Data output procedure
Sub Print(Data: Array Of Double);
Var
i: Integer;
d: Double;
Begin
For i := 0 To Data.Length - 1 Do
If Double.IsNan(Data[i]) Then
Debug.WriteLine(i.ToString + ", ---empty---");
Else
d := Data[i];
Debug.WriteLine(i.ToString + ", " + d.ToString);
End If;
End For;
End Sub Print;
After executing the example the console window displays linear regression calculation results: modeling series, forecasting series, residual series, the Fisher statistic, and Fisher statistic probability.
The requirements and result of the Fore.NET example execution match with those in the Fore example.
Imports Prognoz.Platform.Interop.Stat;
…
Public Shared Sub Main(Params: StartParams);
Var
slr: SmLinearRegress;
Factors: ISlSeries;
res: Integer;
Serie, Factor, Weights: Array Of Double;
Period: IStatPeriod;
AR, MA: Array Of Integer;
ARMA: ISlARMA;
Stat: Double;
Begin
slr := New SmLinearRegress.Create();
// Set explained series
Serie := New Double[20];
Serie[00] := 6209; Serie[01] := 6385;
Serie[02] := 6752; Serie[03] := 6837;
Serie[04] := 6495; Serie[05] := 6907;
Serie[06] := 7349; Serie[07] := 7213;
Serie[08] := 7061; Serie[09] := 7180;
Serie[10] := 7132; Serie[11] := 7137;
Serie[12] := 7473; Serie[13] := 7722;
Serie[14] := 8088; Serie[15] := 7486;
Serie[16] := 7832; Serie[17] := 9064;
Serie[18] := 9380; Serie[19] := 9746;
slr.Explained.Value := Serie;
// Set explanatory series
Factor := New Double[30];
Factor[00] := 4110; Factor[01] := 4280;
Factor[02] := 4459; Factor[03] := 4545;
Factor[04] := 4664; Factor[05] := 4861;
Factor[06] := 5195; Factor[07] := 5389;
Factor[08] := 5463; Factor[09] := 5610;
Factor[10] := 5948; Factor[11] := 6218;
Factor[12] := 6521; Factor[13] := 6788;
Factor[14] := 7222; Factor[15] := 7486;
Factor[16] := 7832; Factor[17] := 8153;
Factor[18] := 8468; Factor[19] := 9054;
Factor[20] := 9907; Factor[21] := 10333;
Factor[22] := 10863; Factor[23] := 11693;
Factors := slr.Explanatories;
Factors.Add().Value := Factor;
// Set weight series
Weights := New Double[20];
Weights[00] := 1; Weights[01] := 1.5;
Weights[02] := 0; Weights[03] := 1;
Weights[04] := 1; Weights[05] := 0;
Weights[06] := 1.5; Weights[07] := 0;
Weights[08] := 1; Weights[09] := 1;
Weights[10] := 1; Weights[11] := 1;
Weights[12] := 1; Weights[13] := 1;
Weights[14] := 1; Weights[15] := 1;
Weights[16] := 0; Weights[17] := 2;
Weights[18] := 1; Weights[19] := 1.5;
slr.UseWeights := True;
slr.Weights := Weights;
// Set parameters of autoregression and moving average
ARMA := slr.ARMA;
AR := New Integer[1];
AR[0] := 1;
ARMA.OrderAR := AR;
MA := New Integer[1];
MA[0] := 1;
ARMA.OrderMA := MA;
// Set sample period parameters
Period := slr.ModelPeriod;
Period.FirstPoint := 4;
Period.LastPoint := 20;
// Set forecast parameters
slr.Forecast.LastPoint := 30;
//Run calculation and output results
res := slr.Execute();
If res <> 0 Then
System.Diagnostics.Debug.WriteLine(slr.Errors);
Else
System.Diagnostics.Debug.WriteLine("=== Modeling series ===");
Print(slr.Fitted);
System.Diagnostics.Debug.WriteLine("=== Forecast ===");
Print(slr.Forecast.Value);
System.Diagnostics.Debug.WriteLine("=== Residual series ===");
Print(slr.Residuals);
System.Diagnostics.Debug.WriteLine("=== Fisher statistic ===");
Stat := slr.SummaryStatistics.Fstat;
System.Diagnostics.Debug.WriteLine(Stat);
System.Diagnostics.Debug.WriteLine("=== Fisher statistics probability === ");
Stat := slr.SummaryStatistics.ProbFstat;
System.Diagnostics.Debug.WriteLine(Stat);
End If;
End Sub;
Public Shared Sub Print(Data: System.Array);
Var
i: Integer;
d: Double;
Begin
For i := 0 To Data.Length - 1 Do
If Double.IsNan(Data.GetValue(i) As Double) Then
System.Diagnostics.Debug.WriteLine(i.ToString() + ", ---empty---");
Else
d := Data.GetValue(i) As Double;
System.Diagnostics.Debug.WriteLine(i.ToString() + ", " + d.ToString());
End If;
End For;
End Sub Print;
See also: