SigmaLower: Double;
SigmaLower: double;
The SigmaLower property determines a lower sigma limit.
Most of real time series include outliers. They can distort seasonality and trend estimations. The X11 method enables the user to reduce outliers influence by excluding the values that lie outside the specified range or by converting these values. Range width is set by the lower and the upper sigma limits (IMsCensus2Transform.SigmaUpper).
Executing the example requires that the repository contains a modeling container with the MS identifier and a time series database with the TSDB identifier. The modeling container must include a model with the MODEL_CENSUS2 identifier.
Add links to the Cubes, Dimensions, Metabase, Ms, Stat system assemblies.
Sub UserProc;
Var
MB: IMetabase;
ModelCont, RubrDescr: IMetabaseObjectDescriptor;
Model: IMsModel;
Transform: IMsFormulaTransform;
TransformVarables: IMsFormulaTransformVariables;
Stub: IVariableStub;
TransVar: IMsFormulaTransformVariable;
Tree: IMsFormulaTransformSlicesTree;
Slice: IMsFormulaTransformSlice;
Selector: IMsFormulaTransformSelector;
Formula: IMsFormula;
CENS: IMsCensus2Transform;
Expl: IMsFormulaTerm;
Av, W: Array Of Double;
Info: IMsFormulaTermInfo;
Begin
// Get current repository
MB := MetabaseClass.Active;
// Get modeling container
ModelCont := MB.ItemById("MS");
// Get model
Model := MB.ItemByIdNamespace("MODEL_CENSUS2", ModelCont.Key).Edit As IMsModel;
// Get object that is used to set up model parameters
Transform := Model.Transform;
// Get object that is used to work with output variable
TransformVarables := Transform.Outputs;
// Get time series database (TSDB)
RubrDescr := Mb.ItemById("TSDB");
// Cast obtained TSDB to abstract data source
Stub := RubrDescr.Bind As IVariableStub;
// Use TSDB as a data source of output variable
TransVar := TransformVarables.Add(Stub);
// Set output variable slice
Tree := TransVar.SlicesTree(TransVar);
Slice := Tree.CreateSlice(1);
// Get model settings for output variable slice
Selector := Transform.CreateSelector;
Selector.Slice := Slice;
Formula := Transform.Transform(Selector);
// Set calendar frequency of calculation
Formula.Level := DimCalendarLevel.Month;
// Specify calculation method: X11
Formula.Kind := MsFormulaKind.Census2;
// Get method parameters
CENS := Formula.Method As IMsCensus2Transform;
// Get object that is used to work with unloaded variables
TransformVarables := Transform.Series;
// Clear unloaded variables collection
TransformVarables.Clear;
// Specify the series, to which data is unloaded after prior adjustment
TransVar := TransformVarables.Add(Stub);
Tree := TransVar.SlicesTree(TransVar);
Slice := Tree.CreateSlice(2);
Info := Transform.CreateTermInfo;
Info.Slice := Slice;
CENS.B1Term := Info;
// Specify the series, to which source series' seasonal component is unloaded
TransVar := TransformVarables.Add(Stub);
Tree := TransVar.SlicesTree(TransVar);
Slice := Tree.CreateSlice(3);
Info := Transform.CreateTermInfo;
Info.Slice := Slice;
CENS.D10Term := Info;
// Specify the series, to which seasonal adjustment is unloaded
TransVar := TransformVarables.Add(Stub);
Tree := TransVar.SlicesTree(TransVar);
Slice := Tree.CreateSlice(4);
Info := Transform.CreateTermInfo;
Info.Slice := Slice;
CENS.D11Term := Info;
// Specify the series, to which trend-cycle component of series is unloaded
TransVar := TransformVarables.Add(Stub);
Tree := TransVar.SlicesTree(TransVar);
Slice := Tree.CreateSlice(5);
Info := Transform.CreateTermInfo;
Info.Slice := Slice;
CENS.D12Term := Info;
// Specify the series, to which irregular component of series is unloaded
TransVar := TransformVarables.Add(Stub);
Tree := TransVar.SlicesTree(TransVar);
Slice := Tree.CreateSlice(6);
Info := Transform.CreateTermInfo;
Info.Slice := Slice;
CENS.D13Term := Info;
// Set weight coefficients for days of week
W := New Double[7];
W[0] := 1.17;
W[1] := 1.00;
W[2] := 1.12;
W[3] := 1.10;
W[4] := 0.95;
W[5] := 0.98;
W[6] := 1.07;
CENS.DailyWeights := W;
// Display output series name
Expl := CENS.Explained;
Debug.WriteLine(Expl.TermToText);
// Set missing data treatment method
CENS.MissingData.Method := MissingDataMethod.PrevValue;
// Set moving average
Av := New Double[12];
Av[0] := 0.02; Av[4] := 0.12;Av[8] := 0.01;
Av[1] := 0.1; Av[5] := 0.11; Av[9] := 0.7;
Av[2] := 0.2; Av[6] := 0.3; Av[10] := 0.4;
Av[3] := 0.5; Av[7] := 0.45; Av[11] := 0.3;
CENS.MovingAverage := Av;
//Set seasonality type
CENS.Seasonality := SeasonalityType.Multiplicative;
// Set upper and lower sigma limits
CENS.SigmaLower := 1.5;
CENS.SigmaUpper := 2.5;
// Set working days adjustment
CENS.TraidingDaysAdjustment := TraidingDaysAdj.Auto;
// Set holiday adjustment
CENS.HolidayAdj := Census2HolidayAdjType.C2hatEaster;
// Use sliding spans
CENS.SlidingSpans := True;
// Save changes
(Model As IMetabaseObject).Save;
End Sub UserProc;
After executing the example new parameters for X11 method calculation are set for the MODEL_CENSUS2 model, the input and output variables are determined. The model is calculated, the data is unloaded to the specified variables.
The requirements and result of the Fore.NET example execution match with those in the Fore example.
Imports Prognoz.Platform.Interop.Cubes;
Imports Prognoz.Platform.Interop.Dimensions;
Imports Prognoz.Platform.Interop.Ms;
Imports Prognoz.Platform.Interop.Stat;
…
Public Shared Sub Main(Params: StartParams);
Var
MB: IMetabase;
ModelCont, RubrDescr: IMetabaseObjectDescriptor;
Model: IMsModel;
Transform: IMsFormulaTransform;
TransformVarables: IMsFormulaTransformVariables;
Stub: IVariableStub;
TransVar: IMsFormulaTransformVariable;
Tree: IMsFormulaTransformSlicesTree;
Slice: IMsFormulaTransformSlice;
Selector: IMsFormulaTransformSelector;
Formula: IMsFormula;
CENS: IMsCensus2Transform;
Expl: IMsFormulaTerm;
Av, W: Array Of Double;
Info: IMsFormulaTermInfo;
Begin
// Get current repository
MB := Params.Metabase;
// Get modeling container
ModelCont := MB.ItemById["MS"];
// Get model
Model := MB.ItemByIdNamespace["MODEL_CENSUS2", ModelCont.Key].Edit() As IMsModel;
// Get object to set up model parameters
Transform := Model.Transform;
// Get object to work with output variable
TransformVarables := Transform.Outputs;
// Get time series database (TSDB)
RubrDescr := Mb.ItemById["TSDB"];
// Cast obtained TSDB to abstract data source
Stub := RubrDescr.Bind() As IVariableStub;
// Use TSDB as a data source of output variable
TransVar := TransformVarables.Add(Stub);
// Specify output variable slice
Tree := TransVar.SlicesTree[TransVar];
Slice := Tree.CreateSlice(1);
// Get model settings for output variable slice
Selector := Transform.CreateSelector();
Selector.Slice := Slice;
Formula := Transform.Transform[Selector];
// Set calendar frequency of calculation
Formula.Level := DimCalendarLevel.dclMonth;
// Specify calculation method: X11
Formula.Kind := MsFormulaKind.mfkCensus2;
// Get method parameters
CENS := Formula.Method As IMsCensus2Transform;
// Get object that is used to work with unloaded variables
TransformVarables := Transform.Series;
// Clear unloaded variables collection
TransformVarables.Clear();
// Specify the series, to which data is unloaded after prior adjustment
TransVar := TransformVarables.Add(Stub);
Tree := TransVar.SlicesTree[TransVar];
Slice := Tree.CreateSlice(2);
Info := Transform.CreateTermInfo();
Info.Slice := Slice;
CENS.B1Term := Info;
// Specify the series, to which seasonal component of source series is unloaded
TransVar := TransformVarables.Add(Stub);
Tree := TransVar.SlicesTree[TransVar];
Slice := Tree.CreateSlice(3);
Info := Transform.CreateTermInfo();
Info.Slice := Slice;
CENS.D10Term := Info;
// Specify the series, to which seasonal component is unloaded
TransVar := TransformVarables.Add(Stub);
Tree := TransVar.SlicesTree[TransVar];
Slice := Tree.CreateSlice(4);
Info := Transform.CreateTermInfo();
Info.Slice := Slice;
CENS.D11Term := Info;
// Specify the series, to which trend-cycle component of series is unloaded
TransVar := TransformVarables.Add(Stub);
Tree := TransVar.SlicesTree[TransVar];
Slice := Tree.CreateSlice(5);
Info := Transform.CreateTermInfo();
Info.Slice := Slice;
CENS.D12Term := Info;
// Specify the series, to which irregular component of series is unloaded
TransVar := TransformVarables.Add(Stub);
Tree := TransVar.SlicesTree[TransVar];
Slice := Tree.CreateSlice(6);
Info := Transform.CreateTermInfo();
Info.Slice := Slice;
CENS.D13Term := Info;
// Set weight coefficients for days of week
W := New Double[7];
W[0] := 1.17;
W[1] := 1.00;
W[2] := 1.12;
W[3] := 1.10;
W[4] := 0.95;
W[5] := 0.98;
W[6] := 1.07;
CENS.DailyWeights := W;
// Display output series name
Expl := CENS.Explained;
System.Diagnostics.Debug.WriteLine(Expl.TermToText());
// Set missing data treatment method
CENS.MissingData.Method := MissingDataMethod.mdmPrevValue;
// Set moving average
Av := New Double[12];
Av[0] := 0.02; Av[4] := 0.12;Av[8] := 0.01;
Av[1] := 0.1; Av[5] := 0.11; Av[9] := 0.7;
Av[2] := 0.2; Av[6] := 0.3; Av[10] := 0.4;
Av[3] := 0.5; Av[7] := 0.45; Av[11] := 0.3;
CENS.MovingAverage := Av;
// Set seasonality type
CENS.Seasonality := SeasonalityType.sstMultiplicative;
// Set lower and upper sigma limits
CENS.SigmaLower := 1.5;
CENS.SigmaUpper := 2.5;
// Set type of working day adjustment
CENS.TraidingDaysAdjustment := TraidingDaysAdj.tdaAuto;
// Set holiday adjustment
CENS.HolidayAdj := Census2HolidayAdjType.C2hatEaster;
// Use sliding spans
CENS.SlidingSpans := True;
// Save changes
(Model As IMetabaseObject).Save();
End Sub;
See also: