C# One Way Anova Example

[TOC]

using System;
using System.Windows.Forms;
using System.Data;
using System.Globalization;

using CenterSpace.NMath.Core;
using CenterSpace.NMath.Stats;

namespace CenterSpace.NMath.Stats.Examples.CSharp
{
  /// <summary>
  /// A .NET example in C# showing how use class OneWayAnova to perform a simple one-way
  /// ANOVA and display the results.
  /// </summary>
  class OneWayAnovaDisplayExample : Form
  {
    private System.Windows.Forms.Label label1;
    private System.Windows.Forms.DataGrid dataGrid1;

    static void Main(string[] args)
    {
      Application.Run(new OneWayAnovaDisplayExample());
    }

    #region Windows Form Designer generated code

    private void InitializeComponent()
    {
      this.dataGrid1 = new System.Windows.Forms.DataGrid();
      this.label1 = new System.Windows.Forms.Label();
      ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
      this.SuspendLayout();
      // 
      // dataGrid1
      // 
      this.dataGrid1.BackgroundColor = System.Drawing.Color.White;
      this.dataGrid1.CaptionVisible = false;
      this.dataGrid1.DataMember = "";
      this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
      this.dataGrid1.Location = new System.Drawing.Point(24, 64);
      this.dataGrid1.Name = "dataGrid1";
      this.dataGrid1.PreferredColumnWidth = 110;
      this.dataGrid1.ReadOnly = true;
      this.dataGrid1.RowHeadersVisible = false;
      this.dataGrid1.Size = new System.Drawing.Size(664, 80);
      this.dataGrid1.TabIndex = 0;
      // 
      // label1
      // 
      this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
      this.label1.Location = new System.Drawing.Point(184, 24);
      this.label1.Name = "label1";
      this.label1.Size = new System.Drawing.Size(280, 32);
      this.label1.TabIndex = 1;
      this.label1.Text = "One Way Anova Example";
      // 
      // OneWayAnovaDisplayExample
      // 
      this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
      this.ClientSize = new System.Drawing.Size(714, 168);
      this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                  this.label1,
                                                                  this.dataGrid1});
      this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
      this.Name = "OneWayAnovaDisplayExample";
      this.Text = "One Way Anova Example";
      ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
      this.ResumeLayout(false);

    }

    #endregion

    public OneWayAnovaDisplayExample()
    {
      InitializeComponent();

      // Create the data to analyze. Class OneWayAnova will accept data in
      // several formats. The one below uses an array of DoubleVectors. Each
      // vector in the array contains the data for a group.
      DoubleVector[] table = new DoubleVector[5];

      table[0] = new DoubleVector("[24 15 21 27 33 23]");
      table[1] = new DoubleVector("[14 7 12 17 14 16]");
      table[2] = new DoubleVector("[11 9 7 13 12 18]");
      table[3] = new DoubleVector("[7 7 4 7 12 18]");
      table[4] = new DoubleVector("[19 24 19 15 10 20]");

      // Create the one-way ANOVA
      OneWayAnova owa = new OneWayAnova(table);

      // The AnovaTable property is a DataFrame instance that contains
      // a traditional ANOVA table. Use the ToDataTable() method of
      // the DataFrame to create a ADO DataTable.
      DataTable dt = owa.AnovaTable.ToDataTable();

      // Set the grids DataSource property to the DataTable just created.
      this.dataGrid1.DataSource = dt;

    }  // Main

  }  // class

}  // namespace


[TOC]