IModelling.MovAvgR

Syntax

MovAvgR(Input: ITimeSeries;

        Period: IMsPeriod;

        [WindowSize: Integer = 5;]

        [Casewise: MsCasewise = 0]): Variant;

Parameters

Input. Output variable.

Period. Period, at which the method is calculated

WindowSize. Window size.

Casewise. Missing data treatment method.

Description

The MovAvgR method transforms the variable by the moving average method using the R package.

Comments

Features of setting parameters:

The moving average method is based on representing a series as a sum of a sufficiently smooth trend and a random component.

Integration with R must be set up in the repository to use this method. To set up integration, see the How to Set Up Integration with R? section.

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 at least one input variable.

Integration with R must be set up in the repository. To set up integration, see the How to Set Up Integration with R? section.

Add links to the Metabase and Ms system assemblies.

Sub ProcAvg;
Var
    Mb: IMetabase;
    ModelSpace, ModelObj: IMetabaseObject;
    Transf: IMsFormulaTransform;
    Formula: IMsFormula;
    Model: IMsModel;
    Determ: IMsDeterministicTransform;
    TransVar: IMsFormulaTransformVariable;
    Slice: IMsFormulaTransformSlice;
    TermInfo: IMsFormulaTermInfo;
    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;
    Expr := Determ.Expression;
    Expr.References := "Ms";
    Expr.AsString := "MovAvgR(" + TermInfo.TermInnerText + ", SetPeriod(" +
        """" + "01.01.2000" + """" + "," + """" + "01.01.2015" + """" + "),  3, MsCasewise.Yes)";
    If Expr.Valid
        Then ModelObj.Save;
        Else Debug.WriteLine(Model is not saved: error in formula);
    End If;
End Sub ProcAvg;

After executing the example the model will transform the first input variable by moving average method at the period of 2000-2015. The Casewise missing data treatment method is used. Calculation is executed using the R package.

Example of Use in Expressions

Expression 1:

MovAvgR({Chicago - population[t]}, SetPeriod("01.01.2000", "01.01.2015"), 4, MsCasewise.Yes)

Result: moving average method is applied to the Chicago - population time series, window size is set to four at the period of 2000-2015. The Casewise missing data treatment method is used. 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:

MovAvgR(X1, SetPeriod("01.01.1990", "01.01.2015"))

Result: moving average method using the R package is applied to the X1 factor.

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

See also:

IModelling | The Calculation Method  moving average | Time Series Database: Calculator | Modeling container: Editing Regressor or Formula