TermInfo: IMsFormulaTermInfo;
The TermInfo property determines term parameters.
Executing the example requires that the repository contains a modeling container with the KONT_MODEL identifier. The container has the VAR_! variable, which will be used as a modeling one, and the VAR_FACTOR variable used as a factor.
Add links to the Metabase, Ms, Stat system assemblies.
Sub UserProc;
Var
MB: IMetabase;
Kont: IMetabaseObjectDescriptor;
CrInf: IMetabaseObjectCreateInfo;
MObj: IMetabaseObject;
Model: IMsModel;
Trans: IMsFormulaTransform;
VarTrans: IMsFormulaTransformVariable;
Tree: IMsFormulaTransformSlicesTree;
Slice: IMsFormulaTransformSlice;
Selector: IMsFormulaTransformSelector;
Formula: IMsFormula;
NonLinear: IMsNonLinearRegressionTransform;
Varr: IVariableStub;
TransVar: IMsFormulaTransformVariable;
TermX1: IMsFormulaTerm;
TermX1Info: IMsFormulaTermInfo;
Begin
MB := MetabaseClass.Active;
Kont := Mb.ItemById("KONT_MODEL");
//create a model
CrInf := Mb.CreateCreateInfo;
CrInf.ClassId := MetabaseObjectClass.KE_CLASS_MSMODEL;
CrInf.Id := "New_NonLinReg";
CrInf.Name := "New_NonLinReg";
CrInf.Parent := Kont;
MObj := Mb.CreateObject(CrInf).Edit;
Model := MObj As IMsModel;
Trans := Model.Transform;
//add an output variable
Varr := MB.ItemByIdNamespace("Var_1",Kont.Key).Bind As IVariableStub;
Trans.Outputs.Add(Varr);
VarTrans := Trans.Outputs.Item(0);
Tree := VarTrans.SlicesTree(VarTrans);
Slice := Tree.CreateSlice(1);
Selector := Trans.CreateSelector;
Selector.Slice := Slice;
Formula := Trans.Transform(Selector);
Formula.Kind := MsFormulaKind.NonLinearRegression;
Formula.Level := DimCalendarLevel.Year;
NonLinear := Formula.Method As IMsNonLinearRegressionTransform;
//add a factor
Varr := MB.ItemByIdNamespace("Var_Factor",Kont.Key).Bind As IVariableStub;
Trans.Inputs.Add(Varr);
TransVar := Trans.Inputs.Item(0);
Slice := TransVar.SlicesTree(VarTrans).CreateSlice(1);
//Compare term with slice in variable
TermX1 := NonLinear.Operands.Add(Slice);
TermX1Info := TermX1.TermInfo;
//change parameters of the first term
TermX1Info.Inversion:= MsInversion.DLog;
TermX1Info.InversionLag:= MsInversionLag.PrecidingYear;
TermX1Info.Lag := "-1";
TermX1.TermInfo := TermX1Info;
//create an equation
NonLinear.Expression.AsString:= "A0+" + TermX1Info.TermToInnerText + "/10";
MObj.Save;
End Sub UserProc;
After executing the example, a new model is created in the modeling container. An output variable and one input variable are added to the created model. A term that refers to the input variable slice is created to compose the equation. The way of initial transformation of data and lag is changed for the term. The non-linear regression method will be used for model calculation.
See also: