Exemplo n.º 1
0
        /// <summary>
        /// Converts the gadget's output to Html
        /// </summary>
        /// <returns></returns>
        public override string ToHTML(string htmlFileName = "", int count = 0)
        {
            if (IsCollapsed) return string.Empty;

            StringBuilder htmlBuilder = new StringBuilder();
            CustomOutputHeading = headerPanel.Text;
            CustomOutputDescription = descriptionPanel.Text;

            if (CustomOutputHeading == null || (string.IsNullOrEmpty(CustomOutputHeading) && !CustomOutputHeading.Equals("(none)")))
            {
                htmlBuilder.AppendLine("<h2 class=\"gadgetHeading\">Means</h2>");
            }
            else if (CustomOutputHeading != "(none)")
            {
                htmlBuilder.AppendLine("<h2 class=\"gadgetHeading\">" + CustomOutputHeading + "</h2>");
            }

            htmlBuilder.AppendLine("<p class=\"gadgetOptions\"><small>");
            htmlBuilder.AppendLine("<em>Main variable:</em> <strong>" + cbxField.Text + "</strong>");
            htmlBuilder.AppendLine("<br />");

            if (cbxFieldCrosstab.SelectedIndex >= 0)
            {
                htmlBuilder.AppendLine("<em>Crosstab variable:</em> <strong>" + cbxFieldCrosstab.Text + "</strong>");
                htmlBuilder.AppendLine("<br />");
            }

            if (cbxFieldWeight.SelectedIndex >= 0)
            {
                htmlBuilder.AppendLine("<em>Weight variable:</em> <strong>" + cbxFieldWeight.Text + "</strong>");
                htmlBuilder.AppendLine("<br />");
            }
            //if (cbxFieldStrata.SelectedIndex >= 0)
            //{
            //    htmlBuilder.AppendLine("<em>Strata variable:</em> <strong>" + cbxFieldStrata.Text + "</strong>");
            //    htmlBuilder.AppendLine("<br />");
            //}
            if (lbxFieldStrata.SelectedItems.Count > 0)
            {
                WordBuilder wb = new WordBuilder(", ");
                foreach (string s in lbxFieldStrata.SelectedItems)
                {
                    wb.Add(s);
                }
                htmlBuilder.AppendLine("<em>Strata variable(s):</em> <strong>" + wb.ToString() + "</strong>");
                htmlBuilder.AppendLine("<br />");
            }

            htmlBuilder.AppendLine("</small></p>");

            if (!string.IsNullOrEmpty(CustomOutputDescription))
            {
                htmlBuilder.AppendLine("<p class=\"gadgetsummary\">" + CustomOutputDescription + "</p>");
            }

            if (!string.IsNullOrEmpty(messagePanel.Text) && messagePanel.Visibility == Visibility.Visible)
            {
                htmlBuilder.AppendLine("<p><small><strong>" + messagePanel.Text + "</strong></small></p>");
            }

            if (!string.IsNullOrEmpty(infoPanel.Text) && infoPanel.Visibility == Visibility.Visible)
            {
                htmlBuilder.AppendLine("<p><small><strong>" + infoPanel.Text + "</strong></small></p>");
            }

            // Each grid in the 'strataGridList' has a tag associated with it which tells us which strata
            // that grid is for. For example, if we stratify by 'Sex' in the Oswego table (in Sample.prj)
            // we will have two grids in strataGridList, one for males and one for females. The tags will
            // be 'Sex = Male' and 'Sex = Female', respectively.
            foreach (Grid grid in this.StrataGridList)
            {
                string gridName = grid.Tag.ToString();

                string summaryText = "This tables contains several descriptive statistics for the field " + cbxField.Text + ". ";
                if (!string.IsNullOrEmpty(cbxFieldWeight.Text)) { summaryText += "The field " + cbxFieldWeight.Text + " has been specified as a weight. "; }
                if (lbxFieldStrata.SelectedItems.Count > 0) { summaryText += "The data has been stratified. The data in this table is for the strata value " + grid.Tag.ToString() + ". "; }
                if (!string.IsNullOrEmpty(cbxFieldCrosstab.Text)) { summaryText += "The data has been cross-tabulated; there will be one data row for each value of " + cbxFieldCrosstab.Text + ". "; }
                summaryText += "The column headings are: The description of the data, the total number of observations, the sum of the observations, the mean, the variance, the standard deviation, the minimum observed value, the 25% value, the median value, the 75% value, the maximum, and the mode.";

                htmlBuilder.AppendLine("<div style=\"height: 7px;\"></div>");
                htmlBuilder.AppendLine("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" summary=\"" + summaryText + "\">");
                htmlBuilder.AppendLine("<caption>" + gridName + "</caption>");

                for (int i = 0; i < grid.RowDefinitions.Count; i++)
                {
                    for (int j = 0; j < grid.ColumnDefinitions.Count; j++)
                    {
                        string tableDataTagOpen = "<td>";
                        string tableDataTagClose = "</td>";

                        if (i == 0)
                        {
                            tableDataTagOpen = "<th>";
                            tableDataTagClose = "</th>";
                        }

                        if (j == 0)
                        {
                            htmlBuilder.AppendLine("<tr>");
                        }
                        if (j == 0 && i > 0)
                        {
                            tableDataTagOpen = "<td class=\"value\">";
                        }

                        ColumnDefinition colDef = grid.ColumnDefinitions[j];
                        if (colDef.Width.Value > 0)
                        {
                            IEnumerable<UIElement> elements = grid.Children.Cast<UIElement>().Where(x => Grid.GetRow(x) == i && Grid.GetColumn(x) == j);
                            TextBlock txt = null;
                            foreach (UIElement element in elements)
                            {
                                if (element is TextBlock)
                                {
                                    txt = element as TextBlock;
                                }
                            }
                            string value = "&nbsp;";

                            if (txt != null)
                            {
                                value = txt.Text;
                            }

                            htmlBuilder.AppendLine(tableDataTagOpen + value + tableDataTagClose);
                        }

                        if (j >= grid.ColumnDefinitions.Count - 1)
                        {
                            htmlBuilder.AppendLine("</tr>");
                        }
                    }
                }

                htmlBuilder.AppendLine("</table>");

                // We must find the specific stack panel that corresponds to this strata value from the list of
                // ANOVA panels in the gadget. The 'tag' property of the panel is a key value pair that contains
                // the strata value we need, plus the set of descriptive statistics that we must display in the
                // output.
                StackPanel anovaPanel = null;
                DescriptiveStatistics statistics = new DescriptiveStatistics();
                foreach (StackPanel panel in anovaBlocks)
                {
                    if(panel.Tag is KeyValuePair<string, DescriptiveStatistics>)
                    {
                        KeyValuePair<string, DescriptiveStatistics> kvp = ((KeyValuePair<string, DescriptiveStatistics>)panel.Tag);
                        if (kvp.Key.Equals(gridName))
                        {
                            anovaPanel = panel;
                            statistics = kvp.Value;
                            break; // no sense in continuning
                        }
                    }
                }

                // check to make sure we actually found one
                if (!(anovaPanel == null))
                {
                    string strssBetweenValue = SharedStrings.UNDEFINED;
                    string strdfBetweenValue = SharedStrings.UNDEFINED;
                    string strmsBetweenValue = SharedStrings.UNDEFINED;
                    string strssWithinValue = SharedStrings.UNDEFINED;
                    string strdfWithinValue = SharedStrings.UNDEFINED;
                    string strmsWithinValue = SharedStrings.UNDEFINED;
                    string strfStatisticValue = SharedStrings.UNDEFINED;
                    string stranovaPValueValue = SharedStrings.UNDEFINED;
                    string stranovaTValueValue = SharedStrings.UNDEFINED;
                    string strchiSquareValue = SharedStrings.UNDEFINED;
                    string strbartlettPValue = SharedStrings.UNDEFINED;
                    string strTotalSSValue = SharedStrings.UNDEFINED;
                    string strTotalDFValue = SharedStrings.UNDEFINED;
                    string strKruskalWallisH = SharedStrings.UNDEFINED;
                    string strKruskalPValue = SharedStrings.UNDEFINED;

                    if (statistics.ssBetween.HasValue) { strssBetweenValue = statistics.ssBetween.Value.ToString("F4"); }
                    if (statistics.dfBetween.HasValue) { strdfBetweenValue = statistics.dfBetween.Value.ToString("F0"); }
                    if (statistics.msBetween.HasValue) { strmsBetweenValue = statistics.msBetween.Value.ToString("F4"); }
                    if (statistics.ssWithin.HasValue) { strssWithinValue = statistics.ssWithin.Value.ToString("F4"); }
                    if (statistics.dfWithin.HasValue) { strdfWithinValue = statistics.dfWithin.Value.ToString("F0"); }
                    if (statistics.msWithin.HasValue) { strmsWithinValue = statistics.msWithin.Value.ToString("F4"); }
                    if (statistics.fStatistic.HasValue) { strfStatisticValue = statistics.fStatistic.Value.ToString("F4"); }
                    if (statistics.anovaPValue.HasValue) { stranovaPValueValue = statistics.anovaPValue.Value.ToString("F4"); }
                    if (statistics.chiSquare.HasValue) { strchiSquareValue = statistics.chiSquare.Value.ToString("F4"); }
                    if (statistics.bartlettPValue.HasValue) { strbartlettPValue = statistics.bartlettPValue.Value.ToString("F4"); }

                    if (statistics.ssBetween.HasValue && statistics.ssWithin.HasValue) { strTotalSSValue = (statistics.ssBetween.Value + statistics.ssWithin.Value).ToString("F4"); }
                    if (statistics.dfBetween.HasValue && statistics.dfWithin.HasValue) { strTotalDFValue = (statistics.dfBetween.Value + statistics.dfWithin.Value).ToString("F0"); }
                    if (statistics.kruskalWallisH.HasValue) { strKruskalWallisH = statistics.kruskalWallisH.Value.ToString("F4"); }
                    if (statistics.kruskalPValue.HasValue) { strKruskalPValue = statistics.kruskalPValue.Value.ToString("F4"); }

                    summaryText = "This table contains analysis of variance (ANOVA) statistics for the field " + cbxField.Text + ", cross-tabulated by " + cbxFieldCrosstab.Text + ". ";
                    summaryText += "The column headings for this table are: The variation, the SS value, the degrees of freedom, the MS value, and the F-statistic. There are three rows: The between, the within, and the total.";

                    // ANOVA
                    htmlBuilder.AppendLine("<div style=\"height: 7px;\"></div>");
                    htmlBuilder.AppendLine("<p><strong>" + SharedStrings.ANOVA_DESCRIPTION_FOR_MEANS + "</strong><br />");
                    htmlBuilder.AppendLine("<small>" + SharedStrings.ANOVA_DESCRIPTION_FOR_MEANS_SUBTITLE + "</small></p>");
                    htmlBuilder.AppendLine("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" summary=\"" + summaryText + "\">");
                    htmlBuilder.AppendLine(" <tr>");
                    htmlBuilder.AppendLine("   <th>Variation</th>");
                    htmlBuilder.AppendLine("   <th>SS</th>");
                    htmlBuilder.AppendLine("   <th>df</th>");
                    htmlBuilder.AppendLine("   <th>MS</th>");
                    htmlBuilder.AppendLine("   <th>F statistic</th>");
                    htmlBuilder.AppendLine(" </tr>");

                    htmlBuilder.AppendLine(" <tr>");
                    htmlBuilder.AppendLine("   <th>Between</th>");
                    htmlBuilder.AppendLine("   <td>" + strssBetweenValue + "</td>");
                    htmlBuilder.AppendLine("   <td>" + strdfBetweenValue + "</td>");
                    htmlBuilder.AppendLine("   <td>" + strmsBetweenValue + "</td>");
                    htmlBuilder.AppendLine("   <td>" + strfStatisticValue + "</td>");
                    htmlBuilder.AppendLine(" </tr>");

                    htmlBuilder.AppendLine(" <tr>");
                    htmlBuilder.AppendLine("   <th>Within</th>");
                    htmlBuilder.AppendLine("   <td>" + strssWithinValue + "</td>");
                    htmlBuilder.AppendLine("   <td>" + strdfWithinValue + "</td>");
                    htmlBuilder.AppendLine("   <td>" + strmsWithinValue + "</td>");
                    htmlBuilder.AppendLine("   <td>&nbsp;</td>");
                    htmlBuilder.AppendLine(" </tr>");

                    htmlBuilder.AppendLine(" <tr>");
                    htmlBuilder.AppendLine("   <th>Total</th>");
                    htmlBuilder.AppendLine("   <td>" + strTotalSSValue + "</td>");
                    htmlBuilder.AppendLine("   <td>" + strTotalDFValue + "</td>");
                    htmlBuilder.AppendLine("   <td>&nbsp;</td>");
                    htmlBuilder.AppendLine("   <td>&nbsp;</td>");
                    htmlBuilder.AppendLine(" </tr>");
                    htmlBuilder.AppendLine("</table>");

                    htmlBuilder.AppendLine("<div style=\"height: 7px;\"></div>");

                    htmlBuilder.AppendLine("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" summary=\"This table contains the ANOVA p-value.\">");
                    htmlBuilder.AppendLine(" <tr>");
                    htmlBuilder.AppendLine("   <th>P Value</th>");
                    htmlBuilder.AppendLine("   <td>" + stranovaPValueValue + "</td>");
                    htmlBuilder.AppendLine(" </tr>");
                    htmlBuilder.AppendLine("</table>");

                    // Bartlett
                    htmlBuilder.AppendLine("<div style=\"height: 7px;\"></div>");
                    htmlBuilder.AppendLine("<p><strong>Bartlett's Test for Inequality of Population Variances</strong></p>");
                    htmlBuilder.AppendLine("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">");
                    htmlBuilder.AppendLine(" <tr>");
                    htmlBuilder.AppendLine("   <th>Chi Square</th>");
                    htmlBuilder.AppendLine("   <td>" + strchiSquareValue + "</td>");
                    htmlBuilder.AppendLine(" </tr>");

                    htmlBuilder.AppendLine(" <tr>");
                    htmlBuilder.AppendLine("   <th>Degrees of freedom</th>");
                    htmlBuilder.AppendLine("   <td>" + strdfBetweenValue + "</td>");
                    htmlBuilder.AppendLine(" </tr>");

                    htmlBuilder.AppendLine(" <tr>");
                    htmlBuilder.AppendLine("   <th>P Value</th>");
                    htmlBuilder.AppendLine("   <td>" + strbartlettPValue + "</td>");
                    htmlBuilder.AppendLine("</table>");

                    htmlBuilder.AppendLine("<p><small>A small p-value (e.g., less than 0.05) suggests that the variances are not homogeneous and that the ANOVA may not be appropriate.</small></p>");

                    // Kruskal-Wallis
                    htmlBuilder.AppendLine("<div style=\"height: 7px;\"></div>");
                    htmlBuilder.AppendLine("<p><strong>Mann-Whitney/Wilcoxon Two-Sample Test (Kruskal-Wallis test for two groups)</strong></p>");
                    htmlBuilder.AppendLine("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" >");
                    htmlBuilder.AppendLine(" <tr>");
                    htmlBuilder.AppendLine("   <th>Kruskal-Wallis H</th>");
                    htmlBuilder.AppendLine("   <td>" + strKruskalWallisH + "</td>");
                    htmlBuilder.AppendLine(" </tr>");

                    htmlBuilder.AppendLine(" <tr>");
                    htmlBuilder.AppendLine("   <th>Degrees of freedom</th>");
                    htmlBuilder.AppendLine("   <td>" + strdfBetweenValue + "</td>");
                    htmlBuilder.AppendLine(" </tr>");

                    htmlBuilder.AppendLine(" <tr>");
                    htmlBuilder.AppendLine("   <th>P Value</th>");
                    htmlBuilder.AppendLine("   <td>" + strKruskalPValue + "</td>");
                    htmlBuilder.AppendLine("</table>");
                }
            }

            return htmlBuilder.ToString();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Adds anova statistics to the gadget
        /// </summary>
        /// <param name="strataValue">The strata value associated with the results</param>
        /// <param name="stats">The descriptive statistics to process</param>
        private void AddAnova(string strataValue, DescriptiveStatistics stats)
        {
            if (stats.crosstabs == 2)
            {
                Expander tTestExpander = new Expander();
                tTestExpander.Margin = (Thickness)this.Resources["expanderMargin"];
                tTestExpander.IsExpanded = true;

                StackPanel pnlT = new StackPanel();

                tTestExpander.Content = pnlT;

                if (this.StrataCount > 1)
                {
                    Expander expander = GetStrataExpander(strataValue);
                    if (expander.Content is StackPanel)
                    {
                        StackPanel sPanel = expander.Content as StackPanel;
                        sPanel.Children.Add(tTestExpander);
                    }
                }
                else
                {
                    panelMain.Children.Add(tTestExpander);
                }

                    KeyValuePair<string, DescriptiveStatistics> TTestStatistics = new KeyValuePair<string, DescriptiveStatistics>(strataValue, stats);
                    pnlT.Tag = TTestStatistics;
                    pnlT.HorizontalAlignment = HorizontalAlignment.Center;
                    pnlT.VerticalAlignment = VerticalAlignment.Center;
                    pnlT.Margin = new Thickness(5);
                    anovaBlocks.Add(pnlT);

                    TextBlock txtT1 = new TextBlock();
                    txtT1.Text = "T-Test";
                    txtT1.HorizontalAlignment = HorizontalAlignment.Center;
                    txtT1.Margin = new Thickness(5);
                    txtT1.FontWeight = FontWeights.Bold;
                    tTestExpander.Header = txtT1;

                    Grid tGrid1 = new Grid();
                    tGrid1.SnapsToDevicePixels = true;
                    tGrid1.HorizontalAlignment = HorizontalAlignment.Center;
                    tGrid1.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(30) });
                    tGrid1.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(30) });
                    tGrid1.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(30) });
                    tGrid1.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto });
                    tGrid1.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto });
                    tGrid1.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto });
                    tGrid1.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto });
                    tGrid1.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto });
                    tGrid1.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto });

                    pnlT.Children.Add(tGrid1);

                    for (int y = 0; y < tGrid1.ColumnDefinitions.Count; y++)
                    {
                        Rectangle rctHeader = new Rectangle();
                        rctHeader.Style = this.Resources["gridHeaderCellRectangle"] as Style;
                        Grid.SetRow(rctHeader, 0);
                        Grid.SetColumn(rctHeader, y);
                        tGrid1.Children.Add(rctHeader);
                    }

                    TextBlock tDiffPooled = new TextBlock();
                    tDiffPooled.Text = "Diff (Group 1 - Group 2)";
                    tDiffPooled.Margin = new Thickness(4, 0, 4, 0);
                    tDiffPooled.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
                    tDiffPooled.VerticalAlignment = System.Windows.VerticalAlignment.Center;
                    tGrid1.Children.Add(tDiffPooled);
                    Grid.SetRow(tDiffPooled, 1);
                    Grid.SetColumn(tDiffPooled, 0);

                    TextBlock tDiffSatterthwaite = new TextBlock();
                    tDiffSatterthwaite.Text = "Diff (Group 1 - Group 2)";
                    tDiffSatterthwaite.Margin = new Thickness(4, 0, 4, 0);
                    tDiffSatterthwaite.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
                    tDiffSatterthwaite.VerticalAlignment = System.Windows.VerticalAlignment.Center;
                    tGrid1.Children.Add(tDiffSatterthwaite);
                    Grid.SetRow(tDiffSatterthwaite, 2);
                    Grid.SetColumn(tDiffSatterthwaite, 0);

                    TextBlock methodHeader = new TextBlock();
                    methodHeader.Text = "Method";
                    methodHeader.Margin = new Thickness(4, 0, 4, 0);
                    methodHeader.FontWeight = FontWeights.Bold;
                    methodHeader.Foreground = Brushes.White;
                    methodHeader.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
                    methodHeader.VerticalAlignment = System.Windows.VerticalAlignment.Center;
                    tGrid1.Children.Add(methodHeader);
                    Grid.SetRow(methodHeader, 0);
                    Grid.SetColumn(methodHeader, 1);

                    TextBlock meanHeader = new TextBlock();
                    meanHeader.Text = "Mean";
                    meanHeader.Margin = new Thickness(4, 0, 4, 0);
                    meanHeader.FontWeight = FontWeights.Bold;
                    meanHeader.Foreground = Brushes.White;
                    meanHeader.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
                    meanHeader.VerticalAlignment = System.Windows.VerticalAlignment.Center;
                    tGrid1.Children.Add(meanHeader);
                    Grid.SetRow(meanHeader, 0);
                    Grid.SetColumn(meanHeader, 2);

                    TextBlock clHeader = new TextBlock();
                    clHeader.Text = "95%";
                    clHeader.Margin = new Thickness(4, 0, 4, 0);
                    clHeader.FontWeight = FontWeights.Bold;
                    clHeader.Foreground = Brushes.White;
                    clHeader.HorizontalAlignment = System.Windows.HorizontalAlignment.Right;
                    clHeader.VerticalAlignment = System.Windows.VerticalAlignment.Center;
                    tGrid1.Children.Add(clHeader);
                    Grid.SetRow(clHeader, 0);
                    Grid.SetColumn(clHeader, 3);

                    TextBlock uclHeader = new TextBlock();
                    uclHeader.Text = "CL";
                    uclHeader.Margin = new Thickness(4, 0, 4, 0);
                    uclHeader.FontWeight = FontWeights.Bold;
                    uclHeader.Foreground = Brushes.White;
                    uclHeader.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
                    uclHeader.VerticalAlignment = System.Windows.VerticalAlignment.Center;
                    tGrid1.Children.Add(uclHeader);
                    Grid.SetRow(uclHeader, 0);
                    Grid.SetColumn(uclHeader, 4);

                    TextBlock stdDevHeader = new TextBlock();
                    stdDevHeader.Text = "StdDev";
                    stdDevHeader.Margin = new Thickness(4, 0, 4, 0);
                    stdDevHeader.FontWeight = FontWeights.Bold;
                    stdDevHeader.Foreground = Brushes.White;
                    stdDevHeader.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
                    stdDevHeader.VerticalAlignment = System.Windows.VerticalAlignment.Center;
                    tGrid1.Children.Add(stdDevHeader);
                    Grid.SetRow(stdDevHeader, 0);
                    Grid.SetColumn(stdDevHeader, 5);

                    TextBlock txtMethod = new TextBlock();
                    txtMethod.Text = "Pooled";
                    txtMethod.Margin = new Thickness(4, 0, 4, 0);
                    txtMethod.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
                    txtMethod.VerticalAlignment = System.Windows.VerticalAlignment.Center;
                    tGrid1.Children.Add(txtMethod);
                    Grid.SetRow(txtMethod, 1);
                    Grid.SetColumn(txtMethod, 1);

                    TextBlock txtMeanP = new TextBlock();
                    txtMeanP.Text = stats.meansDiff.ToString("N4");
                    txtMeanP.Margin = new Thickness(4, 0, 4, 0);
                    txtMeanP.HorizontalAlignment = System.Windows.HorizontalAlignment.Right;
                    txtMeanP.VerticalAlignment = System.Windows.VerticalAlignment.Center;
                    tGrid1.Children.Add(txtMeanP);
                    Grid.SetRow(txtMeanP, 1);
                    Grid.SetColumn(txtMeanP, 2);

                    TextBlock txtLCLP = new TextBlock();
                    txtLCLP.Text = stats.equalLCLMean.ToString("N4");
                    txtLCLP.Margin = new Thickness(4, 0, 4, 0);
                    txtLCLP.HorizontalAlignment = System.Windows.HorizontalAlignment.Right;
                    txtLCLP.VerticalAlignment = System.Windows.VerticalAlignment.Center;
                    tGrid1.Children.Add(txtLCLP);
                    Grid.SetRow(txtLCLP, 1);
                    Grid.SetColumn(txtLCLP, 3);

                    TextBlock txtUCLP = new TextBlock();
                    txtUCLP.Text = stats.equalUCLMean.ToString("N4");
                    txtUCLP.Margin = new Thickness(4, 0, 4, 0);
                    txtUCLP.HorizontalAlignment = System.Windows.HorizontalAlignment.Right;
                    txtUCLP.VerticalAlignment = System.Windows.VerticalAlignment.Center;
                    tGrid1.Children.Add(txtUCLP);
                    Grid.SetRow(txtUCLP, 1);
                    Grid.SetColumn(txtUCLP, 4);

                    TextBlock txtStdDev = new TextBlock();
                    txtStdDev.Text = stats.stdDevDiff.ToString("N4");
                    txtStdDev.Margin = new Thickness(4, 0, 4, 0);
                    txtStdDev.HorizontalAlignment = System.Windows.HorizontalAlignment.Right;
                    txtStdDev.VerticalAlignment = System.Windows.VerticalAlignment.Center;
                    tGrid1.Children.Add(txtStdDev);
                    Grid.SetRow(txtStdDev, 1);
                    Grid.SetColumn(txtStdDev, 5);

                    TextBlock txtMethodS = new TextBlock();
                    txtMethodS.Text = "Satterthwaite";
                    txtMethodS.Margin = new Thickness(4, 0, 4, 0);
                    txtMethodS.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
                    txtMethodS.VerticalAlignment = System.Windows.VerticalAlignment.Center;
                    tGrid1.Children.Add(txtMethodS);
                    Grid.SetRow(txtMethodS, 21);
                    Grid.SetColumn(txtMethodS, 1);

                    TextBlock txtMeanS = new TextBlock();
                    txtMeanS.Text = stats.meansDiff.ToString("N4");
                    txtMeanS.Margin = new Thickness(4, 0, 4, 0);
                    txtMeanS.HorizontalAlignment = System.Windows.HorizontalAlignment.Right;
                    txtMeanS.VerticalAlignment = System.Windows.VerticalAlignment.Center;
                    tGrid1.Children.Add(txtMeanS);
                    Grid.SetRow(txtMeanS, 2);
                    Grid.SetColumn(txtMeanS, 2);

                    TextBlock txtLCLS = new TextBlock();
                    txtLCLS.Text = stats.unequalLCLMean.ToString("N4");
                    txtLCLS.Margin = new Thickness(4, 0, 4, 0);
                    txtLCLS.HorizontalAlignment = System.Windows.HorizontalAlignment.Right;
                    txtLCLS.VerticalAlignment = System.Windows.VerticalAlignment.Center;
                    tGrid1.Children.Add(txtLCLS);
                    Grid.SetRow(txtLCLS, 2);
                    Grid.SetColumn(txtLCLS, 3);

                    TextBlock txtUCLS = new TextBlock();
                    txtUCLS.Text = stats.unequalUCLMean.ToString("N4");
                    txtUCLS.Margin = new Thickness(4, 0, 4, 0);
                    txtUCLS.HorizontalAlignment = System.Windows.HorizontalAlignment.Right;
                    txtUCLS.VerticalAlignment = System.Windows.VerticalAlignment.Center;
                    tGrid1.Children.Add(txtUCLS);
                    Grid.SetRow(txtUCLS, 2);
                    Grid.SetColumn(txtUCLS, 4);

                    int rdcountT = 0;
                    foreach (RowDefinition rd in tGrid1.RowDefinitions)
                    {
                        int cdcount = 0;
                        foreach (ColumnDefinition cd in tGrid1.ColumnDefinitions)
                        {
                            Border b = new Border();
                            b.Style = this.Resources["gridCellBorder"] as Style;

                            if (rdcountT == 0)
                            {
                                b.BorderThickness = new Thickness(b.BorderThickness.Left, 1, b.BorderThickness.Right, b.BorderThickness.Bottom);
                            }
                            if (cdcount == 0)
                            {
                                b.BorderThickness = new Thickness(1, b.BorderThickness.Top, b.BorderThickness.Right, b.BorderThickness.Bottom);
                            }
                            if (cdcount == 3 && rdcountT == 0)
                            {
                                b.BorderThickness = new Thickness(b.BorderThickness.Left, 1, 0, b.BorderThickness.Bottom);
                            }

                            Grid.SetRow(b, rdcountT);
                            Grid.SetColumn(b, cdcount);
                            tGrid1.Children.Add(b);
                            cdcount++;
                        }
                        rdcountT++;
                    }

                    Grid tGrid2 = new Grid();
                    tGrid2.Margin = new Thickness(5);
                    tGrid2.SnapsToDevicePixels = true;
                    tGrid2.HorizontalAlignment = HorizontalAlignment.Center;
                    tGrid2.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(30) });
                    tGrid2.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(30) });
                    tGrid2.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(30) });
                    tGrid2.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto });
                    tGrid2.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto });
                    tGrid2.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto });
                    tGrid2.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto });
                    tGrid2.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto });

                    pnlT.Children.Add(tGrid2);

                    for (int y = 0; y < tGrid2.ColumnDefinitions.Count; y++)
                    {
                        Rectangle rctHeader = new Rectangle();
                        rctHeader.Style = this.Resources["gridHeaderCellRectangle"] as Style;
                        Grid.SetRow(rctHeader, 0);
                        Grid.SetColumn(rctHeader, y);
                        tGrid2.Children.Add(rctHeader);
                    }

                    TextBlock methodHeaderG2 = new TextBlock();
                    methodHeaderG2.Text = "Method";
                    methodHeaderG2.Margin = new Thickness(4, 0, 4, 0);
                    methodHeaderG2.FontWeight = FontWeights.Bold;
                    methodHeaderG2.Foreground = Brushes.White;
                    methodHeaderG2.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
                    methodHeaderG2.VerticalAlignment = System.Windows.VerticalAlignment.Center;
                    tGrid2.Children.Add(methodHeaderG2);
                    Grid.SetRow(methodHeaderG2, 0);
                    Grid.SetColumn(methodHeaderG2, 0);

                    TextBlock variancesHeader = new TextBlock();
                    variancesHeader.Text = "Variances";
                    variancesHeader.Margin = new Thickness(4, 0, 4, 0);
                    variancesHeader.FontWeight = FontWeights.Bold;
                    variancesHeader.Foreground = Brushes.White;
                    variancesHeader.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
                    variancesHeader.VerticalAlignment = System.Windows.VerticalAlignment.Center;
                    tGrid2.Children.Add(variancesHeader);
                    Grid.SetRow(variancesHeader, 0);
                    Grid.SetColumn(variancesHeader, 1);

                    TextBlock dfHeader = new TextBlock();
                    dfHeader.Text = "DF";
                    dfHeader.Margin = new Thickness(4, 0, 4, 0);
                    dfHeader.FontWeight = FontWeights.Bold;
                    dfHeader.Foreground = Brushes.White;
                    dfHeader.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
                    dfHeader.VerticalAlignment = System.Windows.VerticalAlignment.Center;
                    tGrid2.Children.Add(dfHeader);
                    Grid.SetRow(dfHeader, 0);
                    Grid.SetColumn(dfHeader, 2);

                    TextBlock tValueHeader = new TextBlock();
                    tValueHeader.Text = "t Value";
                    tValueHeader.Margin = new Thickness(4, 0, 4, 0);
                    tValueHeader.FontWeight = FontWeights.Bold;
                    tValueHeader.Foreground = Brushes.White;
                    tValueHeader.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
                    tValueHeader.VerticalAlignment = System.Windows.VerticalAlignment.Center;
                    tGrid2.Children.Add(tValueHeader);
                    Grid.SetRow(tValueHeader, 0);
                    Grid.SetColumn(tValueHeader, 3);

                    TextBlock prHeader = new TextBlock();
                    prHeader.Text = "Pr > |t|";
                    prHeader.Margin = new Thickness(4, 0, 4, 0);
                    prHeader.FontWeight = FontWeights.Bold;
                    prHeader.Foreground = Brushes.White;
                    prHeader.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
                    prHeader.VerticalAlignment = System.Windows.VerticalAlignment.Center;
                    tGrid2.Children.Add(prHeader);
                    Grid.SetRow(prHeader, 0);
                    Grid.SetColumn(prHeader, 4);

                    TextBlock txtPooled = new TextBlock();
                    txtPooled.Text = "Pooled";
                    txtPooled.Margin = new Thickness(4, 0, 4, 0);
                    txtPooled.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
                    txtPooled.VerticalAlignment = System.Windows.VerticalAlignment.Center;
                    tGrid2.Children.Add(txtPooled);
                    Grid.SetRow(txtPooled, 1);
                    Grid.SetColumn(txtPooled, 0);

                    TextBlock txtSatterthwaite = new TextBlock();
                    txtSatterthwaite.Text = "Satterthwaite";
                    txtSatterthwaite.Margin = new Thickness(4, 0, 4, 0);
                    txtSatterthwaite.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
                    txtSatterthwaite.VerticalAlignment = System.Windows.VerticalAlignment.Center;
                    tGrid2.Children.Add(txtSatterthwaite);
                    Grid.SetRow(txtSatterthwaite, 2);
                    Grid.SetColumn(txtSatterthwaite, 0);

                    TextBlock txtEqual = new TextBlock();
                    txtEqual.Text = "Equal";
                    txtEqual.Margin = new Thickness(4, 0, 4, 0);
                    txtEqual.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
                    txtEqual.VerticalAlignment = System.Windows.VerticalAlignment.Center;
                    tGrid2.Children.Add(txtEqual);
                    Grid.SetRow(txtEqual, 1);
                    Grid.SetColumn(txtEqual, 1);

                    TextBlock txtUnequal = new TextBlock();
                    txtUnequal.Text = "Unequal";
                    txtUnequal.Margin = new Thickness(4, 0, 4, 0);
                    txtUnequal.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
                    txtUnequal.VerticalAlignment = System.Windows.VerticalAlignment.Center;
                    tGrid2.Children.Add(txtUnequal);
                    Grid.SetRow(txtUnequal, 2);
                    Grid.SetColumn(txtUnequal, 1);

                    TextBlock txtDFP = new TextBlock();
                    txtDFP.Text = stats.df.ToString();
                    txtDFP.Margin = new Thickness(4, 0, 4, 0);
                    txtDFP.HorizontalAlignment = System.Windows.HorizontalAlignment.Right;
                    txtDFP.VerticalAlignment = System.Windows.VerticalAlignment.Center;
                    tGrid2.Children.Add(txtDFP);
                    Grid.SetRow(txtDFP, 1);
                    Grid.SetColumn(txtDFP, 2);

                    TextBlock txtDFS = new TextBlock();
                    txtDFS.Text = stats.SatterthwaiteDF.ToString("N2");
                    txtDFS.Margin = new Thickness(4, 0, 4, 0);
                    txtDFS.HorizontalAlignment = System.Windows.HorizontalAlignment.Right;
                    txtDFS.VerticalAlignment = System.Windows.VerticalAlignment.Center;
                    tGrid2.Children.Add(txtDFS);
                    Grid.SetRow(txtDFS, 2);
                    Grid.SetColumn(txtDFS, 2);

                    TextBlock txtTStatP = new TextBlock();
                    txtTStatP.Text = stats.tStatistic.ToString("N4");
                    txtTStatP.Margin = new Thickness(4, 0, 4, 0);
                    txtTStatP.HorizontalAlignment = System.Windows.HorizontalAlignment.Right;
                    txtTStatP.VerticalAlignment = System.Windows.VerticalAlignment.Center;
                    tGrid2.Children.Add(txtTStatP);
                    Grid.SetRow(txtTStatP, 1);
                    Grid.SetColumn(txtTStatP, 3);

                    TextBlock txtTStatS = new TextBlock();
                    txtTStatS.Text = stats.tStatisticUnequal.ToString("N4");
                    txtTStatS.Margin = new Thickness(4, 0, 4, 0);
                    txtTStatS.HorizontalAlignment = System.Windows.HorizontalAlignment.Right;
                    txtTStatS.VerticalAlignment = System.Windows.VerticalAlignment.Center;
                    tGrid2.Children.Add(txtTStatS);
                    Grid.SetRow(txtTStatS, 2);
                    Grid.SetColumn(txtTStatS, 3);

                    TextBlock txtPValueP = new TextBlock();
                    txtPValueP.Text = stats.pEqual.ToString("N4");
                    txtPValueP.Margin = new Thickness(4, 0, 4, 0);
                    txtPValueP.HorizontalAlignment = System.Windows.HorizontalAlignment.Right;
                    txtPValueP.VerticalAlignment = System.Windows.VerticalAlignment.Center;
                    tGrid2.Children.Add(txtPValueP);
                    Grid.SetRow(txtPValueP, 1);
                    Grid.SetColumn(txtPValueP, 4);

                    TextBlock txtPValueS = new TextBlock();
                    txtPValueS.Text = stats.pUneqal.ToString("N4");
                    txtPValueS.Margin = new Thickness(4, 0, 4, 0);
                    txtPValueS.HorizontalAlignment = System.Windows.HorizontalAlignment.Right;
                    txtPValueS.VerticalAlignment = System.Windows.VerticalAlignment.Center;
                    tGrid2.Children.Add(txtPValueS);
                    Grid.SetRow(txtPValueS, 2);
                    Grid.SetColumn(txtPValueS, 4);

                    rdcountT = 0;
                    foreach (RowDefinition rd in tGrid2.RowDefinitions)
                    {
                        int cdcount = 0;
                        foreach (ColumnDefinition cd in tGrid2.ColumnDefinitions)
                        {
                            Border b = new Border();
                            b.Style = this.Resources["gridCellBorder"] as Style;

                            if (rdcountT == 0)
                            {
                                b.BorderThickness = new Thickness(b.BorderThickness.Left, 1, b.BorderThickness.Right, b.BorderThickness.Bottom);
                            }
                            if (cdcount == 0)
                            {
                                b.BorderThickness = new Thickness(1, b.BorderThickness.Top, b.BorderThickness.Right, b.BorderThickness.Bottom);
                            }

                            Grid.SetRow(b, rdcountT);
                            Grid.SetColumn(b, cdcount);
                            tGrid2.Children.Add(b);
                            cdcount++;
                        }
                        rdcountT++;
                    }
            }

            Expander anovaExpander = new Expander();
            anovaExpander.Margin = (Thickness)this.Resources["expanderMargin"];
            anovaExpander.IsExpanded = true;

            StackPanel pnl = new StackPanel();

            anovaExpander.Content = pnl;

            if (this.StrataCount > 1)
            {
                Expander expander = GetStrataExpander(strataValue);
                if (expander.Content is StackPanel)
                {
                    StackPanel sPanel = expander.Content as StackPanel;
                    sPanel.Children.Add(anovaExpander);
                }
            }
            else
            {
                panelMain.Children.Add(anovaExpander);
            }

            KeyValuePair<string, DescriptiveStatistics> ANOVAStatistics = new KeyValuePair<string, DescriptiveStatistics>(strataValue, stats);
            pnl.Tag = ANOVAStatistics;
            pnl.HorizontalAlignment = HorizontalAlignment.Center;
            pnl.VerticalAlignment = VerticalAlignment.Center;
            pnl.Margin = new Thickness(5);
            anovaBlocks.Add(pnl);

            TextBlock txt1 = new TextBlock();
            txt1.Text = SharedStrings.ANOVA_DESCRIPTION_FOR_MEANS;
            txt1.HorizontalAlignment = HorizontalAlignment.Center;
            txt1.Margin = new Thickness(5);
            txt1.FontWeight = FontWeights.Bold;
            //pnl.Children.Add(txt1);
            anovaExpander.Header = txt1;

            #region Grid1
            TextBlock txt2 = new TextBlock();
            txt2.Text = SharedStrings.ANOVA_DESCRIPTION_FOR_MEANS_SUBTITLE;
            txt2.HorizontalAlignment = HorizontalAlignment.Center;
            pnl.Children.Add(txt2);

            Grid grid1 = new Grid();
            grid1.SnapsToDevicePixels = true;
            grid1.HorizontalAlignment = HorizontalAlignment.Center;
            grid1.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(30) });
            grid1.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(30) });
            grid1.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(30) });
            grid1.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(30) });
            grid1.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto });
            grid1.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto });
            grid1.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto });
            grid1.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto });
            grid1.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto });

            pnl.Children.Add(grid1);

            for (int y = 0; y < grid1.ColumnDefinitions.Count; y++)
            {
                Rectangle rctHeader = new Rectangle();
                rctHeader.Style = this.Resources["gridHeaderCellRectangle"] as Style;
                Grid.SetRow(rctHeader, 0);
                Grid.SetColumn(rctHeader, y);
                grid1.Children.Add(rctHeader);
            }

            for (int y = 1; y < grid1.RowDefinitions.Count; y++)
            {
                Rectangle rctHeader = new Rectangle();
                rctHeader.Style = this.Resources["gridHeaderCellRectangle"] as Style;
                Grid.SetRow(rctHeader, y);
                Grid.SetColumn(rctHeader, 0);
                grid1.Children.Add(rctHeader);
            }

            TextBlock lblVariation = new TextBlock();
            lblVariation.Text = SharedStrings.ANOVA_VARIATION;
            lblVariation.Margin = new Thickness(4, 0, 4, 0);
            lblVariation.FontWeight = FontWeights.Bold;
            lblVariation.Foreground = Brushes.White;
            lblVariation.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
            lblVariation.VerticalAlignment = System.Windows.VerticalAlignment.Center;
            grid1.Children.Add(lblVariation);
            Grid.SetRow(lblVariation, 0);
            Grid.SetColumn(lblVariation, 0);

            TextBlock lblBetween = new TextBlock();
            lblBetween.Text = SharedStrings.ANOVA_BETWEEN;
            lblBetween.Margin = new Thickness(4, 0, 4, 0);
            lblBetween.FontWeight = FontWeights.Bold;
            lblBetween.Foreground = Brushes.White;
            lblBetween.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
            lblBetween.VerticalAlignment = System.Windows.VerticalAlignment.Center;
            grid1.Children.Add(lblBetween);
            Grid.SetRow(lblBetween, 1);
            Grid.SetColumn(lblBetween, 0);

            TextBlock lblWithin = new TextBlock();
            lblWithin.Text = SharedStrings.ANOVA_WITHIN;
            lblWithin.Margin = new Thickness(4, 0, 4, 0);
            lblWithin.FontWeight = FontWeights.Bold;
            lblWithin.Foreground = Brushes.White;
            lblWithin.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
            lblWithin.VerticalAlignment = System.Windows.VerticalAlignment.Center;
            grid1.Children.Add(lblWithin);
            Grid.SetRow(lblWithin, 2);
            Grid.SetColumn(lblWithin, 0);

            TextBlock lblTotal = new TextBlock();
            lblTotal.Text = SharedStrings.ANOVA_TOTAL;
            lblTotal.Margin = new Thickness(4, 0, 4, 0);
            lblTotal.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
            lblTotal.VerticalAlignment = System.Windows.VerticalAlignment.Center;
            lblTotal.FontWeight = FontWeights.Bold;
            lblTotal.Foreground = Brushes.White;
            grid1.Children.Add(lblTotal);
            Grid.SetRow(lblTotal, 3);
            Grid.SetColumn(lblTotal, 0);

            TextBlock lblSS = new TextBlock();
            lblSS.Text = SharedStrings.ANOVA_SS;
            lblSS.Margin = new Thickness(4, 0, 4, 0);
            lblSS.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
            lblSS.VerticalAlignment = System.Windows.VerticalAlignment.Center;
            lblSS.FontWeight = FontWeights.Bold;
            lblSS.Foreground = Brushes.White;
            grid1.Children.Add(lblSS);
            Grid.SetRow(lblSS, 0);
            Grid.SetColumn(lblSS, 1);

            TextBlock lblDf = new TextBlock();
            lblDf.Text = SharedStrings.ANOVA_DF_SHORT;
            lblDf.Margin = new Thickness(4, 0, 4, 0);
            lblDf.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
            lblDf.VerticalAlignment = System.Windows.VerticalAlignment.Center;
            lblDf.FontWeight = FontWeights.Bold;
            lblDf.Foreground = Brushes.White;
            grid1.Children.Add(lblDf);
            Grid.SetRow(lblDf, 0);
            Grid.SetColumn(lblDf, 2);

            TextBlock lblMS = new TextBlock();
            lblMS.Text = SharedStrings.ANOVA_MS;
            lblMS.Margin = new Thickness(4, 0, 4, 0);
            lblMS.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
            lblMS.VerticalAlignment = System.Windows.VerticalAlignment.Center;
            lblMS.FontWeight = FontWeights.Bold;
            lblMS.Foreground = Brushes.White;
            grid1.Children.Add(lblMS);
            Grid.SetRow(lblMS, 0);
            Grid.SetColumn(lblMS, 3);

            TextBlock lblF = new TextBlock();
            lblF.Text = SharedStrings.ANOVA_F;
            lblF.Margin = new Thickness(4, 0, 4, 0);
            lblF.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
            lblF.VerticalAlignment = System.Windows.VerticalAlignment.Center;
            lblF.FontWeight = FontWeights.Bold;
            lblF.Foreground = Brushes.White;
            grid1.Children.Add(lblF);
            Grid.SetRow(lblF, 0);
            Grid.SetColumn(lblF, 4);

            TextBlock txtSSBetween = new TextBlock();
            txtSSBetween.Text = stats.ssBetween.Value.ToString("N4");
            txtSSBetween.Margin = new Thickness(4, 0, 4, 0);
            txtSSBetween.HorizontalAlignment = System.Windows.HorizontalAlignment.Right;
            txtSSBetween.VerticalAlignment = System.Windows.VerticalAlignment.Center;
            grid1.Children.Add(txtSSBetween);
            Grid.SetRow(txtSSBetween, 1);
            Grid.SetColumn(txtSSBetween, 1);

            TextBlock txtSSWithin = new TextBlock();
            txtSSWithin.Text = stats.ssWithin.Value.ToString("N4");
            txtSSWithin.Margin = new Thickness(4, 0, 4, 0);
            txtSSWithin.HorizontalAlignment = System.Windows.HorizontalAlignment.Right;
            txtSSWithin.VerticalAlignment = System.Windows.VerticalAlignment.Center;
            grid1.Children.Add(txtSSWithin);
            Grid.SetRow(txtSSWithin, 2);
            Grid.SetColumn(txtSSWithin, 1);

            TextBlock txtSSTotal = new TextBlock();
            txtSSTotal.Text = (stats.ssWithin.Value + stats.ssBetween.Value).ToString("N4");
            txtSSTotal.Margin = new Thickness(4, 0, 4, 0);
            txtSSTotal.HorizontalAlignment = System.Windows.HorizontalAlignment.Right;
            txtSSTotal.VerticalAlignment = System.Windows.VerticalAlignment.Center;
            grid1.Children.Add(txtSSTotal);
            Grid.SetRow(txtSSTotal, 3);
            Grid.SetColumn(txtSSTotal, 1);

            TextBlock txtDFBetween = new TextBlock();
            txtDFBetween.Text = stats.dfBetween.Value.ToString();
            txtDFBetween.Margin = new Thickness(4, 0, 4, 0);
            txtDFBetween.HorizontalAlignment = System.Windows.HorizontalAlignment.Right;
            txtDFBetween.VerticalAlignment = System.Windows.VerticalAlignment.Center;
            grid1.Children.Add(txtDFBetween);
            Grid.SetRow(txtDFBetween, 1);
            Grid.SetColumn(txtDFBetween, 2);

            TextBlock txtDFWithin = new TextBlock();
            txtDFWithin.Text = stats.dfWithin.Value.ToString();
            txtDFWithin.Margin = new Thickness(4, 0, 4, 0);
            txtDFWithin.HorizontalAlignment = System.Windows.HorizontalAlignment.Right;
            txtDFWithin.VerticalAlignment = System.Windows.VerticalAlignment.Center;
            grid1.Children.Add(txtDFWithin);
            Grid.SetRow(txtDFWithin, 2);
            Grid.SetColumn(txtDFWithin, 2);

            TextBlock txtDFTotal = new TextBlock();
            txtDFTotal.Text = (stats.dfWithin.Value + stats.dfBetween.Value).ToString();
            txtDFTotal.Margin = new Thickness(4, 0, 4, 0);
            txtDFTotal.HorizontalAlignment = System.Windows.HorizontalAlignment.Right;
            txtDFTotal.VerticalAlignment = System.Windows.VerticalAlignment.Center;
            grid1.Children.Add(txtDFTotal);
            Grid.SetRow(txtDFTotal, 3);
            Grid.SetColumn(txtDFTotal, 2);

            TextBlock txtMSBetween = new TextBlock();
            txtMSBetween.Text = stats.msBetween.Value.ToString("N4");
            txtMSBetween.Margin = new Thickness(4, 0, 4, 0);
            txtMSBetween.HorizontalAlignment = System.Windows.HorizontalAlignment.Right;
            txtMSBetween.VerticalAlignment = System.Windows.VerticalAlignment.Center;
            grid1.Children.Add(txtMSBetween);
            Grid.SetRow(txtMSBetween, 1);
            Grid.SetColumn(txtMSBetween, 3);

            TextBlock txtMSWithin = new TextBlock();
            txtMSWithin.Text = stats.msWithin.Value.ToString("N4");
            txtMSWithin.Margin = new Thickness(4, 0, 4, 0);
            txtMSWithin.HorizontalAlignment = System.Windows.HorizontalAlignment.Right;
            txtMSWithin.VerticalAlignment = System.Windows.VerticalAlignment.Center;
            grid1.Children.Add(txtMSWithin);
            Grid.SetRow(txtMSWithin, 2);
            Grid.SetColumn(txtMSWithin, 3);

            TextBlock txtFStat = new TextBlock();
            txtFStat.Text = stats.fStatistic.Value.ToString("N4");
            txtFStat.Margin = new Thickness(4, 0, 4, 0);
            txtFStat.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
            txtFStat.VerticalAlignment = System.Windows.VerticalAlignment.Center;
            grid1.Children.Add(txtFStat);
            Grid.SetRow(txtFStat, 1);
            Grid.SetColumn(txtFStat, 4);

            int rdcount = 0;
            foreach (RowDefinition rd in grid1.RowDefinitions)
            {
                int cdcount = 0;
                foreach (ColumnDefinition cd in grid1.ColumnDefinitions)
                {
                    Border b = new Border();
                    b.Style = this.Resources["gridCellBorder"] as Style;

                    if (rdcount == 0)
                    {
                        b.BorderThickness = new Thickness(b.BorderThickness.Left, 1, b.BorderThickness.Right, b.BorderThickness.Bottom);
                    }
                    if (cdcount == 0)
                    {
                        b.BorderThickness = new Thickness(1, b.BorderThickness.Top, b.BorderThickness.Right, b.BorderThickness.Bottom);
                    }

                    Grid.SetRow(b, rdcount);
                    Grid.SetColumn(b, cdcount);
                    grid1.Children.Add(b);
                    cdcount++;
                }
                rdcount++;
            }

            #endregion // Grid1

            #region Grid2
            Grid grid2 = new Grid();
            grid2.SnapsToDevicePixels = true;
            grid2.Margin = new Thickness(5);
            grid2.HorizontalAlignment = HorizontalAlignment.Center;
            grid2.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(30) });
            grid2.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(110) });
            grid2.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(95) });

            pnl.Children.Add(grid2);

            for (int y = 0; y < grid2.RowDefinitions.Count; y++)
            {
                Rectangle rctHeader = new Rectangle();
                rctHeader.Style = this.Resources["gridHeaderCellRectangle"] as Style;
                Grid.SetRow(rctHeader, y);
                Grid.SetColumn(rctHeader, 0);
                grid2.Children.Add(rctHeader);
            }

            TextBlock lblPValue = new TextBlock();
            lblPValue.Text = SharedStrings.ANOVA_P_VAL;
            lblPValue.HorizontalAlignment = HorizontalAlignment.Center;
            lblPValue.VerticalAlignment = VerticalAlignment.Center;
            lblPValue.FontWeight = FontWeights.Bold;
            lblPValue.Foreground = Brushes.White;
            Grid.SetRow(lblPValue, 0);
            Grid.SetColumn(lblPValue, 0);
            grid2.Children.Add(lblPValue);

            TextBlock txtPValue = new TextBlock();
            txtPValue.Text = stats.anovaPValue.Value.ToString("N4");
            txtPValue.HorizontalAlignment = HorizontalAlignment.Center;
            txtPValue.VerticalAlignment = VerticalAlignment.Center;
            Grid.SetRow(txtPValue, 0);
            Grid.SetColumn(txtPValue, 1);
            grid2.Children.Add(txtPValue);

            rdcount = 0;
            foreach (RowDefinition rd in grid2.RowDefinitions)
            {
                int cdcount = 0;
                foreach (ColumnDefinition cd in grid2.ColumnDefinitions)
                {
                    Border b = new Border();
                    b.Style = this.Resources["gridCellBorder"] as Style;

                    if (rdcount == 0)
                    {
                        b.BorderThickness = new Thickness(b.BorderThickness.Left, 1, b.BorderThickness.Right, b.BorderThickness.Bottom);
                    }
                    if (cdcount == 0)
                    {
                        b.BorderThickness = new Thickness(1, b.BorderThickness.Top, b.BorderThickness.Right, b.BorderThickness.Bottom);
                    }

                    Grid.SetRow(b, rdcount);
                    Grid.SetColumn(b, cdcount);
                    grid2.Children.Add(b);
                    cdcount++;
                }
                rdcount++;
            }
            #endregion // Grid2

            #region Grid3
            TextBlock txt3 = new TextBlock();
            txt3.Text = SharedStrings.ANOVA_BARTLETT;
            txt3.HorizontalAlignment = HorizontalAlignment.Center;
            txt3.Margin = new Thickness(5);
            txt3.FontWeight = FontWeights.Bold;
            pnl.Children.Add(txt3);

            Grid grid3 = new Grid();
            grid3.SnapsToDevicePixels = true;
            grid3.Margin = new Thickness(5);
            grid3.HorizontalAlignment = HorizontalAlignment.Center;
            grid3.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(30) });
            grid3.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(30) });
            grid3.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(30) });
            grid3.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(110) });
            grid3.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(95) });

            pnl.Children.Add(grid3);

            for (int y = 0; y < grid3.RowDefinitions.Count; y++)
            {
                Rectangle rctHeader = new Rectangle();
                rctHeader.Style = this.Resources["gridHeaderCellRectangle"] as Style;
                Grid.SetRow(rctHeader, y);
                Grid.SetColumn(rctHeader, 0);
                grid3.Children.Add(rctHeader);
            }

            TextBlock lblBartlettChi = new TextBlock();
            lblBartlettChi.Text = SharedStrings.ANOVA_CHI;
            lblBartlettChi.HorizontalAlignment = HorizontalAlignment.Center;
            lblBartlettChi.VerticalAlignment = VerticalAlignment.Center;
            lblBartlettChi.FontWeight = FontWeights.Bold;
            lblBartlettChi.Foreground = Brushes.White;
            Grid.SetRow(lblBartlettChi, 0);
            Grid.SetColumn(lblBartlettChi, 0);
            grid3.Children.Add(lblBartlettChi);

            TextBlock lblBartlettDf = new TextBlock();
            lblBartlettDf.Text = SharedStrings.ANOVA_DF_LONG;
            lblBartlettDf.HorizontalAlignment = HorizontalAlignment.Center;
            lblBartlettDf.VerticalAlignment = VerticalAlignment.Center;
            lblBartlettDf.FontWeight = FontWeights.Bold;
            lblBartlettDf.Foreground = Brushes.White;
            Grid.SetRow(lblBartlettDf, 1);
            Grid.SetColumn(lblBartlettDf, 0);
            grid3.Children.Add(lblBartlettDf);

            TextBlock lblBartlettP = new TextBlock();
            lblBartlettP.Text = SharedStrings.ANOVA_P_VAL;
            lblBartlettP.HorizontalAlignment = HorizontalAlignment.Center;
            lblBartlettP.VerticalAlignment = VerticalAlignment.Center;
            lblBartlettP.FontWeight = FontWeights.Bold;
            lblBartlettP.Foreground = Brushes.White;
            Grid.SetRow(lblBartlettP, 2);
            Grid.SetColumn(lblBartlettP, 0);
            grid3.Children.Add(lblBartlettP);

            TextBlock txtBartlettChi = new TextBlock();
            txtBartlettChi.Text = stats.chiSquare.Value.ToString("N4");
            txtBartlettChi.HorizontalAlignment = HorizontalAlignment.Center;
            txtBartlettChi.VerticalAlignment = VerticalAlignment.Center;
            Grid.SetRow(txtBartlettChi, 0);
            Grid.SetColumn(txtBartlettChi, 1);
            grid3.Children.Add(txtBartlettChi);

            TextBlock txtBartlettDf = new TextBlock();
            txtBartlettDf.Text = stats.dfBetween.Value.ToString();
            txtBartlettDf.HorizontalAlignment = HorizontalAlignment.Center;
            txtBartlettDf.VerticalAlignment = VerticalAlignment.Center;
            Grid.SetRow(txtBartlettDf, 1);
            Grid.SetColumn(txtBartlettDf, 1);
            grid3.Children.Add(txtBartlettDf);

            TextBlock txtBartlettP = new TextBlock();
            txtBartlettP.Text = stats.bartlettPValue.Value.ToString("N4");
            txtBartlettP.HorizontalAlignment = HorizontalAlignment.Center;
            txtBartlettP.VerticalAlignment = VerticalAlignment.Center;
            Grid.SetRow(txtBartlettP, 2);
            Grid.SetColumn(txtBartlettP, 1);
            grid3.Children.Add(txtBartlettP);

            rdcount = 0;
            foreach (RowDefinition rd in grid3.RowDefinitions)
            {
                int cdcount = 0;
                foreach (ColumnDefinition cd in grid3.ColumnDefinitions)
                {
                    Border b = new Border();
                    b.Style = this.Resources["gridCellBorder"] as Style;

                    if (rdcount == 0)
                    {
                        b.BorderThickness = new Thickness(b.BorderThickness.Left, 1, b.BorderThickness.Right, b.BorderThickness.Bottom);
                    }
                    if (cdcount == 0)
                    {
                        b.BorderThickness = new Thickness(1, b.BorderThickness.Top, b.BorderThickness.Right, b.BorderThickness.Bottom);
                    }

                    Grid.SetRow(b, rdcount);
                    Grid.SetColumn(b, cdcount);
                    grid3.Children.Add(b);
                    cdcount++;
                }
                rdcount++;
            }

            TextBlock txt4 = new TextBlock();
            txt4.Text = SharedStrings.ANOVA_SMALL_P;
            txt4.HorizontalAlignment = HorizontalAlignment.Center;
            txt4.Margin = new Thickness(5);
            pnl.Children.Add(txt4);

            TextBlock txt5 = new TextBlock();
            txt5.Text = SharedStrings.ANOVA_MWWTST;
            txt5.HorizontalAlignment = HorizontalAlignment.Center;
            txt5.Margin = new Thickness(5);
            txt5.FontWeight = FontWeights.Bold;
            pnl.Children.Add(txt5);

            #endregion // Grid3

            #region Grid4
            Grid grid4 = new Grid();
            grid4.SnapsToDevicePixels = true;
            grid4.Margin = new Thickness(5);
            grid4.HorizontalAlignment = HorizontalAlignment.Center;
            grid4.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(30) });
            grid4.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(30) });
            grid4.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(30) });
            grid4.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(110) });
            grid4.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(95) });

            pnl.Children.Add(grid4);

            for (int y = 0; y < grid4.RowDefinitions.Count; y++)
            {
                Rectangle rctHeader = new Rectangle();
                rctHeader.Style = this.Resources["gridHeaderCellRectangle"] as Style;
                Grid.SetRow(rctHeader, y);
                Grid.SetColumn(rctHeader, 0);
                grid4.Children.Add(rctHeader);
            }

            TextBlock lblKWChi = new TextBlock();
            lblKWChi.Text = SharedStrings.ANOVA_KWH;
            lblKWChi.HorizontalAlignment = HorizontalAlignment.Center;
            lblKWChi.VerticalAlignment = VerticalAlignment.Center;
            lblKWChi.FontWeight = FontWeights.Bold;
            lblKWChi.Foreground = Brushes.White;
            Grid.SetRow(lblKWChi, 0);
            Grid.SetColumn(lblKWChi, 0);
            grid4.Children.Add(lblKWChi);

            TextBlock lblKWDf = new TextBlock();
            lblKWDf.Text = SharedStrings.ANOVA_DF_LONG;
            lblKWDf.HorizontalAlignment = HorizontalAlignment.Center;
            lblKWDf.VerticalAlignment = VerticalAlignment.Center;
            lblKWDf.FontWeight = FontWeights.Bold;
            lblKWDf.Foreground = Brushes.White;
            Grid.SetRow(lblKWDf, 1);
            Grid.SetColumn(lblKWDf, 0);
            grid4.Children.Add(lblKWDf);

            TextBlock lblKWP = new TextBlock();
            lblKWP.Text = SharedStrings.ANOVA_P_VAL;
            lblKWP.HorizontalAlignment = HorizontalAlignment.Center;
            lblKWP.VerticalAlignment = VerticalAlignment.Center;
            lblKWP.FontWeight = FontWeights.Bold;
            lblKWP.Foreground = Brushes.White;
            Grid.SetRow(lblKWP, 2);
            Grid.SetColumn(lblKWP, 0);
            grid4.Children.Add(lblKWP);

            TextBlock txtKWChi = new TextBlock();
            txtKWChi.Text = stats.kruskalWallisH.Value.ToString("N4");
            txtKWChi.HorizontalAlignment = HorizontalAlignment.Center;
            txtKWChi.VerticalAlignment = VerticalAlignment.Center;
            Grid.SetRow(txtKWChi, 0);
            Grid.SetColumn(txtKWChi, 1);
            grid4.Children.Add(txtKWChi);

            TextBlock txtWKDf = new TextBlock();
            txtWKDf.Text = stats.dfBetween.Value.ToString();
            txtWKDf.HorizontalAlignment = HorizontalAlignment.Center;
            txtWKDf.VerticalAlignment = VerticalAlignment.Center;
            Grid.SetRow(txtWKDf, 1);
            Grid.SetColumn(txtWKDf, 1);
            grid4.Children.Add(txtWKDf);

            TextBlock txtKWP = new TextBlock();
            txtKWP.Text = stats.kruskalPValue.Value.ToString("N4");
            txtKWP.HorizontalAlignment = HorizontalAlignment.Center;
            txtKWP.VerticalAlignment = VerticalAlignment.Center;
            Grid.SetRow(txtKWP, 2);
            Grid.SetColumn(txtKWP, 1);
            grid4.Children.Add(txtKWP);

            rdcount = 0;
            foreach (RowDefinition rd in grid4.RowDefinitions)
            {
                int cdcount = 0;
                foreach (ColumnDefinition cd in grid4.ColumnDefinitions)
                {
                    Border b = new Border();
                    b.Style = this.Resources["gridCellBorder"] as Style;

                    if (rdcount == 0)
                    {
                        b.BorderThickness = new Thickness(b.BorderThickness.Left, 1, b.BorderThickness.Right, b.BorderThickness.Bottom);
                    }
                    if (cdcount == 0)
                    {
                        b.BorderThickness = new Thickness(1, b.BorderThickness.Top, b.BorderThickness.Right, b.BorderThickness.Bottom);
                    }

                    Grid.SetRow(b, rdcount);
                    Grid.SetColumn(b, cdcount);
                    grid4.Children.Add(b);
                    cdcount++;
                }
                rdcount++;
            }

            #endregion // Grid4

            //panelMain.Children.Add(pnl);
        }