WeightedSummaryStatistics: 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.
See also: