Exemple #1
0
        public static OIiList OIi_Calc(double th, CATItems it, int[] x, string model, double D)
        {
            OIiList objOIi = null;

            double[] OIi = null;
            try
            {
                if (String.IsNullOrEmpty(model))
                {
                    #region "Calculation for Dichotmous Items"

                    PiList pr = Pi.Pi_Calc(th, it, model, D);

                    if (pr == null)
                    {
                        objOIi           = new OIiList();
                        objOIi.Exception = "No Pi values found!";
                        return(objOIi);
                    }

                    double[] P = pr.Pi; double[] dP = pr.dPi; double[] d2P = pr.d2Pi;

                    OIi = new double[P.Length];

                    objOIi = new OIiList(P.Length);

                    double[] Q = new double[P.Length];

                    for (int i = 0; i < P.Length; i++)
                    {
                        Q[i] = 1 - P[i];
                    }

                    for (int j = 0; j < OIi.Length; j++)
                    {
                        OIi[j] = (P[j] * Q[j] * Math.Pow(dP[j], 2) - (x[0] - P[j]) * (P[j] * Q[j] * d2P[j] + Math.Pow(dP[j], 2) * (P[j] - Q[j]))) / (Math.Pow(P[j], 2) * Math.Pow(Q[j], 2));
                    }

                    #endregion
                }
                else
                {
                    #region "Calculation for Polytomous Items"

                    PiListPoly pr = Pi.Pi_Poly_Calc(th, it, model, D);

                    if (pr == null)
                    {
                        objOIi           = new OIiList();
                        objOIi.Exception = "No Pi values found!";
                        return(objOIi);
                    }

                    double[,] P = pr.Pi; double[,] dP = pr.dPi; double[,] d2P = pr.d2Pi;

                    OIi = new double[it.NumOfItems];

                    objOIi = new OIiList(it.NumOfItems);

                    for (int i = 0; i < x.Length; i++)
                    {
                        double tempdP  = dP[i, x[i]];
                        double tempP   = P[i, x[i]];
                        double tempd2P = d2P[i, x[i]];

                        OIi[i] = (Math.Pow(dP[i, x[i]], 2) / Math.Pow(P[i, x[i]], 2)) - (d2P[i, x[i]] / P[i, x[i]]);
                    }

                    #endregion
                }

                objOIi.Add(OIi);
            }
            catch (Exception ex)
            {
                if (ex != null)
                {
                    if (objOIi == null)
                    {
                        objOIi = new OIiList();
                    }
                    objOIi.Exception = "No Pi value found!";
                }
                return(objOIi);
            }

            return(objOIi);
        }
Exemple #2
0
        public void testOIi_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(10, 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)"

            OIiList objOIi       = 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);

                //Creation of a response pattern
                engineObj.Evaluate("set.seed(1)");
                NumericVector x_val = engineObj.Evaluate("x_val <- genPattern(th = th_val, PolyItems, model = modelName, D = 1)").AsNumeric();
                engineObj.SetSymbol("x_val", x_val);

                // Calling the Ii function from R
                GenericVector result_OIi = engineObj.Evaluate("result_OIi <- OIi(th = th_val, PolyItems, x = x_val, model = modelName, D = 1)").AsList();

                // Getting the function result
                NumericVector OIi = result_OIi.AsNumeric();

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

                objOIi = CatRLib.OIi(th_Values[k], itemBank, x_val.Select(y => (int)y).ToArray(), paramModel.EnumToString(), 1);

                #region "OIi"

                int z = 0;
                resultFlag = true;

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

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

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

                Assert.IsTrue(resultFlag);
                Console.WriteLine("Values of OIi result are Matched!");

                #endregion
            }

            #endregion

            #region "Test block for Metric values"

            objOIi = 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 Metric values
                NumericVector D_val = engineObj.CreateNumericVector(new double[] { D_Values[k] });
                engineObj.SetSymbol("D_val", D_val);

                //Creation of a response pattern
                engineObj.Evaluate("set.seed(1)");
                NumericVector x_val = engineObj.Evaluate("x_val <- genPattern(th = 0, PolyItems, model = modelName, D = D_val)").AsNumeric();
                engineObj.SetSymbol("x_val", x_val);

                // Calling the Ii function from R
                GenericVector result_OIi = engineObj.Evaluate("result_OIi <- OIi(th = 0, PolyItems, x = x_val, model = modelName, D = D_val)").AsList();

                // Getting the function result
                NumericVector OIi = result_OIi.AsNumeric();

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

                objOIi = CatRLib.OIi(0, itemBank, x_val.Select(y => (int)y).ToArray(), paramModel.EnumToString(), D_Values[k]);

                #region "OIi"

                int z = 0;
                resultFlag = true;

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

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

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

                Assert.IsTrue(resultFlag);
                Console.WriteLine("Values of OIi result are Matched!");

                #endregion
            }

            #endregion
        }
Exemple #3
0
        public void testOIi_D()
        {
            REngine.SetEnvironmentVariables();

            REngine engineObj = REngine.GetInstance();

            // Loading a library from R
            engineObj.Evaluate("library(catR)");

            // Dichotomous Items
            DataFrame DichoItems = engineObj.Evaluate("DichoItems <- genDichoMatrix(items = 10)").AsDataFrame();

            engineObj.SetSymbol("DichoItems", DichoItems);

            // Adapting with the existing "CAT-Items" type (Wrapper)
            CATItems itemBank = new CATItems(DichoItems[0].Length, false);

            // New Dictionary
            itemBank.SetItemParamter(CATItems.ColumnNames.a, DichoItems[0].Select(y => (double)y).ToArray());
            itemBank.SetItemParamter(CATItems.ColumnNames.b, DichoItems[1].Select(y => (double)y).ToArray());
            itemBank.SetItemParamter(CATItems.ColumnNames.c, DichoItems[2].Select(y => (double)y).ToArray());
            itemBank.SetItemParamter(CATItems.ColumnNames.d, DichoItems[3].Select(y => (double)y).ToArray());

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

            OIiList objOIi       = 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 Ii function from R
                GenericVector result_OIi = engineObj.Evaluate("result_OIi <- OIi(th = th_val, DichoItems, x = 1, D = 1)").AsList();

                // Getting the function result
                NumericVector OIi = result_OIi.AsNumeric();

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

                objOIi = CatRLib.OIi(th_Values[k], itemBank, new int[] { 1 }, "", 1);

                #region "OIi"

                int z = 0;
                resultFlag = true;

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

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

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

                Assert.IsTrue(resultFlag);
                Console.WriteLine("Values of OIi result are Matched!");

                #endregion
            }

            #endregion

            #region "Test block for Metric values"

            objOIi = 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 Metric values
                NumericVector D_val = engineObj.CreateNumericVector(new double[] { D_Values[k] });
                engineObj.SetSymbol("D_val", D_val);

                // Calling the Ii function from R
                GenericVector result_OIi = engineObj.Evaluate("result_OIi <- OIi(th = 0, DichoItems, x = 1, D = D_val)").AsList();

                // Getting the function result
                NumericVector OIi = result_OIi.AsNumeric();

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

                objOIi = CatRLib.OIi(0, itemBank, new int[] { 1 }, "", D_Values[k]);

                #region "OIi"

                int z = 0;
                resultFlag = true;

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

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

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

                Assert.IsTrue(resultFlag);
                Console.WriteLine("Values of OIi result are Matched!");

                #endregion
            }

            #endregion
        }
Exemple #4
0
        // Function OIi
        public static OIiList OIi(double th, CATItems it, int[] x, string model, double D)
        {
            OIiList objOIi = CatRcs.OIi.OIi_Calc(th, it, x, model, D);

            return(objOIi);
        }