Below is the example of using the GetMs operation to calculate an equation. The request contains an instance of opened modeling container, equation calculation pattern, and parameters of operation execution. The response contains an instance of the model that contains an equation with calculation results.
To execute the example the equation must be calculated using the Linear Regression method.
{ "GetMs" : { "tMs" : { "id" : "IEHFOKNBPENBFOAEDMNIFBMAGBJFMILEEKEMODKJPMDBDAAN!M!S!CKILIGLNBPENBFOAEGCFPILNFBENOEAEENLANPEIMKOMICGHG" }, "tArg" : { "pattern" : { "obInst" : "false", "all" : "false", "item" : { "key" : "89669", "problem" : { "metamodel" : { "calculationChain" : "Get", "calcChainPattern" : { "modelPattern" : { "transform" : { "outputs" : "Get", "formulaCount" : "true", "formulas" : { "method" : { "series" : "true" } }, "displayId" : "true", "equationsFormula" : { "method" : "" }, "series" : "Get", "kind" : "true", "displaySettings" : "true", "additionalAttributes" : "true", "calculationType" : "true", "calculationDirection" : "true", "transformVariable" : { "slices" : "Get", "transformSlice" : { "selection" : "Get" } } }, "stochastic" : "true", "calculationPeriod" : "true", "useModelPeriod" : "true", "useExistingData" : "true", "treatNullsAsZeros" : "true", "autoName" : "true", "generatedName" : "true", "period" : "true", "isExclusive" : "true", "useAutoPeriod" : "true" }, "entryKeys" : { "l" : "4" } } } } } }, "execParams" : { "k" : "0", "modelKeys" : { "l" : "4" }, "pdlIndex" : "1", "scenarioKeys" : "", "execMethod" : "true", "execCoefficients" : "true", "execEvaluateSeries" : "true", "execPairCorrelationMatrix" : "true", "execARMACoefficients" : "true", "execPDLStatCoefficients" : "true", "execStatCoefficients" : "true" } } } }
{ "GetMsResult" : { "id" : { "id" : "IEHFOKNBPENBFOAEDMNIFBMAGBJFMILEEKEMODKJPMDBDAAN!M!S!CKILIGLNBPENBFOAEGCFPILNFBENOEAEENLANPEIMKOMICGHG" }, "meta" : { "item" : { "k" : "89669", "id" : "MODEL_NEW", "n" : "MODEL_NEW", "vis" : "1", "type" : "Problem", "problemMd" : { "metamodel" : { "k" : "89670", "calculationChain" : { "its" : { "Item" : { "k" : "4", "id" : "OBJ4", "n" : "MyOutputVavable|A[t] = A0 + PDL(TS(MyInputVavable[t+1] * 8, Linear), 1, 1) + [AR(1)=A1], (From parent)-(From parent)", "vis" : "1", "type" : "Model", "excluded" : "0", "graphMeta" : "", "model" : { "transform" : { "outputs" : { "its" : { "Item" : { "k" : "1", "id" : "VARIABLES_89670", "n" : "Variables", "vis" : "1", "slices" : { "its" : { "Item" : { "k" : "0", "id" : "MyOutputVavable|A", "n" : "MyOutputVavable|A", "vis" : "1", "variableKey" : "1", "stubKey" : "89671", "selections" : { "its" : { "Item" : { "id" : { "id" : "89683" }, "variant" : "2" } } }, "aggregator" : "None", "parametrizedDimensions" : { "its" : { "Item" : { "dimension" : "0", "parameter" : "0" } } }, "unitInfo" : { "unit" : "4294967295", "measure" : "4294967295", "baseUnit" : "4294967295", "unitsDimensionKey" : "0" }, "level" : "Year" } } }, "variableStubKey" : "89671", "parameterID" : "", "kind" : "Stub", "attributeId" : "", "attributeType" : "Series" } } }, "formulaCount" : "1", "formulas" : { "its" : { "it" : [ { "k" : "0", "kind" : "LinearRegression", "method" : { "linearRegression" : { "constantMode" : "ManualEstimate", "constantValue" : "0.5", "confidenceLevel" : "0.85", "ARMA" : { "orderAR" : { "l" : "1" }, "orderMA" : "", "calcInitMode" : "Auto", "initAR" : "", "initMA" : "", "initIntercept" : "NaN", "estimationMethod" : "LevenbergMarquardt", "tolerance" : "0.0001", "maxIteration" : "500", "coefficientsAR" : { "estimate" : "", "standardError" : "", "tStatistic" : "", "probability" : "" }, "coefficientsMA" : { "estimate" : "", "standardError" : "", "tStatistic" : "", "probability" : "" }, "diff" : "0", "diffSeas" : "1", "orderARSeas" : "", "orderMASeas" : "", "initARSeas" : "", "initMASeas" : "", "periodSeas" : "0", "coefficientsARSeas" : { "estimate" : "", "standardError" : "", "tStatistic" : "", "probability" : "" }, "coefficientsMASeas" : { "estimate" : "", "standardError" : "", "tStatistic" : "", "probability" : "" }, "useARMAasInstrums" : "1", "useAnalyticDeriv" : "1", "useBackCast" : "1" }, "missingData" : { "specifiedVector" : "", "method" : "Casewise", "methodParameter" : "5", "specifiedValue" : "0", "specifiedTerm" : { "k" : "4294967295" } }, "coefficients" : { "d" : "-0.08396406739747959" }, "pairCorrelationMatrix" : { "data" : { "d" : [ "1", "-0.7626332420071756", "-0.7626332420071756", "1" ] } }, "armaCoefficients" : { "orderAR" : { "l" : "1" }, "orderMA" : "", "coefficientsAR" : { "estimate" : { "d" : "0.8682687093029638" }, "standardError" : { "d" : "0.07799376856974333" }, "tStatistic" : { "d" : "11.13253949931325" }, "probability" : { "d" : "2.867720505506099e-10" } }, "coefficientsMA" : { "estimate" : "", "standardError" : "", "tStatistic" : "", "probability" : "" }, "orderARSeas" : "", "orderMASeas" : "", "coefficientsARSeas" : { "estimate" : "", "standardError" : "", "tStatistic" : "", "probability" : "" }, "coefficientsMASeas" : { "estimate" : "", "standardError" : "", "tStatistic" : "", "probability" : "" } }, "pdlStatCoefficients" : { "estimatesSum" : "0", "stdErrSum" : "0", "tStatSum" : "0" }, "statCoefficients" : { "intercept" : { "mode" : "ManualEstimate", "estimate" : "0.5", "standardError" : "NaN", "tStatistic" : "NaN", "probability" : "NaN" }, "coefficients" : { "estimate" : { "d" : "-0.08396406739747959" }, "standardError" : { "d" : "0.02130633695023525" }, "tStatistic" : { "d" : "-3.94080256937608" }, "probability" : { "d" : "0.0007483835396404626" } } } }, "name" : "0.5000 + PDL(X1, 1, 1) + [AR(1)=0.8683]", "series" : { "input" : { "k" : "4294967295", "lag" : "0", "inversion" : { "type" : "None", "lag" : "PrecidingValue", "previousLag" : "-1", "seasonality" : "None", "dependence" : "Linear", "K" : "3" }, "slice" : { "k" : "0", "id" : "MyOutputVavable|A", "n" : "MyOutputVavable|A", "vis" : "1", "variableKey" : "1", "stubKey" : "89671", "selections" : { "its" : { "Item" : { "id" : { "id" : "89683" }, "variant" : "2" } } }, "aggregator" : "None", "parametrizedDimensions" : { "its" : { "Item" : { "dimension" : "0", "parameter" : "0" } } }, "unitInfo" : { "unit" : "4294967295", "measure" : "4294967295", "baseUnit" : "4294967295", "unitsDimensionKey" : "0" }, "level" : "Year" }, "date" : "1899-12-30" }, "addFactor" : { "k" : "4294967295" } }, "evaluateSeries" : { "its" : { "Item" : { "scenarioKey" : "4294967295", "fact" : { "d" : [ "3", "7", "2", "6", "4", "1", "5", "3.42857143", "3.28571429", "3.14285714", "3", "2.85714286", "2.71428571", "2.57142857", "2.42857143", "2.28571429", "2.14285714", "2", "1.85714286", "1.71428571", "1.57142857", "1.42857143", "1.28571429", "1.14285714", "1", "0.85714286", "0.71428571", "0.57142857", "NaN" ] }, "modelling" : { "d" : [ "NaN", "6.796910634289292", "1.14416876286019", "4.975957312453287", "4.442458519583021", "3.514234055349136", "0.9217015149591798", "4.40704993968997", "3.0549012709732", "2.943136473929621", "2.831371668203355", "2.71960687115977", "2.607842074116201", "2.496077268389927", "2.384312471346351", "2.272547674302773", "2.160782877259189", "2.049018071532927", "1.937253274489343", "1.825488477445767", "1.713723671719501", "1.601958874675926", "1.490194077632337", "1.378429280588761", "1.266664474862499", "NaN", "NaN", "NaN", "NaN" ] }, "residuals" : { "d" : [ "NaN", "0.2030893657107082", "0.8558312371398105", "1.024042687546713", "-0.4424585195830213", "-2.514234055349136", "4.07829848504082", "-0.9784785096899702", "0.2308130190268001", "0.199720666070379", "0.1686283317966448", "0.1375359888402303", "0.106443635883799", "0.07535130161007286", "0.04425895865364904", "0.01316661569722655", "-0.01792573725918922", "-0.04901807153292737", "-0.0801104144893432", "-0.1112027674457667", "-0.1422951017195007", "-0.1733874446759258", "-0.2044797876323372", "-0.2355721405887614", "-0.2666644748624989", "NaN", "NaN", "NaN", "NaN" ] }, "input" : { "d" : [ "3", "7", "2", "6", "4", "1", "5", "3.42857143", "3.28571429", "3.14285714", "3", "2.85714286", "2.71428571", "2.57142857", "2.42857143", "2.28571429", "2.14285714", "2", "1.85714286", "1.71428571", "1.57142857", "1.42857143", "1.28571429", "1.14285714", "1", "0.85714286", "0.71428571", "0.57142857", "NaN", "NaN", "NaN" ] }, "indicators" : { "its" : { "it" : [ { "termToText" : "{MyInputVavable[t+1]}", "serie" : { "d" : [ "32", "16", "56", "60", "72.8", "85.59999999999999", "98.40000000000001", "111.2", "124", "136.8", "149.6", "162.4", "175.2", "188", "200.8", "213.6", "226.4", "239.2", "252", "264.8", "277.6", "290.4", "303.2", "316", "328.8", "NaN", "NaN", "NaN", "NaN", "NaN", "NaN" ] }, "transformedSerie" : { "d" : [ "-28.54510344827582", "-52.73702463054184", "-20.92894581280785", "-25.12086699507387", "-20.51278817733989", "-15.90470935960589", "-11.29663054187189", "-6.688551724137909", "-2.080472906403926", "2.527605911330056", "7.135684729064025", "11.74376354679805", "16.35184236453202", "20.95992118226602", "25.56800000000001", "30.17607881773398", "34.78415763546798", "39.39223645320195", "44.00031527093594", "48.60839408866994", "53.21647290640394", "57.82455172413788", "62.43263054187187", "67.0407093596059", "71.6487881773399", "NaN", "NaN", "NaN", "NaN", "NaN", "NaN" ] }, "inversion" : { "type" : "TS", "lag" : "PrecidingValue", "previousLag" : "-1", "seasonality" : "None", "dependence" : "Linear", "K" : "3" }, "entryKey" : "1" } ] } } } }, "dates" : { "it" : [ "1990A1", "1991A1", "1992A1", "1993A1", "1994A1", "1995A1", "1996A1", "1997A1", "1998A1", "1999A1", "2000A1", "2001A1", "2002A1", "2003A1", "2004A1", "2005A1", "2006A1", "2007A1", "2008A1", "2009A1", "2010A1", "2011A1", "2012A1", "2013A1", "2014A1", "2015A1", "2016A1", "2017A1", "2018A1", "2019A1", "2020A1" ] } }, "inversionInfo" : { "type" : "None", "lag" : "PrecidingValue", "previousLag" : "-1", "seasonality" : "None", "dependence" : "Linear", "K" : "3" }, "doUseR" : "0", "supportsR" : "1" }, "calendarLevel" : "Year", "outputSliceKey" : "0" } ] } }, "displayId" : "0", "series" : { "its" : "" }, "kind" : "Simple", "displaySettings" : { "displayTermsAs" : "Derive" }, "additionalAttributes" : "", "calculationType" : "Serie", "calculationDirection" : "Forward" }, "stochastic" : "1", "calculationPeriod" : "Forecast", "useModelPeriod" : "1", "useExistingData" : "0", "treatNullsAsZeros" : "0", "autoName" : "1", "period" : { "identificationStartDate" : "1990-01-01", "identificationEndDate" : "2018-04-24", "forecastStartDate" : "2018-04-25", "forecastEndDate" : "2020-01-01", "identificationStartDateParamID" : "", "identificationEndDateParamID" : "", "forecastStartDateParamID" : "", "forecastEndDateParamID" : "", "autoPeriod" : "28672", "identificationStartOffset" : "0", "identificationEndOffset" : "0", "forecastEndOffset" : "0", "isIdentStartCorrect" : "1", "isIdentEndCorrect" : "1", "isForecastEndCorrect" : "1" }, "isExclusive" : "1", "useAutoPeriod" : "1", "generatedName" : "MyOutputVavable|A[t] = A0 + PDL(TS(MyInputVavable[t+1] * 8, Linear), 1, 1) + [AR(1)=A1]", "warnings" : "", "readOnly" : "0" } } } }, "visualController" : { "userRPath" : "", "isRExist" : "0" }, "suppressEmptyFilter" : { "suppressEmpty" : "0", "suppressEmptyArea" : "SerieBounds" }, "readOnly" : "0", "variableTestUseR" : "0", "calculateIdentOnFact" : "0" }, "useScenarios" : "0", "readOnly" : "0" } } } } }
The GetMsLinearRegr function calculates the specified equation. Input parameters:
ms. Opened modeling container instance.
modelKey. Key of the model that contains the equation.
eqKey. Equation key.
After executing the function returns a model that contains calculated equation. Calculation results are displayed in the console window. The following auxiliary procedures are used to output the results: printPDL and PrintSeries described in this section; PrintCoef, printARMA, PrintArray, and PrintSeries, described in the Calculating Equation section.
public static MsCalculationChainEntry GetMsLinearRegr(MsId ms, ulong modelKey, ulong eqKey) { var getMsOp = new GetMs(); // Set operation execution parameters getMsOp.tMs = ms; getMsOp.tArg = new GetMsArg() { // Set data getting pattern pattern = new MsMdPattern() { obInst = false, all = false, item = new MsItemPattern() { // Specify calculated model key key = modelKey, problem = new MsProblemPattern() { metamodel = new MsMetaModelPattern() { calculationChain = ListOperation.Get, calcChainPattern = new MsCalculationChainPattern() { // Specify calculated equation key entryKeys = new long[] { (long)eqKey }, modelPattern = new MsModelPattern() { autoName = true, calculationPeriod = true, generatedName = true, isExclusive = true, period = true, stochastic = true, treatNullsAsZeros = true, useAutoPeriod = true, useExistingData = true, useModelPeriod = true, transform = new MsFormulaTransformPattern() { additionalAttributes = true, calculationDirection = true, calculationType = true, displayId = true, displaySettings = true, formulaCount = true, outputs = ListOperation.Get, series = ListOperation.Get, kind = true, formulas = new TsFormulaPattern() { method = new TsMethodPattern() { series = true } }, equationsFormula = new TsFormulaPattern() { method = new TsMethodPattern() { } }, transformVariable = new MsFormulaTransformVariablePattern() { slices = ListOperation.Get, transformSlice = new MsFormulaTransformSlicePattern() { selection = ListOperation.Get } } } } } } } } }, // Set equation calculation parameters execParams = new MsMdExecParams() { k = 0, execMethod = true, execEvaluateSeries = true, scenarioKeys = new long[] { }, execPDLStatCoefficients = true, pdlIndex = 1, execPairCorrelationMatrix = true, execStatCoefficients = true, execCoefficients = true, execARMACoefficients = true, modelKeys = new long[] { (long)eqKey } } }; // Create a proxy object for operation calculation var somClient = new SomPortTypeClient(); GetMsResult getMsResult = somClient.GetMs(getMsOp); MsMetaModel meta = getMsResult.meta.item.problemMd.metamodel; MsCalculationChainEntry chainEntry = meta.calculationChain.its.GetValue(0) as MsCalculationChainEntry; // Display errors and warnings MsModel eq = chainEntry.model; if (eq.warnings != null) { Console.WriteLine("-- Warnings --"); Console.WriteLine("".PadRight(3) + printArray(eq.warnings)); } if (eq.error == null) //Check if errors occurred on equation calculation { // Equation is calculated without errors, get calculation results TsFormula formula = eq.transform.formulas.its.GetValue(0) as TsFormula; TsLinearRegressionMethod linR = formula.method.linearRegression; Console.WriteLine("-- Equation coefficient values --"); Console.WriteLine("".PadRight(3) + printArray(linR.coefficients)); // Get equation coefficient values and display into console window PrintCoef(linR.statCoefficients); // Get values of autoregression coefficient, moving average coefficient and display into console window printARMA(linR.armaCoefficients); Console.WriteLine("-- Correlation matrix --"); MsPairCorrelationMatrix pm = linR.pairCorrelationMatrix; if (pm.error != null) { Console.WriteLine("".PadRight(3) + "error: " + pm.error); } Console.WriteLine("".PadRight(3) + printArray(pm.data)); Console.WriteLine("-- Lag variable coefficients --"); MsPDLCoefficients pdl = linR.pdlStatCoefficients; printPDL(pdl); // Display calculated series Console.WriteLine("-- Available data series --"); printSeries(formula.method.series); // Get calculated values and display into console window MsEvaluateSeriesResult seriesRes = formula.method.evaluateSeries; printSeries(seriesRes); } else // Errors occurred on equation calculation { Console.WriteLine("-- Errors --"); Console.WriteLine(eq.error); } // Return the model that contains equation return chainEntry; } // Procedure of displaying coefficient values for lag variables public static void printPDL(MsPDLCoefficients pdl) { Console.WriteLine("".PadRight(3) + " - sum of coefficients: " + pdl.estimatesSum); Console.WriteLine("".PadRight(3) + " - sum of standard errors: " + pdl.stdErrSum); Console.WriteLine("".PadRight(3) + " - sum of t-statistics: " + pdl.tStatSum); Console.WriteLine("".PadRight(3) + " - Coefficients -"); PrintStatCoef(6, pdl as StatCoefficients); } // Procedure of displaying calculated series identifiers public static void printSeries(MsMethodSeries series) { if (series.input != null) {Console.WriteLine("".PadRight(3) + " - input series");}; if (series.fitted != null) { Console.WriteLine("".PadRight(3) + " - smoothed series"); }; if (series.forecast != null) { Console.WriteLine("".PadRight(3) + " - forecasting series"); }; if (series.residuals != null) { Console.WriteLine("".PadRight(3) + " - residual series"); }; if (series.lowerConfidenceLevel != null) { Console.WriteLine("".PadRight(3) + " - lower confidence limit"); }; if (series.upperConfidenceLevel != null) { Console.WriteLine("".PadRight(3) + " - upper confidence limit"); }; if (series.dynamicLowerConfidenceLevel != null) { Console.WriteLine("".PadRight(3) + " - lower dynamic confidence limit"); }; if (series.dynamicUpperConfidenceLevel != null) { Console.WriteLine("".PadRight(3) + " - upper dynamic confidence limit"); }; if (series.addFactor != null) { Console.WriteLine("".PadRight(3) + " - forecast correction factor"); }; }
See also:
Working with Modeling Container | The Linear Regression Method