GrangerTest: IMsVariableTest;
The GrangerTest property returns parameters of the Granger test calculation.
Use the IMsGrangerTestSettings interface to set up calculation options.
Executing the example requires that the repository contains a modeling container with the MS identifier containing a modeling problem with the WEB_PROBLEM identifier. The task must contain the internal metamodel.
Add links to the Dimensions, Metabase, Ms, Stat system assemblies.
Sub GrangerTest;
Var
mb: IMetabase;
msKey: Integer;
Problem: IMsProblem;
Meta: IMsMetaModel;
MetaVisual: IMsMetaModelVisualController;
Test: IMsVariableTest;
CommonSett: IMsVariableTestSettings;
InclSrc: IMsVariableTestDataList;
VarArray: Array;
i, j: Integer;
Slice: IMsFormulaTransformSlice;
TestData: IMsVariableTestData;
Granger: IMsGrangerTestSettings;
TestRes: IMsVariableTestResults;
Res: Array;
Begin
mb := MetabaseClass.Active;
// Get modelling container key
msKey := mb.GetObjectKeyById("MS");
// Get modeling problem
Problem := mb.ItemByIdNamespace("WEB_PROBLEM", msKey).Bind As IMsProblem;
// Get metamodel
Meta := Problem.MetaModel;
MetaVisual := Meta.VisualController;
//Set common parameters of calculating descriptive statistics Test := MetaVisual.GrangerTest;
CommonSett := Test.Settings;
// Calculation period
CommonSett.StartDate := DateTime.Parse("01.01.1990");
CommonSett.EndDate := DateTime.Parse("01.01.2015");
// Method of missing data treatment
CommonSett.MissingData.Method := MissingDataMethod.LinTrend;
// Set variables for calculation
VarArray := MetaVisual.GetVariables;
InclSrc := CommonSett.IncludedSources;
InclSrc.Clear;
Debug.WriteLine("Tested variables");
Debug.WriteLine("");
For i := 0 To VarArray.Length - 1 Do
// Add only variables with annual frequency
Slice := VarArray[i] As IMsFormulaTransformSlice;
If Slice.Level = DimCalendarLevel.Year Then
TestData := InclSrc.Add(Slice);
End If;
End For;
// Set the parameters of Granger test calculation
Granger := CommonSett As IMsGrangerTestSettings;
// Setting significance level
Granger.ConfidenceLevel := 0.1;
// Setting lag
Granger.Lag := 3;
// Perform calculation of the test
TestRes := Test.Execute;
// Output results
If TestRes.Error <> "" Then
Debug.WriteLine(TestRes.Error);
Else
Res := TestRes.PValueMatrix;
Debug.WriteLine("Granger test"); Debug.WriteLine("");
Debug.WriteLine("Probability matrix:");
For i := 0 To Res.GetUpperBound(1) Do
For j := 0 To Res.GetUpperBound(2) Do
Debug.Write(Res[i, j]); Debug.Write("; ");
End For;
Debug.WriteLine("");
End For;
Debug.WriteLine("");
Res := TestRes.TStatMatrix;
Debug.WriteLine("Statistics matrix:");
For i := 0 To Res.GetUpperBound(1) Do
For j := 0 To Res.GetUpperBound(2) Do
Debug.Write(Res[i, j]); Debug.Write("; ");
End For;
Debug.WriteLine("");
End For;
Debug.WriteLine("");
Res := TestRes.ResValueMatrix;
Debug.WriteLine("Variable dependence:");
For i := 0 To InclSrc.Count - 1 Do
Debug.WriteLine("X" + (i + 1).ToString + " - " + InclSrc.Item(i).Name);
End For;
For i := 0 To Res.GetUpperBound(1) Do
For j := 0 To Res.GetUpperBound(2) Do
If i <> j Then
Debug.Write("X" + (i + 1).ToString + "," + "X" + (j + 1).ToString);
If (Res[i, j] As Boolean) Then
Debug.WriteLine(" there is Granger conditionality");
Else
Debug.WriteLine(" there is no Granger conditionality");
End If;
End If;
End For;
Debug.WriteLine("");
End For;
End If;
End Sub GrangerTest;
Example execution result: for all annual frequency variables, which are contained in the metamodel calculation chain, the Granger test is calculated. The results are displayed in the console window.
See also: