BalancedSample: Boolean;
BalancedSample: boolean;
The BalancedSample property determines which observations are used to estimate correlation coefficients.
The property is relevant if the missing data treatment uses the MissingDataMethod.Casewise method. The missing data treatment method is determined by the IMsVariableTestSettings.MissingData property.
Available values BalancedSample:
True. The default value. All observations on the certain point are excluded from the calculation if there is missing data on this point at least in one variable.
False. Correlation coefficients are calculated by all possible data.
Executing the example requires that the repository contains a modeling container with the MODEL_SPACE identifier containing a modeling problem with the WEB_PROBLEM identifier. This problem must contain the internal metamodel containing the internal time series database and variables.
Add links to the Metabase, Ms system assemblies.
Sub PairCorrelation;
Var
mb: IMetabase;
msKey: Integer;
Problem: IMsProblem;
MetaObj: IMetabaseObject;
Meta: IMsMetaModel;
MetaVisual: IMsMetaModelVisualController;
VarTest: IMsVariableTest;
PairCorr: IMsPairCorrelationTestSettings;
Sources: IMsVariableTestDataList;
TestData: IMsVariableTestData;
i, j: Integer;
VarArray: Array;
Slice: IMsFormulaTransformSlice;
TestRes: IMsVariableTestResults;
Res: Array;
Begin
mb := MetabaseClass.Active;
// Get modelling container key
msKey := mb.GetObjectKeyById("MODEL_SPACE");
// Get modeling problem
Problem := mb.ItemByIdNamespace("WEB_PROBLEM", msKey).Bind As IMsProblem;
// Get metamodel
MetaObj := Problem.MetaModel As IMetabaseObject;
Meta := MetaObj.Edit As IMsMetaModel;
MetaVisual := Meta.VisualController;
// Get correlation matrix calculation parameters
VarTest := MetaVisual.PairCorrelationTest;
PairCorr := VarTest.Settings As IMsPairCorrelationTestSettings;
// Correlation coefficients are calculated by all possible data
PairCorr.BalancedSample := False;
// Add checking variables only with the annual frequency
Sources := PairCorr.IncludedSources;
If Sources.Count > 0 Then
Sources.Clear;
End If;
VarArray := MetaVisual.GetVariables;
For i := 0 To VarArray.Length - 1 Do
Slice := VarArray[i] As IMsFormulaTransformSlice;
If Slice.Level = DimCalendarLevel.Year Then
TestData := Sources.Add(Slice, Slice.Key);
Debug.WriteLine("Key of tested variable: " + TestData.EntryKey.ToString);
End If;
End For;
// Setting calculation period
PairCorr.StartDate := DateTime.Parse("01.01.2000");
PairCorr.EndDate := DateTime.Parse("01.01.2014");
// Perform calculation
TestRes := VarTest.Execute;
// Display correlation matrix in the console window
Res := TestRes.ResValueMatrix;
For i := 0 To Res.GetUpperBound(1) Do
For j := 0 To Res.GetUpperBound(2) Do
Debug.Write(Res[i, j]);
Debug.Write("; ");
End For;
Debug.WriteLine("");
End For;
End Sub PairCorrelation;
Example execution result: for all variables of the annual frequency, which are contained in the calculation chain of the metamodel, the correlation matrix is calculated. 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;
…
Public Shared Sub Main(Params: StartParams);
Var
mb: IMetabase;
msKey: uinteger;
Problem: IMsProblem;
MetaObj: IMetabaseObject;
Meta: IMsMetaModel;
MetaVisual: IMsMetaModelVisualController;
VarTest: IMsVariableTest;
PairCorr: IMsPairCorrelationTestSettings;
Sources: IMsVariableTestDataList;
TestData: IMsVariableTestData;
i, j: Integer;
VarArray: Array;
Slice: IMsFormulaTransformSlice;
TestRes: IMsVariableTestResults;
Res: Array;
Begin
mb := Params.Metabase;
// Get modelling container key
msKey := mb.GetObjectKeyById("MODEL_SPACE");
// Get modeling problem
Problem := mb.ItemByIdNamespace["WEB_PROBLEM", msKey].Bind() As IMsProblem;
// Get metamodel
MetaObj := Problem.MetaModel As IMetabaseObject;
Meta := MetaObj.Edit() As IMsMetaModel;
MetaVisual := Meta.VisualController;
// Get correlation matrix calculation parameters
VarTest := MetaVisual.PairCorrelationTest;
PairCorr := VarTest.Settings As IMsPairCorrelationTestSettings;
// Correlation coefficients are calculated by all possible data
PairCorr.BalancedSample := False;
// Add checking variables only with the annual frequency
Sources := PairCorr.IncludedSources;
If Sources.Count > 0 Then
Sources.Clear();
End If;
VarArray := MetaVisual.GetVariables();
For i := 0 To VarArray.Length - 1 Do
Slice := VarArray[i] As IMsFormulaTransformSlice;
If Slice.Level = DimCalendarLevel.dclYear Then
TestData := Sources.Add(Slice, Slice.Key);
System.Diagnostics.Debug.WriteLine("Key of tested variable: " + TestData.EntryKey.ToString());
End If;
End For;
// Setting calculation period
PairCorr.StartDate := DateTime.Parse("01.01.2000");
PairCorr.EndDate := DateTime.Parse("01.01.2014");
// Perform calculation
TestRes := VarTest.Execute();
// Display correlation matrix in the console window
Res := TestRes.ResValueMatrix;
For i := 0 To Res.GetUpperBound(1) Do
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 Sub;
See also: