예제 #1
0
        private void DetermineIterationDetails(bool longList, ref int iterationsOfBinomCdf, ref int iterationStartingPoint)
        {
            if (!longList)
            {
                double mean = BinomialStochasticVariables.My(xVar);
                double dev  = BinomialStochasticVariables.Deviation(xVar);

                iterationStartingPoint = (int)(mean - 3 * dev);
                if (iterationStartingPoint <= 0)
                {
                    iterationStartingPoint = 0;
                }
                iterationsOfBinomCdf = (int)(6 * dev + mean);
                if (iterationsOfBinomCdf > xVar.number)
                {
                    iterationsOfBinomCdf = (int)xVar.number;
                }
            }
        }
예제 #2
0
        void WorkWithPropertiesOfXVar()
        {
            Console.WriteLine("||\n||| Working out useful properties of supplied XVar.");
            CheckValuesForBadness();

            double tempMy = BinomialStochasticVariables.My(xVar);

            Console.WriteLine("||\n|| > Expected value E(X) or my: X~b( n , p ) E(X) = n * p");
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("||| Expected value E(X) or my:\n||| > X~b( {0} , {1} ) E(X) = {0} * {1} = {2}",
                              xVar.number, xVar.probability, tempMy);
            Console.ResetColor();

            double tempVariance = BinomialStochasticVariables.Variance(xVar);

            Console.Write("||\n|| > Binomial Variance Var(X): X~b( n , p )  Var(X) = n * p * (1 - p)");
            Console.ForegroundColor = ConsoleColor.DarkBlue;
            Console.Write("\t\tI made this up, but the values it produces make sense; \n");
            Console.ForegroundColor = ConsoleColor.Green;
            Console.Write("|| Variance Var(X):");
            Console.ForegroundColor = ConsoleColor.DarkBlue;
            Console.Write("\t\t\t\t\t\t\t\tand the sense of the formula is parallel to variance proper, Var(X).\n");
            Console.ForegroundColor = ConsoleColor.Green;
            Console.Write("||| > X~b( {0} , {1} )  Var(X) = {0} * {1} * (1 - {1}) = {2}\n",
                          xVar.number, xVar.probability, Math.Round(tempVariance, 7));
            Console.ResetColor();

            double tempDeviation = BinomialStochasticVariables.Deviation(xVar);

            Console.WriteLine("||\n|| > Mean Deviance / sigma(X): X~b( n , p )  sigma(X) = squareroot of Var(x) \n" +
                              "|| So  sigma(X) = squareroot of (n * p * (1 - p))");
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("|| Deviation sigma(X):" +
                              "\n||| > X~b( {0} , {1} )  Var(X) = sqr({2}) = squareroot of ( {0} * {1} * (1 - {1} )) = {3}",
                              xVar.number, xVar.probability, Math.Round(tempVariance, 3), Math.Round(tempDeviation, 7));
            Console.ResetColor();
            //Console.WriteLine("||");

            double negStandardDeviation = Math.Round(tempMy - tempDeviation, 2);
            double neg2ndDeviation      = Math.Round(tempMy - tempDeviation * 2, 2);
            double neg3rdDeviation      = Math.Round(tempMy - tempDeviation * 3, 2);
            double posStandardDeviation = Math.Round(tempMy + tempDeviation, 2);
            double pos2ndDeviation      = Math.Round(tempMy + tempDeviation * 2, 2);
            double pos3rdDeviation      = Math.Round(tempMy + tempDeviation * 3, 2);

            Console.WriteLine("" +
                              "||\n|| > Normal Distribution for X ~b( {0} , {1} ):\n" +
                              "|| Case: ", xVar.number, xVar.probability);
            Console.ForegroundColor = ConsoleColor.DarkGreen;
            Console.WriteLine(
                "|| \tLow --- \tLow --  \tLow - \t\tMean \t\tHigh + \t\tHigh ++ \tHigh +++ ");
            Console.ForegroundColor = ConsoleColor.Green;
            if (neg3rdDeviation <= 0)
            {
                Console.ForegroundColor = ConsoleColor.DarkMagenta;
            }                                                                                    // to represent the impossibility of a negative deviation, go dark magenta
            Console.Write("|||\t{0}", neg3rdDeviation);
            if (neg2ndDeviation <= 0)
            {
                Console.ForegroundColor = ConsoleColor.DarkMagenta;
            }                                                                                    // to represent the impossibility of a negative deviation, go dark magenta
            Console.Write("\t\t{0}", neg2ndDeviation);
            Console.ForegroundColor = ConsoleColor.Green;
            Console.Write("\t\t{0}\t\t{1}\t\t{2}\t\t{3}\t\t{4}\n",
                          negStandardDeviation, tempMy, posStandardDeviation, pos2ndDeviation, pos3rdDeviation);
            Console.ResetColor();

            double confidenceCoefficient       = Math.Sqrt(xVar.probability * (1 - xVar.probability)) / Math.Sqrt(xVar.number);
            double confidenceIntervalLowPoint  = xVar.probability - 2 * confidenceCoefficient;
            double confidenceIntervalHighPoint = xVar.probability + 2 * confidenceCoefficient;

            //double confidenceIntLow = 0;

            Console.WriteLine("" +
                              "||\n||| > 95% Confidence Interval 'using' XVar ~b( n = {0} , p = {1} );\n" +
                              "|| where {0} is 'interpreted' as sample size \t\t[n] = {0} \t[ Number of cases included in experiment. ]\n" +
                              "|| and {1} is 'treated' as estimated likelyhood\t[p] = {1}\n" +
                              "|| [ [p] of your XVar is treated as if:\t\t\t[p] = rate of queried quality found in sample / sample size ]", Math.Round(xVar.number, 2), Math.Round(xVar.probability, 2));
            //Console.ForegroundColor = ConsoleColor.Green;
            Console.Write("" +
                          "|| Assuming that the sample size {0} is representative of the total population in question,\n" +
                          "|| it might be concluded with confidence that the actual percentage in that total population is\n||| " +
                          "\t\t\t\t\tbetween\t", xVar.number);
            Console.ForegroundColor = ConsoleColor.DarkGreen;
            Console.Write("\t\t{0}%\t", Math.Round(confidenceIntervalLowPoint * 100, 2));
            Console.ResetColor();

            Console.Write(" and\t");

            Console.ForegroundColor = ConsoleColor.DarkGreen;
            Console.Write("{0}%.\n", Math.Round(confidenceIntervalHighPoint * 100, 2));
            Console.ResetColor();

            Console.Write("||\n");
            Console.ForegroundColor = ConsoleColor.DarkBlue;
            Console.Write("|| End of list. Press enter to continue.\n");
            Console.ReadLine();
            Console.ResetColor();

            MethodExit();
        }