Add(Model: IMsModel);
Model. Added model.
The Add method adds a model to the collection.
Executing the example requires that the repository contains a modeling container with the CONT_MODEL identifier. This container must include models with the MODEL and MODEL_EX identifiers, and variables with the X1, Y1, X2, and Y2 identifiers.
Sub Main;
Var
Model, Model_ex: IMsModel;
Desc: IMetabaseObjectDescriptor;
obj: IMetabaseObject;
ModelSpace: IMetabaseObjectDescriptor;
mb: IMetabase;
Equations: IMsLinearEquationsTransform;
Method: IMsMethod;
X1, X2, Y1, Y2, XY2, XY1: IMsFormulaTransformVariable;
Outputs, Inputs: IMsFormulaTransformVariables;
Selector: IMsFormulaTransformSelector;
Formula, f1, f2: IMsFormula;
lr: IMsLinearRegressionTransform;
CompositeTerm: IMsCompositeFormulaTerm;
info: IMsFormulaTermInfo;
Trans: IMsFormulaTransform;
vY1, vY2, vX1, vX2: IMsVariable;
Begin
mb := MetabaseClass.Active;
ModelSpace := mb.ItemById("CONT_MODEL");
Desc := mb.ItemByIdNamespace("MODEL", ModelSpace.Key);
obj := Desc.Edit;
Model := obj As IMsModel;
Trans := Model.Transform;
Outputs := Trans.Outputs;
Outputs.Clear;
Inputs := Trans.Inputs;
Inputs.Clear;
Trans.Kind := MsModelKind.LinearEquations;
Method := Model.Transform.EquationsFormula.Method;
Equations := Method As IMsLinearEquationsTransform;
Equations.ExternalEquations.Clear;
Model_ex := mb.ItemByIdNamespace("MODEL_EX", ModelSpace.Key).Bind As IMsModel;
Equations.ExternalEquations.Add(Model_ex);
Equations.MissingData.Method := MissingDataMethod.LinTrend;
// Endogenous variables
vY1 := mb.ItemByIdNamespace("Y1", ModelSpace.Key).Bind As IMsVariable;
vY2 := mb.ItemByIdNamespace("Y2", ModelSpace.Key).Bind As IMsVariable;
vX1 := mb.ItemByIdNamespace("X1", ModelSpace.Key).Bind As IMsVariable;
vX2 := mb.ItemByIdNamespace("X2", ModelSpace.Key).Bind As IMsVariable;
Y1 := Outputs.Add(vY1 As IVariableStub);
Y2 := Outputs.Add(vY2 As IVariableStub);
X1 := Inputs.Add(vX1 As IVariableStub);
X2 := Inputs.Add(vX2 As IVariableStub);
XY2 := Inputs.Add(vY2 As IVariableStub);
XY1 := Inputs.Add(vY1 As IVariableStub);
// First equation in the system
Selector := Model.Transform.CreateSelector;
Selector.Slice := Y1.Slices.Add(Null);
Trans := Model.Transform;
Formula := Trans.Transform(Selector);
Formula.Kind := MsFormulaKind.LinearRegression;
lr := Formula.Method As IMsLinearRegressionTransform;
lr.MissingData.Method := MissingDataMethod.PrevValue;
lr.HasConstant := True;
CompositeTerm := lr.Explanatories.Add;
info := trans.CreateTermInfo;
info.Slice := X1.Slices.Add(Null);
CompositeTerm.Expression.AsString := info.TermInnerText;
CompositeTerm := lr.Explanatories.Add;
info := trans.CreateTermInfo;
info.Slice := XY2.Slices.Add(Null);
CompositeTerm.Expression.AsString := info.TermInnerText;
f1 := Formula;
Equations.EstimateSimultaneously(f1) := True;
// Second equation in the system
Selector := Model.Transform.CreateSelector;
Selector.Slice := Y2.Slices.Add(Null);
Trans := Model.Transform;
Formula := Trans.Transform(Selector);
Formula.Kind := MsFormulaKind.LinearRegression;
lr := Formula.Method As IMsLinearRegressionTransform;
lr.HasConstant := False;
CompositeTerm := lr.Explanatories.Add;
info := trans.CreateTermInfo;
info.Slice := X2.Slices.Add(Null);
CompositeTerm.Expression.AsString := info.TermInnerText;
CompositeTerm := lr.Explanatories.Add;
info := trans.CreateTermInfo;
info.Slice := XY1.Slices.Add(Null);
CompositeTerm.Expression.AsString := info.TermInnerText;
f2 := Formula;
Equations.EstimateSimultaneously(f2) := True;
obj.Save;
End Sub Main;
After executing the example the system of simultaneous equations, containing two equations of linear regression and one external model, is created.
See also: