DFTest: IMsVariableTest;
The DFTest property returns parameters of calculation of the augmented Dickey-Fuller test.
To set calculation options, 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("Variable key: " + 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 statistic: ");
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.
See also: