public void testPi_P_New(ModelNames.Models paramModel) { REngine.SetEnvironmentVariables(); REngine engineObj = REngine.GetInstance(); // Loading a library from R engineObj.Evaluate("library(catR)"); // Polytomous Items CharacterVector modelName = engineObj.CreateCharacterVector(new string[] { paramModel.EnumToString() }); engineObj.SetSymbol("modelName", modelName); DataFrame PolyItems = engineObj.Evaluate("PolyItems <- genPolyMatrix(100, 5, model = modelName, same.nrCat = FALSE)").AsDataFrame(); engineObj.SetSymbol("PolyItems", PolyItems); // Adapting with the existing "CAT-Items" type (Wrapper) Console.WriteLine("*******************************************"); Console.WriteLine("Polytomous Items, Model : " + paramModel.EnumToString()); Console.WriteLine("*******************************************"); CATItems itemBank = new CATItems(NumOfItems: PolyItems[0].Length, model: paramModel.EnumToString(), nrCat: 5); for (int i = 0; i < itemBank.colSize; i++) { itemBank.all_items_poly[i] = PolyItems[i].Select(y => (double)y).ToArray(); } PiListPoly objPI = null; int decimalPoint = 4; double[] th_Values = CatRcs.Utils.CommonHelper.Sequence(-4, 4, by: 1); NumericVector th_val = engineObj.CreateNumericVector(new double[] { th_Values[0] }); engineObj.SetSymbol("th_val", th_val); // Calling the "Pi" from R GenericVector result_Pi = engineObj.Evaluate("result_Pi <- Pi(th = th_val, PolyItems, model = modelName, D = 1)").AsList(); // Getting the "Pi" function result NumericVector Pi = result_Pi[0].AsNumeric(); NumericVector dPi = result_Pi[1].AsNumeric(); NumericVector d2Pi = result_Pi[2].AsNumeric(); NumericVector d3Pi = result_Pi[3].AsNumeric(); Console.WriteLine("Value of Theta: " + th_Values[0]); // Calling "Pi" function objPI = CatRLib.Pi_P(th_Values[0], itemBank, paramModel.EnumToString(), 1); #region "Pi" int z = 0, pi_index = 0; resultFlag = true; Console.WriteLine("****** Pi ******"); int len = objPI.Pi.GetLength(0); int len2 = objPI.Pi.GetLength(1); for (int i = 0; i < objPI.Pi.GetLength(1); i++) // column { z = i + 1; // item number for (int j = 0; j < objPI.Pi.GetLength(0); j++) // row { double tempPiVal = !CatRcs.Utils.CheckNaValues.IsNaNvalue(Pi[pi_index]) ? Pi[pi_index] : 0; if (decimal.Round(Convert.ToDecimal(tempPiVal), decimalPoint) != decimal.Round(Convert.ToDecimal(objPI.Pi[j, i]), decimalPoint)) { Console.WriteLine("Test for Item No. # " + z + " is not Passed!"); resultFlag = false; } pi_index++; } } Assert.IsTrue(resultFlag); Console.WriteLine("Values of Pi are Matched!"); #endregion #region "dPi" z = 0; pi_index = 0; resultFlag = true; Console.WriteLine("****** dPi ******"); for (int i = 0; i < objPI.dPi.GetLength(1); i++) // column { z = i + 1; // item number for (int j = 0; j < objPI.dPi.GetLength(0); j++) // row { double tempPiVal = !CatRcs.Utils.CheckNaValues.IsNaNvalue(dPi[pi_index]) ? dPi[pi_index] : 0; if (decimal.Round(Convert.ToDecimal(tempPiVal), decimalPoint) != decimal.Round(Convert.ToDecimal(objPI.dPi[j, i]), decimalPoint)) { Console.WriteLine("Test for Item No. # " + z + " is not Passed!"); resultFlag = false; } pi_index++; } } Assert.IsTrue(resultFlag); Console.WriteLine("Values of dPi are Matched!"); #endregion #region "d2Pi" z = 0; pi_index = 0; resultFlag = true; Console.WriteLine("****** d2Pi ******"); for (int i = 0; i < objPI.d2Pi.GetLength(1); i++) // column { z = i + 1; // item number for (int j = 0; j < objPI.d2Pi.GetLength(0); j++) // row { double tempPiVal = !CatRcs.Utils.CheckNaValues.IsNaNvalue(d2Pi[pi_index]) ? d2Pi[pi_index] : 0; if (decimal.Round(Convert.ToDecimal(tempPiVal), decimalPoint) != decimal.Round(Convert.ToDecimal(objPI.d2Pi[j, i]), decimalPoint)) { Console.WriteLine("Test for Item No. # " + z + " is not Passed!"); resultFlag = false; } pi_index++; } } Assert.IsTrue(resultFlag); Console.WriteLine("Values of d2Pi are Matched!"); #endregion #region "d3Pi" z = 0; pi_index = 0; resultFlag = true; Console.WriteLine("****** d3Pi ******"); for (int i = 0; i < objPI.d3Pi.GetLength(1); i++) // column { z = i + 1; // item number for (int j = 0; j < objPI.d3Pi.GetLength(0); j++) // row { double tempPiVal = !CatRcs.Utils.CheckNaValues.IsNaNvalue(d3Pi[pi_index]) ? d3Pi[pi_index] : 0; if (decimal.Round(Convert.ToDecimal(tempPiVal), decimalPoint) != decimal.Round(Convert.ToDecimal(objPI.d3Pi[j, i]), decimalPoint)) { Console.WriteLine("Test for Item No. # " + z + " is not Passed!"); resultFlag = false; } pi_index++; } } Assert.IsTrue(resultFlag); Console.WriteLine("Values of d3Pi are Matched!"); #endregion }