Statsar Statistics Library

v1.0.1 for .NET

Product Guide



More Information...

Valid XHTML


One Sample T-Test Demo Example (VB.NET)

[VB.NET]
' COPYRIGHT(C), SIMPLEXAR SOFTWARE LIMITED, 2006-2008.
' All rights reserved.
'
' Use of this copyright notice is precautionary only, and does not imply
' publication or disclosure. The content of this work contains confidential
' and proprietary information of Simplexar Software Limited. Any duplication,
' modification, distribution, or disclosure in any form, in whole, or in part,
' is strictly prohibited without express prior written permission.

' Get namespaces.
Imports System
Imports Simplexar.Statsar
Imports Simplexar.Statsar.HypothesisTests

' Start namespace.
Namespace Simplexar.Examples.Statsar

    ' This example shows how to perform a statistical hypothesis test
    ' by using the one sample T-test class. This tests if a sample
    ' comes from a particular population, by comparing means.
    Module Example

        ' The application entry point.
        Public Sub Main()
            Try
                RunExample()
            Catch exception As Exception
                Console.WriteLine(exception)
            End Try
            Console.WriteLine("Press ENTER to terminate.")
            Console.ReadLine()
        End Sub

        Private Sub RunExample()

            ' Define test parameters.
            Dim xbar As Double = 5 ' The sample mean.
            Dim sampleStandardDeviation As Double = 1.5
            Dim n As Integer = 53  ' The sample size.
            Dim populationMean As Double = 5.4
            Dim alpha As Double = 0.05

            ' Create a new one sample T-test. In this example
            ' we create the test using explict test parameters.
            ' A second constructor is also provided which
            ' constructs a test from sample data.
            Dim test As New OneSampleTTest( _
                xbar, sampleStandardDeviation, n, _
                populationMean, alpha, HypothesisType.TwoSided)

            ' Display test statistics.
            Console.WriteLine( _
                "P-value: {0}", test.P)

            Console.WriteLine( _
                "Reject: {0}", test.Reject)

            Console.WriteLine( _
                "Statistic: {0}", test.Statistic)

            Console.WriteLine( _
                "Left critical value: {0}", test.LeftCriticalValue)

            Console.WriteLine( _
                "Right critical value: {0}", test.RightCriticalValue)

            Console.WriteLine( _
                "Left probability: {0}", test.LeftProbability)

            Console.WriteLine( _
                "Right probability: {0}", test.RightProbability)

            Console.WriteLine( _
                "Lower confidence limit: {0}", test.LowerConfidenceLimit)

            Console.WriteLine( _
                "Upper confidence limit: {0}", test.UpperConfidenceLimit)

            Console.WriteLine( _
                "Standard error of the mean: {0}", test.SEM)

            Console.WriteLine( _
                "Distribution degrees of freedom: {0}", test.DegreesOfFreedom)

        End Sub

    End Module

End Namespace