Imports System Imports System.Collections Imports Microsoft.VisualBasic Imports CenterSpace.NMath.Core Namespace CenterSpace.NMath.Examples.VisualBasic A .NET example in Visual Basic showing two-way ranova two. Public Class Form1 Inherits System.Windows.Forms.Form #Region " Windows Form Designer generated code " Public Sub New() MyBase.New() This call is required by the Windows Form Designer. InitializeComponent() Add any initialization after the InitializeComponent() call Read in data from a file. The file contains data for the following study*: A researcher was interested in whether frequency of exposure to a picture of an ugly or attractive person would influence ones liking for the photograph. In order to find out the researcher, at the start of each class he taught, pinned a large photograph of an ugly and attractive person in front of the class. At the end of the class period the students in the class were asked to rate on a 7 point liking scale the extent to which they found the persons depicted in the photos to be likeable on a scale similar to the one below. unlikeable -3 -2 -1 0 1 2 3 likeable The psychologist posted the pictures at the start of each class period and had the students rate their liking for the two pictures at the end of the lst class, again after 5 classes and finally again after 10 classes. Thus each student gave 3 ratings for each of the two photographs (after 1 exposure, 5 exposures and 10 exposures). Dim AnovaData As DataFrame = DataFrame.Load("TwoWayRanovaTwoExample.dat", True, False, " ", True) Class TwoWayRanovaTwo performs a balanced two-way analysis of variance with repeated measures on both factors. Multiple linear regression is used to compute the RANOVA values. The constructor takes a DataFrame containing the data, the column indices of the two factors, and the column index of the data: Dim Anova As TwoWayRanovaTwo = New TwoWayRanovaTwo(AnovaData, 1, 2, 0) This example simply displays a traditional ANOVA table in a System.Windows.Forms.DataGrid object. The next few lines of code format the table contents. First retrieve the table to display. Class TwoWayRanovaTwoTable is a subclass of DataFrame. Dim AnovaTable As TwoWayRanovaTwoTable = Anova.RanovaTable Next, lets set the precision to three decimal places. Note that this does not actually change the numbers in the ANOVA table. It just determines how many decimal places are displayed when the table is converted to a string. Dim I As Integer For I = 1 To (AnovaTable.Cols - 1) CType(AnovaTable(I), DFNumericColumn).NumericFormat = "F3" Next Next convert the RANOVA table into a string. This has the effect of formatting all the numbers so that they have three digits after the decimal point and all Double.NaN values are represented as a ".". (Some rows in the ANOVA table that do not have F statistic values or F statistic p-values associated with them. The cells that correspond to these rows and the F and P columns contain Double.NaN values.) Dim DisplayFrame As New DataFrame(AnovaTable.ToString(), True, True, ControlChars.Tab, False) Now display the RANOVA table in the DataGrid. DataGrid1.DataSource = DisplayFrame.ToDataTable() Results of the analysis indicated a main effect for the photo attractiveness, F = 147.00, p = 0.001 <= 0.05, with the attractive photo liked more than the ugly photo. There was no main effect for the frequency of exposure to the photo, F = .60, p = 0.579 > 0.05. There was a significant attractiveness of photo by frequency of exposure interaction, F = 18.00, p = 0.003 <= 0.05. End Sub Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub Required by the Windows Form Designer Private components As System.ComponentModel.IContainer NOTE: The following procedure is required by the Windows Form Designer It can be modified using the Windows Form Designer. Do not modify it using the code editor. Friend WithEvents DataGrid1 As System.Windows.Forms.DataGrid Friend WithEvents Label1 As System.Windows.Forms.Label <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() Me.DataGrid1 = New System.Windows.Forms.DataGrid() Me.Label1 = New System.Windows.Forms.Label() CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).BeginInit() Me.SuspendLayout() DataGrid1 Me.DataGrid1.AllowSorting = False Me.DataGrid1.BackgroundColor = System.Drawing.Color.White Me.DataGrid1.CaptionVisible = False Me.DataGrid1.DataMember = "" Me.DataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText Me.DataGrid1.Location = New System.Drawing.Point(24, 112) Me.DataGrid1.Name = "DataGrid1" Me.DataGrid1.PreferredColumnWidth = 110 Me.DataGrid1.ReadOnly = True Me.DataGrid1.RowHeadersVisible = False Me.DataGrid1.Size = New System.Drawing.Size(664, 152) Me.DataGrid1.TabIndex = 0 Label1 Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label1.Location = New System.Drawing.Point(144, 24) Me.Label1.Name = "Label1" Me.Label1.Size = New System.Drawing.Size(336, 64) Me.Label1.TabIndex = 1 Me.Label1.Text = "Two Way Anova Example With Repeated Measures On Both Factors" Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter Form1 Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(706, 288) Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Label1, Me.DataGrid1}) Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle Me.Name = "Form1" Me.Text = "Two Way Anova Example" CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).EndInit() Me.ResumeLayout(False) End Sub #End Region End Class End Namespace← All NMath Code Examples