DFTest: IMsVariableTest;
DFTest: Prognoz.Platform.Interop.Ms.IMsVariableTest;
The DFTest property returns parameters of calculation of the augmented Dickey-Fuller test.
To set calculation parameters, use the IMsDFTestSettings interface.
Executing the example requires that the repository contains a modeling container with the MS identifier, containing a modeling problem with the MODEL_DFTEST_WEB identifier. The problem must be created in the web application and contain several variables.
Add links to the Dimensions, Metabase, Ms, Stat, Transform system assemblies.
Sub DFTest;
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;
DF: IMsDFTestSettings;
TestRes: IMsVariableTestResults;
Res: Array;
Begin
mb := MetabaseClass.Active;
// Get modelling container key
msKey := mb.GetObjectKeyById("MS");
// Get modeling problem
Problem := mb.ItemByIdNamespace("MODEL_DFTEST_WEB", msKey).Edit As IMsProblem;
// Get metamodel
Meta := Problem.MetaModel;
MetaVisual := Meta.VisualController;
// Set common parameters of calculating the descriptive statistics
Test := MetaVisual.DFTest;
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);
// Specify lag and transformation of the first variable
If i = 0 Then
TestData.Lag := "1";
TestData.InversionInfo.Inversion := TsInversion.Log;
End If;
// Display the information about the variable in the console window
Debug.WriteLine("Original name of variable: " + TestData.Slice.Name);
Debug.WriteLine("name of the variable considering transformations and lag: " + TestData.Name);
Debug.WriteLine("Key of variable: " + TestData.EntryKey.ToString);
Debug.WriteLine("");
End If;
End For;
// Set calculation parameters of the Dickey-Fuller test
DF := CommonSett As IMsDFTestSettings;
// Determinenbsp;autoregressionnbsp;order
DF.AutoRegressionOrder := 1;
// Set the parameters of differentiation of the series
DF.TestedSeries := ADFTestedSeriesType.FirstDifference;
// Set the model type
DF.EquationType := ADFEquationType.ConstantTrend;
// Check if test can be calculated by means of R package
If DF.SupportsR
Then
DF.UseR := True;
Debug.WriteLine("Test is calculated by means of connection to R");
Else
Debug.WriteLine("Test does not support calculation by means of R");
End If;
Debug.WriteLine("");
// Perform calculation of the test
TestRes := Test.Execute;
// Output results
If TestRes.Error <> "" Then
Debug.WriteLine(TestRes.Error);
Else
Res := TestRes.ResValueMatrix;
Debug.WriteLine("Augmented Dickey-Fuller test");
Debug.WriteLine("");
For i := 0 To Res.GetUpperBound(1) Do
Select Case i
Case 0: Debug.Write("Variables: ");
Case 1: Debug.Write("ADF statistics: ");
Case 2: Debug.Write("1% significance: ");
Case 3: Debug.Write("5% of significance: ");
Case 4: Debug.Write("10% of significance: ");
Case 5: Debug.Write("Stationarity: ");
Case 6: Debug.Write("Error: ");
End Select;
For j := 0 To Res.GetUpperBound(2) Do
Debug.Write(Res[i, j]); Debug.Write("; ");
End For;
Debug.WriteLine("");
End For;
End If;
End Sub DFTest;
Example execution result: the augmented Dickey-Fuller test is calculated for all variables of the annual frequency contained in the metamodel calculation chain using R package. The results are displayed in the console window.
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;
Imports Prognoz.Platform.Interop.Transform;
…
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;
DF: IMsDFTestSettings;
TestRes: IMsVariableTestResults;
Res: Array;
Begin
mb := Params.Metabase;
// Get modelling container key
msKey := mb.GetObjectKeyById("MS");
// Get modeling problem
Problem := mb.ItemByIdNamespace["MODEL_DFTEST_WEB", msKey].Edit() As IMsProblem;
// Get metamodel
Meta := Problem.MetaModel;
MetaVisual := Meta.VisualController;
// Set common parameters of calculating the descriptive statistics
Test := MetaVisual.DFTest;
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);
// Specify lag and transformation of the first variable
If i = 0 Then
TestData.Lag := "1";
TestData.InversionInfo.Inversion := TsInversion.tsiLog;
End If;
// Display the information about the variable in the console window
System.Diagnostics.Debug.WriteLine("Original name of variable: " + TestData.Slice.Name);
System.Diagnostics.Debug.WriteLine("Name of the variable considering transformations and lag: " + TestData.Name);
System.Diagnostics.Debug.WriteLine("");
End If;
End For;
// Set calculation parameters of the Dickey-Fuller test
DF := CommonSett As IMsDFTestSettings;
// Determinenbsp;autoregressionnbsp;order
DF.AutoRegressionOrder := 1;
// Set the parameters of differentiation of the series
DF.TestedSeries := ADFTestedSeriesType.adftstLevel;
// Set the model type
DF.EquationType := ADFEquationType.adfetConstantTrend;
// Check if test can be calculated by means of R package
If DF.SupportsR
Then
DF.UseR := True;
System.Diagnostics.Debug.WriteLine("Test is calculated by means of connection to R");
Else
System.Diagnostics.Debug.WriteLine("Test does not support calculation by means of R");
End If;
System.Diagnostics.Debug.WriteLine("");
// Perform calculation of the test
TestRes := Test.Execute();
// Output results
If TestRes.Error <> "" Then
System.Diagnostics.Debug.WriteLine(TestRes.Error);
Else
Res := TestRes.ResValueMatrix;
System.Diagnostics.Debug.WriteLine("Augmented Dickey-Fuller test");
System.Diagnostics.Debug.WriteLine("");
For i := 0 To Res.GetUpperBound(1) Do
Select Case i
Case 0: System.Diagnostics.Debug.Write("Variables: ");
Case 1: System.Diagnostics.Debug.Write("ADF statistics: ");
Case 2: System.Diagnostics.Debug.Write("1% of significance: ");
Case 3: System.Diagnostics.Debug.Write("5% of significance: ");
Case 4: System.Diagnostics.Debug.Write("10% of significance: ");
Case 5: System.Diagnostics.Debug.Write("Stationarity: ");
Case 6: System.Diagnostics.Debug.Write("Error: ");
End Select;
For j := 0 To Res.GetUpperBound(0) Do
System.Diagnostics.Debug.Write(Res[j, i]); System.Diagnostics.Debug.Write("; ");
End For;
System.Diagnostics.Debug.WriteLine("");
End For;
End If;
End Sub;
See also: