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 with the ARIMA method.
The C# example uses the PrintStat, PrintCoef, PrintStatCoef, printARMA, printSeries, printCorrel, printArray auxiliary operations to display results.
{ "GetMs" : { "tMs" : { "id" : "FMCFHDKCILMBFOAEIPIHNADFKGINDLOELLPHABJCJOEOKJNL!M!S!CLICDCEKCILMBFOAENGEBOPHPJKKIMALEIIAELEOPFIDCCJFF" }, "tArg" : { "pattern" : { "obInst" : "false", "all" : "false", "item" : { "key" : "89669", "problem" : { "metamodel" : { "calculationChain" : "Get", "calcChainPattern" : { "modelPattern" : { "transform" : { "formulas" : { "method" : "" }, "displayId" : "true", "equationsFormula" : { "method" : "" }, "kind" : "true" } }, "entryKeys" : { "l" : "4" } } } } } }, "execParams" : { "k" : "0", "modelKeys" : { "l" : "4" }, "scenarioKeys" : "", "execMethod" : "true", "execSummaryStatistics" : "true", "execCoefficients" : "true", "execEvaluateSeries" : "true", "execARMACoefficients" : "true", "execAutoCorrelation" : "true", "execInitDefault" : "true", "execStatCoefficients" : "true", "execGenerateName" : "true" } } } }
{ "GetMsResult" : { "id" : { "id" : "FMCFHDKCILMBFOAEIPIHNADFKGINDLOELLPHABJCJOEOKJNL!M!S!CLICDCEKCILMBFOAENGEBOPHPJKKIMALEIIAELEOPFIDCCJFF" }, "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, (From parent)-(From parent)", "vis" : "1", "type" : "Model", "excluded" : "0", "graphMeta" : "", "model" : { "transform" : { "formulas" : { "its" : { "it" : [ { "k" : "0", "kind" : "Arima", "method" : { "arima" : { "maxIteration" : "500", "constantMode" : "AutoEstimate", "constantValue" : "21.1", "missingData" : { "specifiedVector" : "", "method" : "Casewise", "methodParameter" : "5", "specifiedValue" : "0", "specifiedTerm" : { "k" : "4294967295" } }, "confidenceLevel" : "0.95", "ARMA" : { "orderAR" : "", "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" }, "explained" : { "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" }, "lag" : "", "key" : "0", "termToText" : "{MyOutputVavable|A[t]}", "termToInnerText" : "@_1:0[]", "termInfo" : { "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" }, "unitInfo" : { "unit" : "4294967295", "measure" : "4294967295", "baseUnit" : "4294967295", "unitsDimensionKey" : "0" }, "included" : "0" }, "autoCorrelation" : { "acf" : { "d" : [ "0.8806007142476413", "0.7755396833857469", "0.6492537711209424", "0.5441074569585843", "0.4357976653696499", "0.3308992057992645", "0.230094344651138", "0.1340653483289803", "0.04349448323650126", "-0.04093598422258941" ] }, "pacf" : { "d" : [ "0.8806007142476413", "0.0003654786750526034", "-0.1503469976514621", "0.009199850923512483", "-0.06627064694467796", "-0.07473420934025392", "-0.05207086459054212", "-0.06025413480285589", "-0.06127247771726842", "-0.05803709524513948" ] }, "qStatistics" : { "d" : [ "22.58132583422224", "40.82566711623952", "54.16802252411557", "63.96468294205459", "70.54856258696468", "74.53415453907314", "76.5627229925804", "77.2896519275377", "77.37066419885673", "77.44691104245111" ] }, "probability" : { "d" : [ "2.014330523714136e-06", "1.364014567961647e-09", "1.033195751176663e-11", "4.251043961289724e-13", "7.882583474838611e-14", "4.785061236134425e-14", "6.905587213168474e-14", "1.714184350021242e-13", "5.370148770111882e-13", "1.585953590677036e-12" ] }, "confidenceLevel" : "0.3779644730092272" }, "armaCoefficients" : { "orderAR" : "", "orderMA" : "", "coefficientsAR" : { "estimate" : "", "standardError" : "", "tStatistic" : "", "probability" : "" }, "coefficientsMA" : { "estimate" : "", "standardError" : "", "tStatistic" : "", "probability" : "" }, "orderARSeas" : "", "orderMASeas" : "", "coefficientsARSeas" : { "estimate" : "", "standardError" : "", "tStatistic" : "", "probability" : "" }, "coefficientsMASeas" : { "estimate" : "", "standardError" : "", "tStatistic" : "", "probability" : "" } }, "statCoefficients" : { "intercept" : { "mode" : "AutoEstimate", "estimate" : "21.1", "standardError" : "2.402626767647315", "tStatistic" : "8.782054826044169", "probability" : "4.117620577837044e-09" }, "coefficients" : { "estimate" : "", "standardError" : "", "tStatistic" : "", "probability" : "" } } }, "summaryStatistics" : { "stR2" : "-2.220446049250313e-16", "stAdjR2" : "-2.220446049250313e-16", "stR2_2" : "-2.220446049250313e-16", "stAdjR2_2" : "-2.220446049250313e-16", "stSE" : "12.25104077211402", "stSSR" : "3752.200000000001", "stLogL" : "-101.5284158459659", "stDW" : "0.02452161398646127", "stDWLowerBound" : "5.059215779628777e-27", "stDWUpperBound" : "5.059215779628777e-27", "stSD" : "12.25104077211402", "stAIC" : "7.886801218920452", "stSC" : "7.935189547305892", "stFstat_2" : "-INF", "stProbFstat_2" : "NaN", "stFstat" : "-INF", "stProbFstat" : "NaN", "stME" : "-5.465713352000771e-15", "stMAE" : "10.4", "stMSE" : "144.3153846153846", "stMaxAE" : "20.1", "stSqMSE" : "12.01313383823658", "stVE" : "144.3153846153846", "stSEE" : "12.01313383823657", "stMD" : "21.1", "stHQcriterion" : "7.900735306675025", "stAvgLogL" : "NaN", "stMcFaddenRsquared" : "NaN", "stRestrLogL" : "NaN", "stLRstatistic" : "NaN", "stLRprobability" : "NaN", "stIncludedObservations" : "26", "stJstat" : "NaN", "stProbJstat" : "NaN", "stNumOfIter" : "-1", "stJBStat" : "1.524528747984945", "stProbJBStat" : "0.4666086533649697" }, "name" : "21.1000", "evaluateSeries" : { "its" : { "Item" : { "scenarioKey" : "4294967295", "fact" : { "d" : [ "1", "4", "2", "7", "7.5", "9.1", "10.7", "12.3", "13.9", "15.5", "17.1", "18.7", "20.3", "21.9", "23.5", "25.1", "26.7", "28.3", "29.9", "31.5", "33.1", "34.7", "36.3", "37.9", "39.5", "41.1", "NaN", "NaN", "NaN" ] }, "modelling" : { "d" : [ "21.1", "21.1", "21.1", "21.1", "21.1", "21.1", "21.1", "21.1", "21.1", "21.1", "21.1", "21.1", "21.1", "21.1", "21.1", "21.1", "21.1", "21.1", "21.1", "21.1", "21.1", "21.1", "21.1", "21.1", "21.1", "21.1", "NaN", "NaN", "NaN" ] }, "residuals" : { "d" : [ "-20.1", "-17.1", "-19.1", "-14.1", "-13.6", "-12.00000000000001", "-10.40000000000001", "-8.800000000000004", "-7.200000000000005", "-5.600000000000005", "-4.000000000000004", "-2.400000000000006", "-0.8000000000000043", "0.7999999999999936", "2.399999999999995", "3.999999999999996", "5.599999999999994", "7.199999999999996", "8.799999999999994", "10.4", "12", "13.6", "15.19999999999999", "16.79999999999999", "18.4", "20", "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" ] }, "factors" : { "its" : "" } } }, "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", "kind" : "Simple" }, "warnings" : "", "readOnly" : "0" } } } }, "visualController" : { "userRPath" : "", "isRExist" : "0" }, "suppressEmptyFilter" : { "suppressEmpty" : "0", "suppressEmptyArea" : "SerieBounds" }, "readOnly" : "0", "variableTestUseR" : "0", "calculateIdentOnFact" : "0" }, "useScenarios" : "0", "readOnly" : "0" } } } } }
public static MsCalculationChainEntry GetMsCalcEq(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 model key key = modelKey, problem = new MsProblemPattern() { metamodel = new MsMetaModelPattern() { calculationChain = ListOperation.Get, calcChainPattern = new MsCalculationChainPattern() { entryKeys = new long[] { (long)eqKey }, modelPattern = new MsModelPattern() { transform = new MsFormulaTransformPattern() { kind = true, formulas = new TsFormulaPattern() { method = new TsMethodPattern() { } }, displayId = true, equationsFormula = new TsFormulaPattern() { method = new TsMethodPattern() { } } } } } } } } }, // Set equation calculation parameters execParams = new MsMdExecParams() { k = 0, execMethod = true, execEvaluateSeries = true, execGenerateName = true, execSummaryStatistics = true, execAutoCorrelation = true, execCoefficients = true, execStatCoefficients = true, execARMACoefficients = true, modelKeys = new long[] { (long)eqKey }, scenarioKeys = new long[] { }, execInitDefault = true, options = null } }; // Create a proxy object for operation execution var somClient = new SomPortTypeClient(); GetMsResult getMsResult = somClient.GetMs(getMsOp); MsCalculationChainEntry chainEntry = getMsResult.meta.item.problemMd.metamodel.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; TsArimaMethod arima = formula.method.arima; // Get summary statistics and display into console window StatSummaryStatistics stat = formula.method.summaryStatistics; PrintStat(stat); // Get coefficient values and display into console window StatModelCoefficients coef = arima.statCoefficients; PrintCoef(coef); // Get values of autoregression coefficients, moving average coefficients and display into console window SlARMA armaCoef = arima.armaCoefficients; printARMA(armaCoef); // Get autocorrelation analysis values MsAutoCorrelationResult corr = arima.autoCorrelation; printCorrel(corr); // 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); } // Returns the model that contains equation return chainEntry; } //Procedure of displaying summary statistics values into console window public static void PrintStat(StatSummaryStatistics stat) { Console.WriteLine("-- Summary statistics --"); Console.WriteLine("".PadRight(3) + "- Quality criteria -"); Console.WriteLine("".PadRight(6) + "- determination coefficient: " + stat.stR2); Console.WriteLine("".PadRight(6) + "- adjusted determination coefficient: " + stat.stAdjR2); Console.WriteLine("".PadRight(6) + "- determination coefficient (uncentered): " + stat.stR2_2); Console.WriteLine("".PadRight(6) + "- adjusted determination coefficient (uncentered): " + stat.stAdjR2_2); Console.WriteLine("".PadRight(6) + "- Fisher statistics: " + stat.stFstat); Console.WriteLine("".PadRight(6) + "- Fisher statistics probability: " + stat.stProbFstat); Console.WriteLine("".PadRight(6) + "- log-likelihood function: " + stat.stLogL); Console.WriteLine("".PadRight(6) + "- Akaike information criterion: " + stat.stAIC); Console.WriteLine("".PadRight(6) + "- Schwarz information criterion: " + stat.stSC); Console.WriteLine("".PadRight(6) + "- standard error: " + stat.stSE); Console.WriteLine("".PadRight(6) + "- J-statistics: " + stat.stJstat); Console.WriteLine("".PadRight(6) + "- J-statistics probability: " + stat.stProbJstat); Console.WriteLine("".PadRight(3) + "- diagnostic criteria -"); Console.WriteLine("".PadRight(6) + "- Durbin-Watson statistic: " + stat.stDW); Console.WriteLine("".PadRight(9) + "- lower limit probability: " + stat.stDWLowerBound); Console.WriteLine("".PadRight(9) + "- upper limit probability: " + stat.stDWUpperBound); Console.WriteLine("".PadRight(6) + "- HQ-criterion: " + stat.stHQcriterion); Console.WriteLine("".PadRight(6) + "- mean of log-likelihood function: " + stat.stAvgLogL); Console.WriteLine("".PadRight(6) + "- McFadden determination coefficient: " + stat.stMcFaddenRsquared); Console.WriteLine("".PadRight(6) + "- restricted log-likelihood function: " + stat.stRestrLogL); Console.WriteLine("".PadRight(6) + "- LR statistics: " + stat.stLRstatistic); Console.WriteLine("".PadRight(6) + "- p-value of probability for the LR-statistics: " + stat.stLRprobability); Console.WriteLine("".PadRight(3) + "- residual analysis -"); Console.WriteLine("".PadRight(6) + "- mean error: " + stat.stME); Console.WriteLine("".PadRight(6) + "- mean absolute error: " + stat.stMAE); Console.WriteLine("".PadRight(6) + "- mean squared error: " + stat.stMSE); Console.WriteLine("".PadRight(6) + "- root mean squared error: " + stat.stSqMSE); Console.WriteLine("".PadRight(6) + "- standard deviation of residuals: " + stat.stSEE); Console.WriteLine("".PadRight(6) + "- Jarque-Bera statistics: " + stat.stJBStat); Console.WriteLine("".PadRight(6) + "- sum of squared residuals: " + stat.stSSR); Console.WriteLine("".PadRight(6) + "- maximum absolute error: " + stat.stMaxAE); Console.WriteLine("".PadRight(3) + "- Common -"); Console.WriteLine("".PadRight(6) + "- number of observations: " + stat.stIncludedObservations); Console.WriteLine("".PadRight(6) + "- number of iterations after which the method has converged: " + stat.stNumOfIter); Console.WriteLine("".PadRight(6) + "- average of dependent variable: " + stat.stMD); Console.WriteLine("".PadRight(6) + "- standard deviation of dependent variable: " + stat.stSD); Console.WriteLine("".PadRight(6) + "- residual variable: " + stat.stVE); } // Procedure of displaying coefficient values into console window public static void PrintCoef(StatModelCoefficients coef) { Console.WriteLine("-- Coefficients --"); StatIntercept constVal = coef.intercept; Console.WriteLine("".PadRight(3)+"- Constant -"); Console.WriteLine("".PadRight(6)+" - calculation mode: "+constVal.mode); Console.WriteLine("".PadRight(6)+" - value: "+constVal.estimate); Console.WriteLine("".PadRight(6)+" - standard error: "+constVal.standardError); Console.WriteLine("".PadRight(6)+" - t-statistics: "+constVal.tStatistic); Console.WriteLine("".PadRight(6)+" - probablity: "+constVal.probability); Console.WriteLine("".PadRight(3) + "- Factor -"); PrintStatCoef(6, coef.coefficients); } public static void PrintStatCoef(int pad, StatCoefficients statCoef) { Console.WriteLine("".PadRight(pad) + " - value: " + printArray(statCoef.estimate)); Console.WriteLine("".PadRight(pad) + " - standard error: " + printArray(statCoef.standardError)); Console.WriteLine("".PadRight(pad) + " - t-statistics: " + printArray(statCoef.tStatistic)); Console.WriteLine("".PadRight(pad) + " - probability: " + printArray(statCoef.probability)); } // Procedure of displaying ARMA coefficients into console window public static void printARMA(SlARMA armaCoef) { Console.WriteLine("-- Autoregression and moving average cofficients --"); Console.WriteLine("".PadRight(3) + "- Autoregression coefficients -"); PrintStatCoef(6, armaCoef.coefficientsAR); Console.WriteLine("".PadRight(3) + "- Seasonal autoregression coefficients -"); PrintStatCoef(6, armaCoef.coefficientsARSeas); Console.WriteLine("".PadRight(3) + "- Moving average coefficients -"); PrintStatCoef(6, armaCoef.coefficientsMA); Console.WriteLine("".PadRight(3) + "- Seasonal moving average coefficients -"); PrintStatCoef(6, armaCoef.coefficientsMASeas); } // Procedure of displaying calculated values public static void printSeries(MsEvaluateSeriesResult seriesRes) { Console.WriteLine("-- Calculated values --"); MsEvaluateSeriesResultForScenario res = seriesRes.its.GetValue(0) as MsEvaluateSeriesResultForScenario; Console.WriteLine("".PadRight(3) + "- Scenario data -"); Console.WriteLine("".PadRight(6) + "- key: "+ res.scenarioKey); Console.WriteLine("".PadRight(3) + "- Calculation dates -"); Console.WriteLine("".PadRight(6) + printArray(seriesRes.dates)); Console.WriteLine("".PadRight(3) + "- Source series -"); Console.WriteLine("".PadRight(6) + printArray(res.fact)); if (res.modelling != null) { Console.WriteLine("".PadRight(3) + "- Modeling series -"); Console.WriteLine("".PadRight(6) + printArray(res.modelling)); } if (res.forecast != null) { Console.WriteLine("".PadRight(3) + "- Forecasting series -"); Console.WriteLine("".PadRight(6) + printArray(res.forecast)); } if (res.residuals != null) { Console.WriteLine("".PadRight(3) + "- Residual series -"); Console.WriteLine("".PadRight(6) + printArray(res.residuals)); } if (res.lowerConfidenceLevel != null) { Console.WriteLine("".PadRight(3) + "- Lower confidence limit -"); Console.WriteLine("".PadRight(6) + printArray(res.lowerConfidenceLevel)); } if (res.upperConfidenceLevel != null) { Console.WriteLine("".PadRight(3) + "- Upper confidence limit -"); Console.WriteLine("".PadRight(6) + printArray(res.upperConfidenceLevel)); } if (res.dLowerConfidenceLevel != null) { Console.WriteLine("".PadRight(3) + "- Lower dynamic confidence limit -"); Console.WriteLine("".PadRight(6) + printArray(res.dLowerConfidenceLevel)); } if (res.dUpperConfidenceLevel != null) { Console.WriteLine("".PadRight(3) + "- Upper dynamic confidence limit -"); Console.WriteLine("".PadRight(6) + printArray(res.dUpperConfidenceLevel)); } if (res.factsMatrix != null) { Console.WriteLine("".PadRight(3) + "- Factor matrix -"); Console.WriteLine("".PadRight(6) + printArray(res.factsMatrix)); } } // Procedure of displaying autocorrelation analysis results into console window public static void printCorrel(MsAutoCorrelationResult corr) { Console.WriteLine("-- ACF and PACF --"); Console.WriteLine("".PadRight(3) + " - confidence limits relevance: " + corr.confidenceLevel); Console.WriteLine("".PadRight(3) + " - Ljung-Box q-statistics -"); Console.WriteLine("".PadRight(6) + printArray(corr.qStatistics)); Console.WriteLine("".PadRight(3) + " - q-statistics probability -"); Console.WriteLine("".PadRight(6) + printArray(corr.probability)); Console.WriteLine("".PadRight(3) + " - Autocorrelation function - "); Console.WriteLine("".PadRight(6) + printArray(corr.acf)); Console.WriteLine("".PadRight(3) + " - Partial autocorrelation function - "); Console.WriteLine("".PadRight(6) + printArray(corr.pacf)); } // Procedure of displaying array of values into console window public static string printArray(Array arr) { if (arr != null) { int rank = arr.Rank; string s = ""; if (rank == 1) { for (int i = 0; i <= (arr.Length - 1); i++) { s = s + arr.GetValue(i) + "; "; }; } else { for (int i = 0; i <= (arr.GetLength(0) - 1); i++) { for (int j = 0; j <= (arr.GetLength(1) - 1); j++) { s = s + arr.GetValue(i, j) + "; "; }; s = s + "\n\r"; }; }; return s; } else { return "No values"; }; }
See also: