Add(Slice: IMsFormulaTransformSlice): IMsFormulaTerm;
Slice is data slice in the variable, to which the term is referred.
The Add method adds a new term to the collection. Data slice, from which the data is taken, is passed by the Slice parameter.
Sub Main;
Var
MB: IMetabase;
CrInf: IMetabaseObjectCreateInfo;
MObj: IMetabaseObject;
Model: IMsModel;
Trans: IMsFormulaTransform;
VarTrans: IMsFormulaTransformVariable;
Tree: IMsFormulaTransformSlicesTree;
Slice: IMsFormulaTransformSlice;
Selector: IMsFormulaTransformSelector;
Formula: IMsFormula;
NonLinear: IMsNonLinearRegressionTransform;
Varr: IMsVariable;
TransVar: IMsFormulaTransformVariable;
TermX1: IMsFormulaTerm;
s: String;
Begin
MB := MetabaseClass.Active;
//create a model
CrInf := Mb.CreateCreateInfo;
CrInf.ClassId := MetabaseObjectClass.KE_CLASS_MSMODEL;
CrInf.Id := "New_NonLinReg";
CrInf.Name := "New_NonLinReg";
CrInf.Parent := Mb.ItemById("KONT_MODEL");
CrInf.Permanent := False;
MObj := Mb.CreateObject(CrInf).Edit;
Model := MObj As IMsModel;
Trans := Model.Transform;
// add output variable
Varr := MB.ItemByIdNamespace("Var_1", MB.ItemById("KONT_MODEL").Key).Bind As IMsVariable;
Model.Output.Add(Varr);
VarTrans := Trans.Outputs.Item(0);
Tree := VarTrans.SlicesTree(VarTrans);
Slice := Tree.CreateSlice(1);
Selector := Model.Transform.CreateSelector;
Selector.Slice := Slice;
Formula := Model.Transform.Transform(Selector);
Formula.Kind := MsFormulaKind.NonLinearRegression;
NonLinear := Formula.Method As IMsNonLinearRegressionTransform;
//adding a factor
Varr := MB.ItemByIdNamespace("Var_Factor", MB.ItemById("KONT_MODEL").Key).Bind As IMsVariable;
Model.Input.Add(Varr);
TransVar := Model.Transform.Inputs.Item(0);
//comparison of term to the slice in the variable
TermX1 := NonLinear.Operands.Add(TransVar.SlicesTree(VarTrans).CreateSlice(1));
//changing term parameters
TermX1.Inversion := MsInversion.DLog;
TermX1.InversionLag := MsInversionLag.PrecidingYear;
TermX1.UpdateSlice(TermX1.Slice, "-1");
//creation of the equation
s := "A0+" + Trans.SliceToTerm(TermX1.Slice, TermX1.Lag.AsString) + "/10 ";
NonLinear.Expression.AsString := s;
MObj.Save;
End Sub Main;
After executing the example, a new model is created in the modeling container. The output variable and one factor are added to the created model. To make the equation, create the term that refers to the slice of the first input variable. The way of initial transformation of data and lag is changed for the term. The method of non-linear regression is used for model calculation.
See also: