Accord.Statistics.Testing.OneWayAnova.initialize C# (CSharp) Method

initialize() private method

private initialize ( double samples ) : void
samples double
return void
        private void initialize(double[][] samples)
        {
            DFb = groupCount - 1;
            DFw = totalSize - groupCount;
            DFt = totalSize - 1;

            // Step 1. Calculate the mean within each group
            means = Measures.Mean(samples, 1);

            // Step 2. Calculate the overall mean
            totalMean = Measures.GrandMean(means, sizes);


            // Step 3. Calculate the "between-group" sum of squares
            for (int i = 0; i < samples.Length; i++)
            {
                //  between-group sum of squares
                double u = (means[i] - totalMean);
                SSb += sizes[i] * u * u;
            }


            // Step 4. Calculate the "within-group" sum of squares
            for (int i = 0; i < samples.Length; i++)
            {
                for (int j = 0; j < samples[i].Length; j++)
                {
                    double u = samples[i][j] - means[i];
                    SSw += u * u;
                }
            }

            SSt = SSb + SSw; // total sum of squares


            // Step 5. Calculate the F statistic
            MSb = SSb / DFb; // between-group mean square
            MSw = SSw / DFw; // within-group mean square
            FTest = new FTest(MSb / MSw, DFb, DFw);


            // Step 6. Create the ANOVA table
            List<AnovaVariationSource> table = new List<AnovaVariationSource>();
            table.Add(new AnovaVariationSource(this, "Between-Groups", SSb, DFb, FTest));
            table.Add(new AnovaVariationSource(this, "Within-Groups", SSw, DFw, null));
            table.Add(new AnovaVariationSource(this, "Total", SSt, DFt, null));
            this.Table = new AnovaSourceCollection(table);
        }