# VB Hypothesis Test Example

← All NMath Stats Code Examples

```Imports System
Imports System.Collections

Imports CenterSpace.NMath.Core
Imports CenterSpace.NMath.Stats

Namespace CenterSpace.NMath.Stats.Examples.VisualBasic

' A .NET example in Visual Basic showing how to use the hypothesis test classes to test statistical
' hypotheses.

' Hypothesis tests use statistics to determine the probability that a
' given hypothesis is true. For example, could the differences between two
' sample means be explained away as sampling error? NMath Stats provides
' classes for many common hypothesis tests, such as the z-test, t-test,
' F-test, and Kolmogorov-Smirnov test, with calculation of p-values,
' critical values, and confidence intervals. All hypothesis test classes
' share substantially the same interface. Once you learn how to use one
' test, it’s easy to use any of the others.

Module HypothesisTestExample

Sub Main()

' Suppose we measure the thickness of plaque (mm) in the carotid
' artery of 10 randomly selected patients with mild artherosclerotic
' disease. Two measurements are taken: before treatment with
' Vitamin E (baseline), and after two years of taking Vitamin E daily.
Dim DF As DataFrame = New DataFrame()
Dim Col1 As DFNumericColumn = New DFNumericColumn("Baseline")
Col1.NumericFormat = "F7"
Dim Col2 As DFNumericColumn = New DFNumericColumn("Vit E")
Col2.NumericFormat = "F7"

' Display the data
Console.WriteLine()
Console.WriteLine(DF)
Console.WriteLine()

' Construct a TwoSamplePairedTTest from the two columns of data.
Dim Test As TwoSamplePairedTTest = New TwoSamplePairedTTest(DF("Baseline"), DF("Vit E"))

' Display the results
Console.WriteLine(Test)
Console.WriteLine()

' Change test type and alpha level, and display new results.
Test.Type = HypothesisType.Right
Test.Alpha = 0.05
Console.WriteLine(Test)
Console.WriteLine()

' Modify the data.
DF(5, 1) = 0.56
Console.WriteLine(DF)
Console.WriteLine()

' Update the test, and display new results.
Test.Update(DF("Baseline"), DF("Vit E"))
Test.Type = HypothesisType.TwoSided
Console.WriteLine(Test)
Console.WriteLine()

Console.WriteLine("Properties")
Console.WriteLine("number of pairs = " & Test.N)
Console.WriteLine("mean difference between pairs = " & Test.Xbar)
Console.WriteLine("standard deviation of differences between pairs = " & Test.S)
Console.WriteLine("deg of freedom = " & Test.DegreesOfFreedom)
Console.WriteLine("t-statistic = " & Test.Statistic)
Console.WriteLine("test type = " & Test.Type)
Console.WriteLine("alpha level = " & Test.Alpha)
Console.WriteLine("p-value = " & Test.P)
Console.WriteLine("critical values: " & Test.LeftCriticalValue & " " & Test.RightCriticalValue)
Console.WriteLine("reject the null hypothesis? " & Test.Reject)
Console.WriteLine("confidence interval: " & Test.LowerConfidenceLimit & " " & Test.UpperConfidenceLimit)

Console.WriteLine()
Console.WriteLine("Press Enter Key")