Inheritance: Accord.Statistics.Testing.ChiSquareTest
        public void MultinomialTestConstructorTest()
        {
            // Example from http://www.stat.berkeley.edu/~stark/SticiGui/Text/chiSquare.htm

            int[] sample = { 45, 41, 9 };
            double[] hypothesizedProportion = { 18 / 38.0, 18 / 38.0, 2 / 38.0 };

            MultinomialTest target = new MultinomialTest(sample, hypothesizedProportion);

            Assert.AreEqual(18 / 38.0, target.HypothesizedProportions[0]);
            Assert.AreEqual(18 / 38.0, target.HypothesizedProportions[1]);
            Assert.AreEqual(2 / 38.0, target.HypothesizedProportions[2]);

            Assert.AreEqual(45 / 95.0, target.ObservedProportions[0]);
            Assert.AreEqual(41 / 95.0, target.ObservedProportions[1]);
            Assert.AreEqual(9 / 95.0, target.ObservedProportions[2]);


            Assert.AreEqual(3.55555556, target.Statistic, 1e-5);
        }
        public void MultinomialTestConstructorTest2()
        {
            // This example is based on the example available on About.com Statistics,
            // An Example of Chi-Square Test for a Multinomial Experiment By Courtney Taylor
            // http://statistics.about.com/od/Inferential-Statistics/a/An-Example-Of-Chi-Square-Test-For-A-Multinomial-Experiment.htm

            // In this example, we would like to test if a die is fair. For this, we
            // will be rolling the die 600 times, annotating the result every time 
            // the die falls. In the end, we got a one 106 times, a two 90 times, a 
            // three 98 times, a four 102 times, a five 100 times and a six 104 times:

            int[] sample = { 106, 90, 98, 102, 100, 104 };

            // If the die was fair, we should note that we would be expecting the
            // probabilities to be all equal to 1 / 6:

            double[] hypothesizedProportion = 
            { 
                //   1        2           3          4          5         6
                1 / 6.0,   1 / 6.0,   1 / 6.0,   1 / 6.0,   1 / 6.0,   1 / 6.0, 
            };

            // Now, we create our test using the samples and the expected proportion
            MultinomialTest test = new MultinomialTest(sample, hypothesizedProportion);

            double chiSquare = test.Statistic; // 1.6
            bool significant = test.Significant; // false

            // Since the test didn't come up significant, it means that we
            // don't have enough evidence to to reject the null hypothesis 
            // that the die is fair.

            Assert.AreEqual(1.6000000000000003, chiSquare);
            Assert.IsFalse(significant);
        }
        private void updateFormValues()
        {
            srPop.Points.Clear();
            srSamp.Points.Clear();
            srPop2.Points.Clear();
            srSamp2.Points.Clear();
            System.Windows.Forms.ComboBox cmbPrimary = (System.Windows.Forms.ComboBox)hs.Controls["cmbPrimary"];
            string cmbTxt = cmbPrimary.Text;
            System.Windows.Forms.DataVisualization.Charting.Chart ch = hs.chrHistogram;
            string k = ch.Titles[0].Text.Replace("Distribution for ", "");
            if (cmbTxt == "Bins")
            {
                ch.ChartAreas[0].AxisX.Title = "Bins";
                double[] binProp1 = ClusterProportions[k];
                double[] binProp2 = ClusterSampleProportions[k];
                int[] clusCntSamp = clusSampleCountDic[k];
                Accord.Statistics.Testing.MultinomialTest mt = new MultinomialTest(clusCntSamp, binProp1);
                ch.ChartAreas[1].AxisX.Title = "Chi-Square = " + mt.Statistic.ToString() + "\np-value = " + mt.PValue.ToString();
                double[] xAxes = (from int i in System.Linq.Enumerable.Range(0, binProp1.Length) select System.Convert.ToDouble(i)).ToArray();
                double ypSum = 0;
                double ysSum = 0;
                for (int i = 0; i < binProp1.Length; i++)
                {
                    double bp1 = binProp1[i];
                    double bp2 = binProp2[i];
                    ypSum += bp1;
                    ysSum += bp2;
                    srPop.Points.AddXY(xAxes[i], bp1);
                    srSamp.Points.AddXY(xAxes[i], bp2);
                    srPop2.Points.AddXY(xAxes[i], ypSum);
                    srSamp2.Points.AddXY(xAxes[i], ysSum);
                }
            }
            else
            {
                int cmbInd = System.Convert.ToInt32(cmbTxt) - 1;
                ch.ChartAreas[0].AxisX.Title = "Principle Component " + cmbTxt;
                ch.ChartAreas[1].AxisX.Title = "proportion of variance = " + pca.ProportionOfTotalVariance[cmbInd].ToString() + "\np-value = " + pDic[k][cmbInd].ToString();
                double[][] minMax1 = minMaxDic1[k];
                double[][] minMax2 = minMaxDic2[k];
                double min = minMax1[0][cmbInd];
                if (minMax2[0][cmbInd] < min) min = minMax2[0][cmbInd];
                double max = minMax1[1][cmbInd];
                if (minMax2[1][cmbInd] > max) max = minMax2[1][cmbInd];
                double span = (max - min) / numberOfBins;
                double[] binProp1 = binPropDic1[k][cmbInd];
                double[] binProp2 = binPropDic2[k][cmbInd];
                double[] xAxes = new double[binProp1.Length];
                double halfMin = min / 2;
                for (int i = 0; i < xAxes.Length; i++)
                {
                    xAxes[i] = min + halfMin + (span * i);
                }

                double ypSum = 0;
                double ysSum = 0;
                for (int i = 0; i < binProp1.Length; i++)
                {
                    double bp1 = binProp1[i];
                    double bp2 = binProp2[i];
                    ypSum += bp1;
                    ysSum += bp2;
                    srPop.Points.AddXY(xAxes[i], bp1);
                    srSamp.Points.AddXY(xAxes[i], bp2);
                    srPop2.Points.AddXY(xAxes[i], ypSum);
                    srSamp2.Points.AddXY(xAxes[i], ysSum);
                }
            }
            ch.Show();
        }