MedianSmoothR(Input: ITimeSeries;
Period: IMsPeriod;
[WindowSize: Integer = 5];
[Casewise: MsCasewise = 0]): Variant;
Input. Output variable.
Period. Period, at which the method is calculated.
WindowSize. Window size.
Casewise. Missing data treatment method.
The MedianSmoothR method applies median smoothing to a variable using the R package.
Features of setting parameters:
Period. If the parameter is set to Null, the method is calculated at the entire time period.
WindowSize. The parameter should have an uneven value.
The main advantage of median smoothing is its robustness to outliers.
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.
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 ProcMedianSmooth;
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 := "MedianSmoothR(" + TermInfo.TermInnerText + ", SetPeriod(" +
"""" + "01.01.2000" + """" + "," + """" + "01.01.2015" + """" + "), 5, MsCasewise.Yes)";
If Expr.Valid
Then ModelObj.Save;
Else Debug.WriteLine(Model is not saved: error in formula);
End If;
End Sub ProcMedianSmooth;
After executing the example the model transforms data of the first input variable using the median smoothing method at the period of 2000-2015. The Casewise method is applied for missing data treatment. Calculation is executed using the R package.
Expression 1:
MedianSmoothR({Chicago - population[t]}, SetPeriod("01.01.2000", "01.01.2015"), 9, MsCasewise.Yes)
Result: median smoothing using the R package at the period 2000-2015 is applied to the Chicago - population time series. Window size is set to nine, missing data is treated using the Casewise method.
Use: it can be used in formulas of cross functional expression editor in any platform tool where it is available.
Expression 2:
MedianSmoothR(X1, SetPeriod("01.01.2005", "01.01.2015"), 3, MsCasewise.Yes)
Result: median smoothing using the R package is applied to the X1 factor, window size is three. The calculation is applied at the period of 2005-2015 by the Casewise missing data treatment method.
Use: it can be used in model formulas of modeling container.
See also:
IModelling | The Calculation Method Median Smoothing | Time Series Database: Calculator | Modeling Container: Editing Regressor or Formula