GLSMatrix: Array;
GLSMatrix: System.Array;
The GLSMatrix property determines a covariance matrix for generalized least squares method.
A covariance matrix should be symmetric and positive definite.
Add a link to the Stat system assembly.
Sub UserProc;
Var
OLS: ISmLinearRegress;
can, fra, ger: Array[10] Of Double;
omega: Array[10, 10] Of Double;
res: Integer;
Begin
OLS := New SmLinearRegress.Create;
// Set values for variables
can[0] := 6209; fra[0] := 4110; ger[0] := 3415;
can[1] := 6385; fra[1] := 4280; ger[1] := 3673;
can[2] := Double.Nan; 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;
omega[1, 1] := 0;
omega[2, 2] := 0;
omega[5, 5] := 0;
// Sample period parameters
OLS.ModelPeriod.FirstPoint := 1;
OLS.ModelPeriod.LastPoint := 10;
// Choose explained variable
OLS.Explained.Value := can;
// Choose regressors
OLS.Explanatories.Clear;
OLS.Explanatories.Add.Value := fra;
OLS.Explanatories.Add.Value := ger;
// Parameters of model coefficients
OLS.ModelCoefficients.Intercept.Mode := InterceptMode.AutoEstimate;
// Method of missing data treatment
OLS.MissingData.Method := MissingDataMethod.LinTrend;
// Value of weights use
OLS.UseWeights := True;
// Setting covariance matrix for generalized least squares method
OLS.GLSMatrix := omega;
// Type of least squares method
OLS.LSType := LRLSType.GLS;
res := OLS.Execute;
Debug.WriteLine(OLS.Errors);
Debug.WriteLine("Summary statistics");
Debug.Indent;
Debug.WriteLine("Fisherstatistic:"+OLS.SummaryStatistics.Fstat.ToString); Debug.WriteLine("Probability for Fisher statistics: " + OLS.SummaryStatistics.ProbFstat.ToString);
Debug.Unindent;
End Sub UserProc;
As a result of the example execution, the following settings are defined:
Sample period.
Method of missing data treatment.
Parameters of model coefficients.
Covariance matrix for generalized least squares method.
Type of least squares method.
The console window shows summary 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
OLS: ISmLinearRegress;
PDLTerm: ISlPDLTerm;
Explanatories: ISlSerie;
can, fra, ger: Array[10] Of Double;
omega: Array[10, 10] Of Double;
arr: Array Of Double;
res: Integer;
str: String;
Begin
OLS := New SmLinearRegress.Create();
// Set values fornbsp;variables
can[0] := 6209; fra[0] := 4110; ger[0] := 3415;
can[1] := 6385; fra[1] := 4280; ger[1] := 3673;
can[2] := Double.Nan; 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;
omega[1, 1] := 0;
omega[2, 2] := 0;
omega[5, 5] := 0;
// Sample period parameters
OLS.ModelPeriod.FirstPoint := 1;
OLS.ModelPeriod.LastPoint := 10;
// Choose explained variable
OLS.Explained.Value := can;
// Choose regressors
OLS.Explanatories.Clear();
OLS.Explanatories.Add().Value := fra;
OLS.Explanatories.Add().Value := ger;
// Parameters of model coefficients
OLS.ModelCoefficients.Intercept.Mode := InterceptMode.imAutoEstimate;
// Missing data treatment method
OLS.MissingData.Method := MissingDataMethod.mdmLinTrend;
// Value of weights use
OLS.UseWeights := True;
// Set covariance matrix for generalized least squares method
OLS.GLSMatrix := omega;
// OLS type
OLS.LSType := LRLSType.lrlstGLS;
res := OLS.Execute();
System.Diagnostics.Debug.WriteLine(OLS.Errors);
System.Diagnostics.Debug.WriteLine("Summary statistics");
System.Diagnostics.Debug.Indent();
System.Diagnostics.Debug.WriteLine("Fisherstatistic:"+OLS.SummaryStatistics.Fstat.ToString()); System.Diagnostics.Debug.WriteLine("Fisher statistics probability: " + OLS.SummaryStatistics.ProbFstat.ToString());
System.Diagnostics.Debug.Unindent();
System.Diagnostics.Debug.WriteLine("Explained series");
System.Diagnostics.Debug.Indent();
End Sub;
See also: