IMsLinearRegressionTransform.DiagnosticTests

Fore Syntax

DiagnosticTests: IMsDiagnosticTestList;

Fore.NET Syntax

DiagnosticTests: Prognoz.Platform.Interop.Ms.IMsDiagnosticTestList;

Description

The DiagnosticTests property returns a set of diagnostic tests of the model.

Comments

The test set cannot be changed, that is, the existing test cannot be removed or the custom test cannot be added.

Fore Example

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[1Of 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(19900101);
    Calc.Period.IdentificationEndDate := DateTime.ComposeDay(20071231);
    Calc.Period.ForecastStartDate := DateTime.ComposeDay(20080101);
    Calc.Period.ForecastEndDate := DateTime.ComposeDay(20101231);
// 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:

Then testing is performed, and 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.Cubes;
Imports Prognoz.Platform.Interop.Ms;
Imports Prognoz.Platform.Interop.Stat;

Public Shared Sub Main(Params: StartParams);
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[1Of integer;
    Stat: ISpecificationTestStatistic;
    i: Integer;
    Coef: ICoefficients;
    CoefNames: System.Array;
Begin
    mb := Params.Metabase;
    ContModelDescr := mb.ItemById["MODEL_SPACE_7_2"];
    ModelObj := mb.ItemByIdNamespace["MODEL_35617", 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[NullNull];
// Find missing variables criterion
    Test := pTestList.FindByType[MsDiagnosticTestType.mdttOmittedVariables];
    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_35618", 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.Parse("1990.01.01");
    Calc.Period.IdentificationEndDate := DateTime.Parse("2007.12.31");
    Calc.Period.ForecastStartDate := DateTime.Parse("2008.01.01");
    Calc.Period.ForecastEndDate := DateTime.Parse("2010.12.31");
// Perform testing
    Res := Test.Execute(Calc As IMsMethodCalculation, Coord);
// display results
    Stat := Res.ChiTest;
System.Diagnostics.Debug.WriteLine("--Chi-square statistic--");     System.Diagnostics.Debug.Write("     Value: ");
    System.Diagnostics.Debug.WriteLine(Stat.Statistic);
    System.Diagnostics.Debug.Write("     Probability: ");
    System.Diagnostics.Debug.WriteLine(Stat.Probability);
    If Res.FTestResult Then
        System.Diagnostics.Debug.WriteLine("     The hypothesis of added series insignificance is accepted");
    Else
        System.Diagnostics.Debug.WriteLine("     The hypothesis of added series insignificance is rejected");
    End If;
    Stat := Res.FTest;
System.Diagnostics.Debug.WriteLine("--Fisher statistic--");     System.Diagnostics.Debug.Write("     Value: ");
    System.Diagnostics.Debug.WriteLine(Stat.Statistic);
    System.Diagnostics.Debug.Write("     Probability: ");
    System.Diagnostics.Debug.WriteLine(Stat.Probability);
    If Res.ChiTestResult Then
        System.Diagnostics.Debug.WriteLine("     The hypothesis of added series insignificance is accepted");
    Else
        System.Diagnostics.Debug.WriteLine("     The hypothesis of added series insignificance is rejected");
    End If;
    System.Diagnostics.Debug.WriteLine("-- Standard error --");
    System.Diagnostics.Debug.WriteLine(Res.SummaryStatistics.SE);
    System.Diagnostics.Debug.WriteLine("-- Values of model coefficients --");
    Coef := Res.ModelCoefficients.Coefficients;
    For i := 0 To Coef.Estimate.Length - 1 Do
        System.Diagnostics.Debug.WriteLine("   Coefficient " + i.ToString());
        System.Diagnostics.Debug.Write("     Value: ");
        System.Diagnostics.Debug.WriteLine(Coef.Estimate.GetValue(i));
        System.Diagnostics.Debug.Write("     Probability: ");
        System.Diagnostics.Debug.WriteLine(Coef.Probability.GetValue(i));
    End For;
    CoefNames := Res.CoefficientsARNames;
    If CoefNames.Length <> 0 Then
        System.Diagnostics.Debug.WriteLine("-- Autoregression coefficients --");
        Coef := Res.CoefficientsAR;
        For i := 0 To CoefNames.Length - 1 Do
            System.Diagnostics.Debug.WriteLine("   Coefficient " + CoefNames.GetValue(i));
            System.Diagnostics.Debug.Write("     Value: ");
            System.Diagnostics.Debug.WriteLine(Coef.Estimate.GetValue(i));
            System.Diagnostics.Debug.Write("     Probability: ");
            System.Diagnostics.Debug.WriteLine(Coef.Probability.GetValue(i));
        End For;
    End If;
    CoefNames := Res.CoefficientsMANames;
    If CoefNames.Length <> 0 Then
    System.Diagnostics.Debug.WriteLine("-- Moving average coefficients --");
    Coef := Res.CoefficientsMA;
        For i := 0 To CoefNames.Length - 1 Do
            System.Diagnostics.Debug.WriteLine("   Coefficient " + CoefNames.GetValue(i));
            System.Diagnostics.Debug.Write("     Value: ");
            System.Diagnostics.Debug.WriteLine(Coef.Estimate.GetValue(i));
            System.Diagnostics.Debug.Write("     Probability: ");
            System.Diagnostics.Debug.WriteLine(Coef.Probability.GetValue(i));
        End For;
    End If;
End Sub;

See also:

IMsLinearRegressionTransform