DiagnosticTests: IMsDiagnosticTestList;
The DiagnosticTests property returns a set of diagnostic tests of the model.
The test set cannot be changed, that is, the existing test cannot be removed or the custom test cannot be added.
Executing the example requires that the repository contains a modeling container with the MODEL_SPACE identifier containing a model of linear regression (OLS estimation) with the MODEL identifier. The model contains more than one factor. The container should also include a variable with the VAR identifier. This variable must not be present in the MODEL model.
Add links to the Metabase, Ms, Stat, Cubes system assemblies.
Sub DiagnosticTests;
Var
mb: IMetabase;
ContModelDescr: IMetabaseObjectDescriptor;
ModelObj: IMetabaseObject;
pModel: IMsModel;
pTransform: IMsFormulaTransform;
pFormula: IMsFormula;
pRegress: IMsLinearRegressionTransform;
pTestList: IMsDiagnosticTestList;
Test: IMsDiagnosticTest;
OmittedVarTest: IMsOmittedVariablesTestSettings;
Info: IMsFormulaTermInfo;
VarTrans: IMsFormulaTransformVariable;
Calc: IMsMethodCalculation;
Coord: IMsFormulaTransformCoord;
Expl: IMsCompositeFormulaTerm;
Res: IMsDiagnosticTestResults;
Varr: IVariableStub;
pVar: IMsFormulaTransformVariable;
ar: Array[1] Of integer;
Stat: ISpecificationTestStatistic;
i: Integer;
Coef: ICoefficients;
CoefNames: Array Of String;
Begin
mb := MetabaseClass.Active;
ContModelDescr := mb.ItemById("MODEL_SPACE");
ModelObj := mb.ItemByIdNamespace("MODEL", ContModelDescr.Key).Edit;
pModel := ModelObj As IMsModel;
pTransform := pModel.Transform;
pFormula := pTransform.FormulaItem(0);
pRegress := pFormula.Method As IMsLinearRegressionTransform;
// get diagnostic tests set
pTestList := pRegress.DiagnosticTests;
// Find missing variables criterion
Test := pTestList.FindByType(MsDiagnosticTestType.OmittedVariables);
OmittedVarTest := Test.Settings As IMsOmittedVariablesTestSettings;
// Refresh parameters
OmittedVarTest.RefreshIncluded;
// Keep the first model factor in the explained series
ar[0] := 0;
OmittedVarTest.IncludedExplanatories := ar;
// Get tested variable
Varr := MB.ItemByIdNamespace("VAR", ContModelDescr.Key).Bind As IVariableStub;
Info := pTransform.CreateTermInfo;
pVar := pTransform.Inputs.Add(Varr);
VarTrans := pTransform.Outputs.Item(0);
Info.Slice := pVar.SlicesTree(VarTrans).CreateSlice(1);
// Include obtained variable to the test
Expl := OmittedVarTest.OmittedExplanatories.Add;
Expl.Expression.AsString := Info.TermInnerText;
// set testing parameters
Coord := pTransform.CreateCoord(VarTrans);
Calc := pModel.CreateCalculation As IMsMethodCalculation;
Calc.Period.IdentificationStartDate := DateTime.ComposeDay(1990, 01, 01);
Calc.Period.IdentificationEndDate := DateTime.ComposeDay(2007, 12, 31);
Calc.Period.ForecastStartDate := DateTime.ComposeDay(2008, 01, 01);
Calc.Period.ForecastEndDate := DateTime.ComposeDay(2010, 12, 31);
// Perform testing
Res := Test.Execute(Calc As IMsMethodCalculation, Coord);
// display results
Stat := Res.ChiTest;
Debug.WriteLine("--Chi-square statistic--"); Debug.Write(" Value: ");
Debug.WriteLine(Stat.Statistic);
Debug.Write(" Probability: ");
Debug.WriteLine(Stat.Probability);
If Res.FTestResult Then
Debug.WriteLine(" The hypothesis of added series insignificance is accepted");
Else
Debug.WriteLine(" The hypothesis of added series insignificance is rejected");
End If;
Stat := Res.FTest;
Debug.WriteLine("--Fisher statistic--"); Debug.Write(" Value: ");
Debug.WriteLine(Stat.Statistic);
Debug.Write(" Probability: ");
Debug.WriteLine(Stat.Probability);
If Res.ChiTestResult Then
Debug.WriteLine(" The hypothesis of added series insignificance is accepted");
Else
Debug.WriteLine(" The hypothesis of added series insignificance is rejected");
End If;
Debug.WriteLine("-- Standard error --");
Debug.WriteLine(Res.SummaryStatistics.SE);
Debug.WriteLine("-- Model coefficients values --");
Coef := Res.ModelCoefficients.Coefficients;
For i := 0 To Coef.Estimate.Length - 1 Do
Debug.WriteLine(" Coefficient " + i.ToString);
Debug.Write(" Value: ");
Debug.WriteLine(Coef.Estimate[i]);
Debug.Write(" Probability: ");
Debug.WriteLine(Coef.Probability[i]);
End For;
CoefNames := Res.CoefficientsARNames;
If CoefNames.Length <> 0 Then
Debug.WriteLine("-- Autoregression coefficients --");
Coef := Res.CoefficientsAR;
For i := 0 To CoefNames.Length - 1 Do
Debug.WriteLine(" Coefficient " + CoefNames[i]);
Debug.Write(" Value: ");
Debug.WriteLine(Coef.Estimate[i]);
Debug.Write(" Probability: ");
Debug.WriteLine(Coef.Probability[i]);
End For;
End If;
CoefNames := Res.CoefficientsMANames;
If CoefNames.Length <> 0 Then
Debug.WriteLine("-- Moving average coefficients --");
Coef := Res.CoefficientsMA;
For i := 0 To CoefNames.Length - 1 Do
Debug.WriteLine(" Coefficient " + CoefNames[i]);
Debug.Write(" Value: ");
Debug.WriteLine(Coef.Estimate[i]);
Debug.Write(" Probability: ");
Debug.WriteLine(Coef.Probability[i]);
End For;
End If;
End Sub DiagnosticTests;
The example describes setup of the diagnostic test parameters (missing variables criterion). Parameters that are set:
Explanatory series - the first model factor.
Added variable - the VAR variable.
Then testing is performed, and the results are displayed in the console window.
See also: