IMsMetaModelVisualController.GrangerTest

Fore Syntax

GrangerTest: IMsVariableTest;

Fore.NET Syntax

GrangerTest: Prognoz.Platform.Interop.Ms.IMsVariableTest;

Description

The GrangerTest property returns parameters of the Granger test calculation.

Comments

Use the IMsGrangerTestSettings interface to set up calculation parameters.

Fore Example

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(1Do
            For j := 0 To Res.GetUpperBound(2Do
                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(1Do
            For j := 0 To Res.GetUpperBound(2Do
                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(1Do
            For j := 0 To Res.GetUpperBound(2Do
                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.

Fore.NET Example

The requirements and result of the Fore.NET example execution match with those in the Fore example.

Imports Prognoz.Platform.Interop.Dimensions;
Imports Prognoz.Platform.Interop.Ms;
Imports Prognoz.Platform.Interop.Stat;

Public Shared Sub Main(Params: StartParams);
Var
    mb: IMetabase;
    msKey: uinteger;
    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 := Params.Metabase;
    // 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.mdmLinTrend;
    // Set variables for calculation
    VarArray := MetaVisual.GetVariables();
    InclSrc := CommonSett.IncludedSources;
    InclSrc.Clear();
    System.Diagnostics.Debug.WriteLine("Tested variables");
    System.Diagnostics.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.dclYear Then
            TestData := InclSrc.Add(Slice, 0);
        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
        System.Diagnostics.Debug.WriteLine(TestRes.Error);
    Else
        Res := TestRes.PValueMatrix;
        System.Diagnostics.Debug.WriteLine("Granger test"); System.Diagnostics.Debug.WriteLine("");
        System.Diagnostics.Debug.WriteLine("Probability matrix:");
        For i := 0 To Res.GetUpperBound(1Do
            For j := 0 To Res.GetUpperBound(0Do
                System.Diagnostics.Debug.Write(Res[j, i]); System.Diagnostics.Debug.Write(";    ");
            End For;
            System.Diagnostics.Debug.WriteLine("");
        End For;
        System.Diagnostics.Debug.WriteLine("");
        Res := TestRes.TStatMatrix;
        System.Diagnostics.Debug.WriteLine("Statistics matrix:");
        For i := 0 To Res.GetUpperBound(1Do
            For j := 0 To Res.GetUpperBound(0Do
                System.Diagnostics.Debug.Write(Res[j, i]); System.Diagnostics.Debug.Write(";    ");
            End For;
            System.Diagnostics.Debug.WriteLine("");
        End For;
        System.Diagnostics.Debug.WriteLine("");
        Res := TestRes.ResValueMatrix;
        System.Diagnostics.Debug.WriteLine("Dependence of variables:");
        For i := 0 To InclSrc.Count - 1 Do
            System.Diagnostics.Debug.WriteLine("X" + (i + 1).ToString() + " - " + InclSrc.Item[i].Name);
        End For;
        For i := 0 To Res.GetUpperBound(1Do
            For j := 0 To Res.GetUpperBound(0Do
                If i <> j Then
                    System.Diagnostics.Debug.Write("X" + (i + 1).ToString() + "," + "X" + (j + 1).ToString());
                    If ((Res[j, i] As integer) = 1Then
                        System.Diagnostics.Debug.WriteLine("there is Granger conditionality");
                    Else
                        System.Diagnostics.Debug.WriteLine("there is no Granger conditionality");
                    End If;
                End If;
            End For;
            System.Diagnostics.Debug.WriteLine("");
        End For;
    End If;
End Sub;

See also:

IMsMetaModelVisualController