예제 #1
0
        private void ListOfBinomCdf()
        {
            Console.WriteLine("|||\n" +
                              "|| List of cumulative likelyhoods of AT MOST rate [r] success': X~b( n , p ) P( X <= r ) [r = 0,..,n]\n" +
                              "|| given the probability [p] of a success among [n] elements: X~b(n,p) P(X=r)\n||");

            CheckValuesForBadness();

            bool longList = DecideListLength();

            for (int i = 0; i <= xVar.number; i++)
            {
                double binomCdf = BinomialStochasticVariables.binomCdf(xVar, i);
                if (binomCdf > 0.0025 && binomCdf < 0.98 | longList)
                {
                    //Console.ForegroundColor = ConsoleColor.Green;
                    //if ((binomCdf <= 0.05)) { Console.ForegroundColor = ConsoleColor.DarkRed; }
                    //if ((binomCdf >= 0.95)) { Console.ForegroundColor = ConsoleColor.DarkYellow; }
                    ColorCodeIntervals(binomCdf);

                    Console.WriteLine("||| Chance of {0} or less success' = {1}%:\t X~b( {2} , {3} ) P(X <= {0}) = {4} \t\t {5}",
                                      i, 100 * Math.Round(binomCdf, 4), xVar.number, xVar.probability,
                                      Math.Round(binomCdf, 5), Access.Dash(binomCdf /*, 4*/));

                    if (binomCdf > 0.9999)
                    {
                        break;
                    }
                }
            }
            Console.ResetColor();

            Console.ReadLine();
        }
예제 #2
0
        private void ListOfBinomICdf()
        {
            Console.WriteLine("|||\n||  X~b( n , p ) P( X >= r ) [r = 0,..,n]\n|| List of cumulative likelyhoods of AT LEAST rate [r] success':\n" +
                              "|| given the probability of a success [p] among [n] elements: X~b(n,p) P(X=r)\n||");

            CheckValuesForBadness();

            bool longList = DecideListLength();

            int iterationsOfBinomCdf = (int)xVar.number; // number of times the binomCdf() will run; changed if only a non-longList is demanded by user

            int iterationStartingPoint = 0;              // will be 0 if traversing all values; set to xVars My value if going for short list

            //Here is implemented a way of cutting off the list that uses the actual numbers of the
            // xVar - doesn't make much difference... which is cool.
            DetermineIterationDetails(longList, ref iterationsOfBinomCdf, ref iterationStartingPoint);
            for (int i = iterationStartingPoint; i <= iterationsOfBinomCdf; i++)
            {
                double binomICdf = BinomialStochasticVariables.binomICdf(xVar, i);
                //if (binomICdf > 0.0025 && binomICdf < 0.951 | longList)
                //{

                ColorCodeIntervals(binomICdf);
                Console.WriteLine("||| Chance of {0} or more success' = {1}%:\t X~b( {2} , {3} ) P(X >= {0}) = {4} \t\t {5}",
                                  i, 100 * Math.Round(binomICdf, 4), xVar.number, xVar.probability,
                                  Math.Round(binomICdf, 7), Access.Dash(binomICdf /*, 3*/));
                //}
            }
            Console.ResetColor();
            Console.ReadLine();
        }
예제 #3
0
        private void ListChanceOfAllSingleRatesSuccess()
        {
            Console.WriteLine("|||\n|| List of the chances of all specific rates [r] of success\n" +
                              "|| given the probability of a success [p] among [n] elements: X~b(n,p) P(X=r)\n||");

            CheckValuesForBadness();

            bool longList = DecideListLength();

            for (int i = 0; i <= xVar.number; i++)
            {
                double binomPdf = BinomialStochasticVariables.binomPdf(xVar, i);

                if (binomPdf > 0.0002 | longList)
                {
                    ColorCodeIntervals(binomPdf);

                    Console.WriteLine("||| Chance of {0} success = {1}% :\tX~b( {2} , {3} ) P(X = {0}) = {4}\t\t {5}",
                                      i, 100 * Math.Round(binomPdf, 4), xVar.number, xVar.probability,
                                      Math.Round(binomPdf, 5), Access.Dash(binomPdf));
                }
            }
            Console.ResetColor();
            Console.ReadLine();
        }
예제 #4
0
        void CalculateChanceOfNoLessThanRateSuccess()
        {
            Console.WriteLine("|||Calculate the chance of EQUAL TO OR MORE than rate [r] of success: X~b( n , p ) P( X >= r )\n" +
                              "|| given the probability of a success [p] among [n] elements: X~b(n,p) P(X=r)\n||");

            CheckValuesForBadness();
            Rate = FetchRate();

            Console.WriteLine("||\n||| Chance of {0} or more success' = {1}% : X~b( {2} , {3} ) P(X >= {0}) = {4}\n||",
                              Rate, 100 * Math.Round(BinomialStochasticVariables.binomICdf(xVar, Rate), 5), xVar.number, xVar.probability,
                              Math.Round(BinomialStochasticVariables.binomICdf(xVar, Rate), 7));
            Console.WriteLine("|| Enter to continue.");
            Console.ReadLine();
        }
예제 #5
0
        void CalculateChanceOfAtLeastRateSuccess()
        {
            Console.WriteLine("|||Calculate the probability of EQUAL OR LESS than rate [r] of success: X~b( n , p ) P( X <= r )\n" +
                              "|| given the probability [p] of a success among [n] elements: X~b(n,p) P(X=r)\n||");

            CheckValuesForBadness();
            Rate = FetchRate();

            Console.WriteLine("||\n||| Chance of no more than {0} success' = {1}% : X~b( {2} , {3} ) P(X <= {0}) = {4}\n||",
                              Rate, 100 * Math.Round(BinomialStochasticVariables.binomCdf(xVar, Rate), 5), xVar.number, xVar.probability,
                              Math.Round(BinomialStochasticVariables.binomCdf(xVar, Rate), 5));
            Console.WriteLine("|| Enter to continue.");
            Console.ReadLine();
        }
예제 #6
0
        private void ChanceOfSingleRateSuccess()
        {
            Console.WriteLine("|||Calculate the chance of a specific rate [r] of success\n" +
                              "|| given the probability of a success [p] among [n] elements:\t X~b(n,p) P(X=r)\n||");

            CheckValuesForBadness();
            Rate = FetchRate();

            Console.WriteLine("||\n||| The likelyhood of {0} success' = {1}% : X~b( {2} , {3} ) P(X = {0}) = {4}\n||",
                              Rate, 100 * Math.Round(BinomialStochasticVariables.binomPdf(xVar, Rate), 3), xVar.number, xVar.probability,
                              Math.Round(BinomialStochasticVariables.binomPdf(xVar, Rate), 5));
            Console.WriteLine("|| Enter to continue.");
            Console.ReadLine();
        }
예제 #7
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;
                }
            }
        }
예제 #8
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();
        }