NMath User's Guide

TOC | Previous | Next | Index

45.3 Shapiro-Wilk Test (.NET, C#, CSharp, VB, Visual Basic, F#)

Class ShapiroWilkTest tests the null hypothesis that a sample comes from a normally distributed population. The sample data provided must be of size between 3 and 5000. If the size becomes too large, then the test begins to perform poorly.

Code Example – C# Shapiro-Wilk test

var data = new DoubleVector(
  "4.6057571 5.0352571 2.5780990 3.8300667 3.9096730 0.3203129 " +
  "0.7165054 9.8681061 3.8967762 9.4639023 6.4092569 2.9835816 " +
  "8.1763496 8.5650066 10.2810477 7.7123572 2.6411587 2.5043797 " +
  "7.5617508 11.2223571" );



double alpha = 0.1;
var test = new ShapiroWilkTest( data, alpha );

Code Example – VB Shapiro-Wilk test

Dim Data As New DoubleVector(
  "4.6057571 5.0352571 2.5780990 3.8300667 3.9096730 0.3203129 " &
  "0.7165054 9.8681061 3.8967762 9.4639023 6.4092569 2.9835816 " &
  "8.1763496 8.5650066 10.2810477 7.7123572 2.6411587 2.5043797 " &
  "7.5617508 11.2223571")



Dim Alpha As Double = 0.1
Dim Test As New ShapiroWilkTest(Data, Alpha)

Once you've constructed and configured a TwoSampleKSTest object, you can access the various test results using the provided properties:

Code Example – C# Shapiro-Wilk test

Console.WriteLine( "statistic = " + test.Statistic );
Console.WriteLine( "p-value = " + test.P );
Console.WriteLine( "alpha = " + test.Alpha );
Console.WriteLine( "reject the null hypothesis? " + test.Reject);

Code Example – VB Shapiro-Wilk test

Console.WriteLine("statistic = " & Test.Statistic)
Console.WriteLine("p-value = " & Test.P)
Console.WriteLine("alpha = " & Test.Alpha)
Console.WriteLine("reject the null hypothesis? " & Test.Reject)

Top

Top