示例#1
0
        public static double SemTheta_Calc(double thEst, CATItems it, int[] x = null, string model = null, double[] priorPar = null, int[] parInt = null, double D = 1, string method = "BM", string priorDist = "norm")
        {
            double result = 0;

            if (priorPar == null || priorPar.Length < 2)
            {
                priorPar    = new double[2];
                priorPar[0] = 0;
                priorPar[1] = 1;
            }

            if (parInt == null || parInt.Length < 3)
            {
                parInt    = new int[3];
                parInt[0] = -4;
                parInt[1] = 4;
                parInt[2] = 33;
            }

            if (method == ModelNames.EstimaatorMethods.EAP.EnumToString())
            {
                result = EapSEM.EapSEM_Calc(thEst, it, x, model, priorPar, D, priorDist, parInt[0], parInt[1], parInt[2]);
            }
            else
            {
                if (String.IsNullOrEmpty(model))   // Dichotomous Items
                {
                    #region "Function 'dr0' "
                    Func <double> dr0 = () =>
                    {
                        double res = 0;

                        if (method == ModelNames.EstimaatorMethods.BM.EnumToString())
                        {
                            switch (priorDist)
                            {
                            case "norm":
                                res = -1 / (Math.Pow(priorPar[1], 2));
                                break;

                            case "unif":
                                res = 0;
                                break;

                            case "Jeffreys":
                                IiList objIi = Ii.Ii_Calc(thEst, it, model, D);
                                res = (CatRcs.Utils.RowColumn.Sum(objIi.d2Ii) * CatRcs.Utils.RowColumn.Sum(objIi.Ii)
                                       - Math.Pow(CatRcs.Utils.RowColumn.Sum(objIi.dIi), 2)) / (2 * Math.Pow(CatRcs.Utils.RowColumn.Sum(objIi.Ii), 2));
                                break;
                            }
                        }
                        else
                        {
                            if (method == ModelNames.EstimaatorMethods.ML.EnumToString() || method == ModelNames.EstimaatorMethods.WL.EnumToString())
                            {
                                res = 0;
                            }
                        }

                        return(res);
                    };
                    #endregion

                    result = 1 / Math.Sqrt(-dr0() + CatRcs.Utils.RowColumn.Sum(Ii.Ii_Calc(thEst, it, model, D).Ii));
                }
                else   // Polytomous Items
                {
                    double met = 0, pd = 0, optI = 0;
                    ModelNames.EstimaatorMethods md = ModelNames.StringToEnumMethods(method);

                    switch (md)
                    {
                    case ModelNames.EstimaatorMethods.ML:
                        met = 1;
                        break;

                    case ModelNames.EstimaatorMethods.BM:
                        met = 2;
                        break;

                    case ModelNames.EstimaatorMethods.WL:
                        met = 3;
                        break;

                    case ModelNames.EstimaatorMethods.EAP:
                        met = 4;
                        break;
                    }

                    switch (priorDist)
                    {
                    case "norm":
                        pd = 1;
                        break;

                    case "unif":
                        pd = 2;
                        break;

                    case "Jeffreys":
                        pd = 3;
                        break;
                    }

                    if (met == 1 || (met == 2 && pd == 2))
                    {
                        optI = CatRcs.Utils.RowColumn.Sum(Ii.Ii_Calc(thEst, it, model, D).Ii);
                    }

                    if (met == 2 && pd == 1)
                    {
                        optI = CatRcs.Utils.RowColumn.Sum(Ii.Ii_Calc(thEst, it, model, D).Ii) + (1 / Math.Pow(priorPar[1], 2));
                    }

                    if (met == 3 || (met == 2 && pd == 3))
                    {
                        IiList objIi = Ii.Ii_Calc(thEst, it, model, D);

                        if (met == 2)
                        {
                            optI = CatRcs.Utils.RowColumn.Sum(objIi.Ii) + (Math.Pow(CatRcs.Utils.RowColumn.Sum(objIi.dIi), 2) - CatRcs.Utils.RowColumn.Sum(objIi.d2Ii) *
                                                                           CatRcs.Utils.RowColumn.Sum(objIi.Ii)) / (2 * Math.Pow(CatRcs.Utils.RowColumn.Sum(objIi.Ii), 2));
                        }
                        else
                        {
                            optI = CatRcs.Utils.RowColumn.Sum(objIi.Ii);
                        }
                    }

                    result = 1 / Math.Sqrt(optI);
                }
            }

            return(result);
        }
示例#2
0
        // Optimized CAT Items
        public static double EPV_Calc(CATItems itemBank, int item, int[] x, double theta, CATItems it_given, string model, double[] priorPar = null, int[] parInt = null, double D = 1, string priorDist = "norm")
        {
            double res = 0;

            double th = theta;

            if (priorPar == null || priorPar.Length < 2)
            {
                priorPar    = new double[2];
                priorPar[0] = 0;
                priorPar[1] = 1;
            }

            if (parInt == null || parInt.Length < 3)
            {
                parInt    = new int[3];
                parInt[0] = -4;
                parInt[1] = 4;
                parInt[2] = 33;
            }

            if (String.IsNullOrEmpty(model))  // Dichotomous Items
            {
                CATItems itj = itemBank.AddItem_D(it_given, new int[] { item });

                double p1 = Pi.Pi_Calc(th, itemBank, model, D).Pi[item - 1];  // item is matched with the array index

                double p0 = 1 - p1;

                int[] temp_x = new int[x.Length + 1];
                for (int i = 0; i < x.Length; i++)
                {
                    temp_x[i] = x[i];
                }
                temp_x[x.Length - 1] = 0;

                double th0 = EapEST.EapEST_Calc(itj, temp_x, "", priorPar, D, priorDist, parInt[0], parInt[1], parInt[2]);

                double var0 = Math.Pow(EapSEM.EapSEM_Calc(th0, itj, temp_x, "", priorPar, D, priorDist, parInt[0], parInt[1], parInt[2]), 2);

                temp_x = new int[x.Length + 1];
                for (int i = 0; i < x.Length; i++)
                {
                    temp_x[i] = x[i];
                }
                temp_x[x.Length - 1] = 1;

                double th1 = EapEST.EapEST_Calc(itj, temp_x, "", priorPar, D, priorDist, parInt[0], parInt[1], parInt[2]);

                double var1 = Math.Pow(EapSEM.EapSEM_Calc(th1, itj, temp_x, "", priorPar, D, priorDist, parInt[0], parInt[1], parInt[2]), 2);

                res = (p0 * var0) + (p1 * var1);
            }
            else                                                                // Polytomous Items  !!!! Optimization needed !!!!
            {
                double[,] temp_Pi = Pi.Pi_Poly_Calc(th, itemBank, model, D).Pi; // Already returns a NA free list of values.

                // !! Optimize !!
                List <double> probs = new List <double>();

                for (int i = 0; i < temp_Pi.GetLength(1); i++)
                {
                    probs.Add(temp_Pi[0, i]);
                }

                // !!!! Add new method for polytomous items !!!!
                CATItems it_new = it_given;

                double[]   th_new = new double[probs.Count];
                double[]   se_new = new double[probs.Count];
                List <int> temp_x = new List <int>();

                for (int j = 0; j < probs.Count; j++)
                {
                    temp_x = x.ToList();
                    temp_x.Add(j);

                    th_new[j] = EapEST.EapEST_Calc(it_new, temp_x.ToArray(), "", priorPar, D, priorDist, parInt[0], parInt[1], parInt[2]);

                    se_new[j] = Math.Pow(EapSEM.EapSEM_Calc(th_new[j], it_new, temp_x.ToArray(), "", priorPar, D, priorDist, parInt[0], parInt[1], parInt[2]), 2);
                }

                res = CatRcs.Utils.RowColumn.Sum(probs.Select((p, s) => p * se_new[s]).ToArray());
            }

            return(res);
        }