IModelling.Ols

Fore Syntax

Ols(Input: ITimeSeries;
    Period: IMsPeriod;

    ConstantValue: Variant;

    AROrder: String;

    MAOrder: String;

    Casewise: MsCasewise;

    Explanatories: Array): Variant;

Fore.NET Syntax

Ols(Context: Prognoz.Platform.Interop.Fore.ForeRuntimeContext;
    Input: Prognoz.Platform.Interop.Ms.ITimeSeries;
    Period: Prognoz.Platform.Interop.Ms.IMsPeriod;

    ConstantValue: object;

    AROrder: string;

    MAOrder: string;

    Casewise: Prognoz.Platform.Interop.Ms.MsCasewise;

    Explanatories: array of object): object;

Parameters

Context. Context. The parameter is used only in Fore.NET.

Input. Output variable.

Period. Period, at which the method is calculated. If the parameter is set to Null, the method is calculated at the entire time period.

ConstantValue. Constant used in calculations.

AROrder. Autoregression order.

MAOrder. Moving average order.

Casewise. Missing data treatment method.

Explanatories. Explanatory variables.

Description

The Ols method models a variable with the help of linear regression (OLS estimation).

Comment

The Ols method should be used only on series calculation mode.

ConstantValue. The constant value can be determined by the user or estimated automatically. Use the IModelling.Estimate method to estimate values automatically. If the model must be calculated without constant, use the IModelling.None method.

AROrder, MAOrder. Parameters are set in the string view. Specify the numbers or ranges of autoregression or moving average orders separated by commas. The range of autoregression or moving average orders is specified via the sign -. For example: AROrder = 1-3,5.

MAOrder. If the moving average order is set, back-casting can be used to estimate its coefficients. Back-casting is used by default. If back-casting must be disabled, the MAOrder parameter must contain the string "backcast.No". For example: MAOrder = "1-4;backcast.No".

Explanatories. Terms, corresponding to variables, are specified via comma. Remember that the number of explanatory variables (m) must satisfy the inequality: 0 < m < n-1 for model with constant and 0 < m < n for model without constant, where n is the number of observations in the output variable.

Fore Example

Executing the example requires that the repository contains a modeling container with the MS identifier. This container contains a model with the MODEL_D identifier calculated using by determinate expression method and containing more than one factor.

Add links to the Metabase, 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_1, Inp_2: String;
    Expr: IExpression;
Begin
    Mb := MetabaseClass.Active;
    ModelSpace := Mb.ItemById("MS").Bind;
    ModelObj := Mb.ItemByIdNamespace("MODEL_D", ModelSpace.Key).Edit;
    Model := ModelObj As IMsModel;
    Transf := Model.Transform;
    Formula := Transf.FormulaItem(0);
    Determ := Formula.Method As IMsDeterministicTransform;
    TransVar := Transf.Inputs.Item(0);
    Slice := TransVar.Slices.Item(0);
    TermInfo := Transf.CreateTermInfo;
    TermInfo.Slice := Slice;
    TermInfo.Type := MsFormulaTermType.Pointwise;
    Inp_1 := TermInfo.TermInnerText;
    TransVar := Transf.Inputs.Item(1);
    Slice := TransVar.Slices.Item(0);
    TermInfo := Transf.CreateTermInfo;
    TermInfo.Slice := Slice;
    TermInfo.Type := MsFormulaTermType.Pointwise;
    Inp_2 := TermInfo.TermInnerText;
    Expr := Determ.Expression;
    Expr.References := "Ms";
    Expr.AsString := "Ols(" + Inp_1 + ", SetPeriod(" +
        """" + "01.01.2000" + """" + "," + """" + "01.01.2015" + """" +
        "), Estimate, """ + "1" + """, """ + "" + """, MsCasewise.Yes, " + Inp_2 + ")";
    If Expr.Valid Then
        ModelObj.Save;
    Else
        Debug.WriteLine("Model is not saved: error in formula");
    End If;
End Sub UserProc;

After executing the example the model models the first input variable using linear regression (OLS estimation) for the period from 2000 to 2015. The value of constant is estimated automatically. Calculation is executed using the Casewise missing data treatment method.

Fore.NET Example

The requirements and result of the Fore.NET example execution match with those in the Fore example.

Imports Prognoz.Platform.Interop.Ms;
Imports Prognoz.Platform.Interop.ForeSystem;

Public Shared Sub Main(Params: StartParams);
Var
    Mb: IMetabase;
    ModelSpace, ModelObj: IMetabaseObject;
    Transf: IMsFormulaTransform;
    Formula: IMsFormula;
    Model: IMsModel;
    Determ: IMsDeterministicTransform;
    TransVar: IMsFormulaTransformVariable;
    Slice: IMsFormulaTransformSlice;
    TermInfo: IMsFormulaTermInfo;
    Inp_1, Inp_2: String;
    Expr: IExpression;
Begin
    Mb := Params.Metabase;
    ModelSpace := Mb.ItemById["MS"].Bind();
    ModelObj := Mb.ItemByIdNamespace["MODEL_D", ModelSpace.Key].Edit();
    Model := ModelObj As IMsModel;
    Transf := Model.Transform;
    Formula := Transf.FormulaItem[0];
    Determ := Formula.Method As IMsDeterministicTransform;
    TransVar := Transf.Inputs.Item[0];
    Slice := TransVar.Slices.Item[0];
    TermInfo := Transf.CreateTermInfo();
    TermInfo.Slice := Slice;
    TermInfo.Type := MsFormulaTermType.mfttPointwise;
    Inp_1 := TermInfo.TermInnerText;
    TransVar := Transf.Inputs.Item[1];
    Slice := TransVar.Slices.Item[0];
    TermInfo := Transf.CreateTermInfo();
    TermInfo.Slice := Slice;
    TermInfo.Type := MsFormulaTermType.mfttPointwise;
    Inp_2 := TermInfo.TermInnerText;
    Expr := Determ.Expression;
    Expr.References := "Ms";
    Expr.AsString := "Ols(" + Inp_1 + ", SetPeriod(" +
        """" + "01.01.2000" + """" + "," + """" + "01.01.2015" + """" +
        "), Estimate, """ + "1" + """, """ + "" + """, MsCasewise.Yes, " + Inp_2 + ")";
    If Expr.Valid Then
        ModelObj.Save();
    Else
        System.Diagnostics.Debug.WriteLine("Model is not saved: error in the formula");
    End If;
End Sub;

Example of Use in Expressions

Expression 1:

Ols({Brazil|BCA[t]},SetPeriod("01.01.2002", "01.01.2015"), None,"","", MsCasewise.Yes,{China|BCA})

Result: the Brazil|BCA series will be modeled by the linear regression method (OLS estimation) for the period from 2002 to 2016 by the following parameters: constant is not used, autoregression and moving average orders are not set, explanatory variable is the China|BCA exponent, calculation is executed using the Casewise missing data treatment method.

Use: it can be used in formulas of calculated series of time series database and in formulas of attribute-based models of modeling container.

Expression 2:

Ols(X1, Null, Estimate, "1", "2;backcast.No", MsCasewise.Yes, X2, X3)

Result: the X1 factor will be modeled by the linear regression method (OLS estimation) by the following parameters: constant is estimated by the IModelling.Estimate method, autoregression order is 1, moving average order is not set, explanatory variables are the X2 and the X3 factors; calculation is executed using the Casewise missing data treatment method.

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

See also:

IModelling | Least Squares Method | Time Series Database: Calculator, Linear Regression   Modeling Container: The Linear Regression (OLS Estimation) Model, Editing Regressor or Formula