WeightedSummaryStatistics: ISummaryStatistics;
WeightedSummaryStatistics: Prognoz.Platform.Interop.Stat.ISummaryStatistics;
The WeightedSummaryStatistics property returns weighted descriptive statistics of a model.
Descriptive statistics are calculated using general formulas. The property does not calculate statistics, not relevant for the current model.
To execute the example, add a link to the Stat system assembly.
Sub UserProc;
Var
Method: SmLinearRegress;
can, fra, ger: Array[10] Of Double;
omega: Array[10, 10] Of Double;
status, i, j: Integer;
str: String;
Begin
Method := New SmLinearRegress.Create;
// Set explained series
can[0] := 6209; fra[0] := 4110; ger[0] := 3415;
can[1] := 6385; fra[1] := 4280; ger[1] := 3673;
can[2] := 6528; fra[2] := 4459; ger[2] := 4013;
can[3] := 6837; fra[3] := 4545; ger[3] := 4278;
can[4] := 6495; fra[4] := 4664; ger[4] := 4577;
can[5] := 6907; fra[5] := 4861; ger[5] := 5135;
can[6] := 7349; fra[6] := 5195; ger[6] := 5388;
can[7] := 7213; fra[7] := 5389; ger[7] := 5610;
can[8] := 7061; fra[8] := 5463; ger[8] := 5787;
can[9] := 7180; fra[9] := 5610; ger[9] := 6181;
For i := 0 To omega.GetUpperBound(1) - 1 Do
omega[i, i] := 1 + 0.05*i;
End For;
// Sample period parameters
Method.ModelPeriod.FirstPoint := 1;
Method.ModelPeriod.LastPoint := 10;
// Choose explained variable
Method.Explained.Value := can;
// Choose regressors
Method.Explanatories.Clear;
Method.Explanatories.Add.Value := fra;
Method.Explanatories.Add.Value := ger;
// Set forecast parameters
Method.Forecast.LastPoint := 10;
// Value of weights use
Method.UseWeights := True;
// Set covariance matrix for generalized least squares method
Method.GLSMatrix := omega;
// Type of weights
Method.WeightsType := LRWeightsType.StdDeviation;
// Method of weights scaling
Method.WeightsScaling := WeightsScalingType.Average;
//Run calculation and output results
status := Method.Execute;
If status <> 0 Then
Debug.WriteLine(Method.Errors);
Else
Debug.WriteLine("=== Summary statistics ===");
Debug.WriteLine(" Determination coefficient: " + Method.WeightedSummaryStatistics.R2.ToString);
Debug.WriteLine(" Mean error: " + Method.WeightedSummaryStatistics.ME.ToString);
Debug.WriteLine(" Standard error: " + Method.WeightedSummaryStatistics.SE.ToString);
Debug.WriteLine(" Standard deviation of residuals: " + Method.WeightedSummaryStatistics.SEE.ToString);
Debug.WriteLine("=== Covariance matrix ===");
For i := 0 To Method.CovarianceMatrix.GetUpperBound(1) Do
str := "";
For j := 0 To Method.CovarianceMatrix.GetUpperBound(2) Do
str := str + " " + (Method.CovarianceMatrix[i, j] As Double).ToString;
End For;
Debug.WriteLine(str);
End For;
End If;
End Sub UserProc;
After executing the example the console window displays values of covariance matrix and weighted dscriptive statistics.
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
Method: SmLinearRegress;
can, fra, ger: Array[10] Of Double;
omega: Array[10, 10] Of Double;
status, i, j: Integer;
str: String;
Matrix: System.Array;
Begin
Method := New SmLinearRegress.Create();
// Set explained series
can[0] := 6209; fra[0] := 4110; ger[0] := 3415;
can[1] := 6385; fra[1] := 4280; ger[1] := 3673;
can[2] := 6528; fra[2] := 4459; ger[2] := 4013;
can[3] := 6837; fra[3] := 4545; ger[3] := 4278;
can[4] := 6495; fra[4] := 4664; ger[4] := 4577;
can[5] := 6907; fra[5] := 4861; ger[5] := 5135;
can[6] := 7349; fra[6] := 5195; ger[6] := 5388;
can[7] := 7213; fra[7] := 5389; ger[7] := 5610;
can[8] := 7061; fra[8] := 5463; ger[8] := 5787;
can[9] := 7180; fra[9] := 5610; ger[9] := 6181;
For i := 0 To omega.GetUpperBound(1) - 1 Do
omega[i, i] := 1 + 0.05*i;
End For;
// Sample period parameters
Method.ModelPeriod.FirstPoint := 1;
Method.ModelPeriod.LastPoint := 10;
// Choose explained variable
Method.Explained.Value := can;
// Choose regressors
Method.Explanatories.Clear();
Method.Explanatories.Add().Value := fra;
Method.Explanatories.Add().Value := ger;
// Set forecast parameters
Method.Forecast.LastPoint := 10;
// Value of weights use
Method.UseWeights := True;
// Set covariance matrix for generalized least squares method
Method.GLSMatrix := omega;
// Type of weights
Method.WeightsType := LRWeightsType.wtStdDeviation;
// Method of weights scaling
Method.WeightsScaling := WeightsScalingType.wstAverage;
//Run calculation and output results
status := Method.Execute();
If status <> 0 Then
System.Diagnostics.Debug.WriteLine(Method.Errors);
Else
System.Diagnostics.Debug.WriteLine("=== Summary statistics ===");
System.Diagnostics.Debug.WriteLine(" Determination coefficient: " + Method.WeightedSummaryStatistics.R2.ToString());
System.Diagnostics.Debug.WriteLine(" Mean error: " + Method.WeightedSummaryStatistics.ME.ToString());
System.Diagnostics.Debug.WriteLine(" Standard error: " + Method.WeightedSummaryStatistics.SE.ToString());
System.Diagnostics.Debug.WriteLine(" Standard deviation of residuals: " + Method.WeightedSummaryStatistics.SEE.ToString());
System.Diagnostics.Debug.WriteLine("=== Covariance matrix ===");
Matrix := Method.CovarianceMatrix;
For i := 0 To Method.CovarianceMatrix.GetUpperBound(1) Do
str := "";
For j := 0 To Method.CovarianceMatrix.GetUpperBound(0) Do
str := str + " " + (Matrix[i, j] As Double).ToString();
End For;
System.Diagnostics.Debug.WriteLine(str);
End For;
End If;
End Sub;
See also: