IModelling.TslsR

Syntax

TslsR(Input: ITimeSeries;
      Period: IMsPeriod;
      ConstantValue: Variant;
      Casewise: MsCasewise;
      Explanatories: Array): Variant;

Parameters

Input. Output variable.

Period. Period, at which the method is calculated.

ConstantValue. Constant used in calculations.

Casewise. Missing data treatment method.

Explanatories. Exogenous and instrumental variables.

Description

The TslsR method models variable data using linear regression (instrumental variables estimation). Calculation is executed using the R package.

Comments

Use the TslsR method only when series mode of calculation is applied.

Integration with R must be set up in the repository to use this method. For details about integration setup see the How to Set Up Integration with R? section.

Features of setting parameters:

Example

Executing the example requires that the repository contains a modeling container with the MS identifier. This container includes a model with the MODEL_D identifier that is calculated by the determinate equation method and contains more than two input variables.

Integration with R must be set up in the repository. For details about integration setup see the How to Set Up Integration with R? section.

Add links to the Metabase and Ms system assemblies.

Sub UserProc;
Var
    Mb: IMetabase;
    ModelSpace, ModelObj: IMetabaseObject;
    Transf: IMsFormulaTransform;
    Formula: IMsFormula;
    Model: IMsModel;
    Determ: IMsDeterministicTransform;
    TransVar: IMsFormulaTransformVariable;
    Slice: IMsFormulaTransformSlice;
    TermInfo: IMsFormulaTermInfo;
    Inp, Instr, Exogen: String;
    Expr: IExpression;
Begin
    // Get repository
    Mb := MetabaseClass.Active;
    // Get modeling container
    ModelSpace := Mb.ItemById("MS").Bind;
    // Get model
    ModelObj := Mb.ItemByIdNamespace("MODEL_D", ModelSpace.Key).Edit;
    Model := ModelObj As IMsModel;
    // Get model calculation parameters
    Transf := Model.Transform;
    Formula := Transf.FormulaItem(0);
    Determ := Formula.Method As IMsDeterministicTransform;
    // Get the first input variable
    TransVar := Transf.Inputs.Item(0);
    Slice := TransVar.Slices.Item(0);
    TermInfo := Transf.CreateTermInfo;
    TermInfo.Slice := Slice;
    // Set mode of passing variable into calculation
    TermInfo.Type := MsFormulaTermType.Pointwise;
    // Get internal view of the variable as a text
    Inp := TermInfo.TermInnerText;
    // Get the second input variable.
    // It will be used as an exogenous variable.
    TransVar := Transf.Inputs.Item(1);
    Slice := TransVar.Slices.Item(0);
    TermInfo := Transf.CreateTermInfo;
    TermInfo.Slice := Slice;
    // Set mode of passing variable into calculation
    TermInfo.Type := MsFormulaTermType.Pointwise;
    // Get internal view of the variable as a text
    Exogen := TermInfo.TermInnerText;
    // Get the third input variable.
    // It will be used as an instrumental variable.
    TransVar := Transf.Inputs.Item(2);
    Slice := TransVar.Slices.Item(0);
    TermInfo := Transf.CreateTermInfo;
    TermInfo.Slice := Slice;
    // Set mode of passing variable into calculation
    TermInfo.Type := MsFormulaTermType.Pointwise;
    // Get internal view of the variable as a text
    Instr := TermInfo.TermInnerText;
    // Get model calculation expression
    Expr := Determ.Expression;
    Expr.References := "Ms;Stat";
    // Set model calculation expression
    Expr.AsString := "TslsR(" + Inp + ", SetPeriod(2000,2015), Estimate," +
        "MsCasewise.Yes, " + Exogen + ", Null, " + Instr + ")";
    // Check if the expression is correct
    If Expr.Valid
        // If the expression is set correctly, save the model
        Then ModelObj.Save;
        // If the expression is incorrect, display a message to the console window 
        Else Debug.WriteLine("Model is not saved: error in the formula");
    End If;
End Sub UserProc;

After executing the example the model will model the first input variable by the linear regression (instrumental variables estimation). Constant value is estimated automatically, the Casewise missing data treatment method is used. Calculation is executed using the R package.

Example of Use in Expressions

Expression 1:

Tsls({Brazil|BCA},Estimate,"","",MsCasewise.Yes,{China|BCA},Null,{Japan|BCA})

TslsR({Chicago - population[t]}, Null, Estimate, MsCasewise.No, {Mexico - unemployment rate[t]}, Null, {Anchorage - population[t]})

Result: the Chicago - Population time series will be modeled at the entire time period using the linear regression (instrumental variables estimation) method by the the following parameters: constant value is estimated automatically, exogenous variable - the Mexico - Unemployment Rate time series, instrumental variable - the Ancorage Population time series, missing data treatment is not applied. Calculation is executed using the R package.

Use: it can be used in formulas of cross functional expression editor in any platform tool where it is available.

Expression 2:

TslsR(X1, SetPeriod(2000, 2015), None, MsCasewise.Yes, X4, Null, X2, X3)

Result: the X1 factor is modeled using the linear regression method (instrumental variables estimation) by the following parameters: calculation period - 2000-2015, the constant is not specified, the X4 factor is used as the exogenous variable, the X2 and X3 factors are used as instrumental variables, the Casewise missing data treatment method is used. Calculation is executed using the R package.

Use: it can be used in model formulas of modeling container.

See also:

IModelling | Instrumental variables method | Time Series Database: Calculator Modeling Container: The Linear regression (instrumental variables estimation) Model, Editing Regressor or Formula