Esempio n. 1
0
        private void ProcessTheta(int[] items, int[] responses)
        {
            CATItems itemBank = null;

            if ((bool)Session["IsDicho"])
            {
                itemBank = new CATItems(items.Length);
                Tuple <CATItems.ColumnNames, int>[] cols = itemBank.GetKeys();

                for (int i = 0; i < cols.Length; i++)
                {
                    string tempKey = cols[i].Item1.ToString() + cols[i].Item2.ToString();
                    itemBank.SetItemParamter(cols[i], cat_items[tempKey].Select(y => (double)y).ToArray());
                }

                // Calculate theta
                CalculateTheta(itemBank, responses);
            }

            if ((bool)Session["IsPoly"])
            {
                ModelNames.Models paramModel = ModelNames.Models.GRM;
                itemBank = new CATItems(items.Length, paramModel.EnumToString(), nrCat: 5);
                Tuple <CATItems.ColumnNames, int>[] cols = itemBank.GetKeys();

                for (int i = 0; i < cols.Length; i++)
                {
                    string tempKey = cols[i].Item1.ToString() + cols[i].Item2.ToString();
                    itemBank.SetItemParamter(cols[i], cat_items[tempKey].Select(y => (double)y).ToArray());
                }

                // Calculate theta
                CalculateTheta(itemBank, responses, model: paramModel.EnumToString());
            }
        }
Esempio n. 2
0
        public void testJi_P(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 = TRUE)").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(PolyItems[0].Length, paramModel.EnumToString(), 5);

            Tuple <CATItems.ColumnNames, int>[] cols = itemBank.GetKeys();

            for (int i = 0; i < cols.Length; i++)
            {
                itemBank.SetItemParamter(cols[i], PolyItems[i].Select(y => (double)y).ToArray());
            }

            #region "Test block for Ability Values (th)"

            JiList objJi        = null;
            int    decimalPoint = 6;

            double[] th_Values = CatRcs.Utils.CommonHelper.Sequence(-6, 6, by: 1);

            Console.WriteLine("******* TEST for Ability value Theta ********");

            for (int k = 0; k < th_Values.Length; k++)
            {
                // Sequence Generation for Theta (Ability) values
                NumericVector th_val = engineObj.CreateNumericVector(new double[] { th_Values[k] });
                engineObj.SetSymbol("th_val", th_val);

                // Calling the "Ji" function from R
                GenericVector result_Ji = engineObj.Evaluate("result_Ji <- Ji(th = th_val, PolyItems, model = modelName, D = 1)").AsList();

                // Getting the function result
                NumericVector Ji  = result_Ji[0].AsNumeric();
                NumericVector dJi = result_Ji[1].AsNumeric();

                Console.WriteLine("Value of Theta: " + th_Values[k]);

                objJi = CatRLib.Ji(th_Values[k], itemBank, paramModel.EnumToString(), 1);

                #region "Ji"

                int z = 0;
                resultFlag = true;

                Console.WriteLine("****** Ji ******");

                for (int i = 0; i < objJi.Ji.Length; i++)
                {
                    z = i + 1;  // item number

                    if (decimal.Round(Convert.ToDecimal(Ji[i]), decimalPoint) != decimal.Round(Convert.ToDecimal(objJi.Ji[i]), decimalPoint))
                    {
                        Console.WriteLine("Test for Item No. # " + z + " is not Passed!");
                        Console.WriteLine("Value from R: " + decimal.Round(Convert.ToDecimal(Ji[i]), decimalPoint));
                        Console.WriteLine("Value from CS: " + decimal.Round(Convert.ToDecimal(objJi.Ji[i]), decimalPoint));
                        resultFlag = false;
                    }
                }

                Assert.IsTrue(resultFlag);
                Console.WriteLine("Values of Ji result is Passed!");

                #endregion

                #region "dJi"

                z          = 0;
                resultFlag = true;

                Console.WriteLine("****** dJi ******");

                for (int i = 0; i < objJi.dJi.Length; i++)
                {
                    z = i + 1;  // item number

                    if (decimal.Round(Convert.ToDecimal(dJi[i]), decimalPoint) != decimal.Round(Convert.ToDecimal(objJi.dJi[i]), decimalPoint))
                    {
                        Console.WriteLine("Test for Item No. # " + z + " is not Passed!");
                        resultFlag = false;
                    }
                }

                Assert.IsTrue(resultFlag);
                Console.WriteLine("Values of dJi result is Passed!");

                #endregion
            }

            #endregion

            #region "Test block for Metric values"

            objJi = null;

            double[] D_Values = CatRcs.Utils.CommonHelper.Sequence(0.5, 1, by: 0.1);

            Console.WriteLine("******* TEST for Metric Constant ********");

            for (int k = 0; k < D_Values.Length; k++)
            {
                // Sequence Generation for Theta (Ability) values
                NumericVector D_val = engineObj.CreateNumericVector(new double[] { D_Values[k] });
                engineObj.SetSymbol("D_val", D_val);

                // Calling the "Ji" function from R
                GenericVector result_Ji = engineObj.Evaluate("result_Ji <- Ji(th = 0, PolyItems, model = modelName, D = D_val)").AsList();

                // Getting the function result
                NumericVector Ji  = result_Ji[0].AsNumeric();
                NumericVector dJi = result_Ji[1].AsNumeric();

                Console.WriteLine("Value of Metric Constant: " + D_Values[k]);

                objJi = CatRLib.Ji(0, itemBank, paramModel.EnumToString(), D_Values[k]);

                #region "Ji"

                int z = 0;
                resultFlag = true;

                Console.WriteLine("****** Ji ******");

                for (int i = 0; i < objJi.Ji.Length; i++)
                {
                    z = i + 1;  // item number

                    if (decimal.Round(Convert.ToDecimal(Ji[i]), decimalPoint) != decimal.Round(Convert.ToDecimal(objJi.Ji[i]), decimalPoint))
                    {
                        /*Console.WriteLine("Test for Item No. # " + z + " is not Passed!");
                         * Console.WriteLine("Value from R: " + decimal.Round(Convert.ToDecimal(Ji[i]), decimalPoint));
                         * Console.WriteLine("Value from CS: " + decimal.Round(Convert.ToDecimal(objJi.Ji[i]), decimalPoint));*/
                        resultFlag = false;
                    }
                }

                //Assert.IsTrue(resultFlag);
                Console.WriteLine("Values of Ji result is Passed!");

                #endregion

                #region "dJi"

                z          = 0;
                resultFlag = true;

                Console.WriteLine("****** dJi ******");

                for (int i = 0; i < objJi.dJi.Length; i++)
                {
                    z = i + 1;  // item number

                    if (decimal.Round(Convert.ToDecimal(dJi[i]), decimalPoint) != decimal.Round(Convert.ToDecimal(objJi.dJi[i]), decimalPoint))
                    {
                        Console.WriteLine("Test for Item No. # " + z + " is not Passed!");
                        resultFlag = false;
                    }
                }

                Assert.IsTrue(resultFlag);
                Console.WriteLine("Values of dJi result is Passed!");

                #endregion
            }

            #endregion
        }