Two Sample Paired T-Test Demo Example (C#)
[C#]
/* 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.
using System;
using Simplexar.Statsar;
using Simplexar.Statsar.HypothesisTests;
// Start namespace.
namespace Simplexar.Examples.Statsar
{
/// <summary>
/// This example shows how to perform a statistical hypothesis test
/// by using the two sample paired T-test class. This tests if the
/// mean of the paired differences of two samples is 0.
/// </summary>
public static class Example
{
/// <summary>
/// The application entry point.
/// </summary>
public static void Main()
{
try
{
RunExample();
}
catch(Exception exception)
{
Console.WriteLine(exception);
}
Console.WriteLine("Press ENTER to terminate.");
Console.ReadLine();
}
private static void RunExample()
{
// Define test parameters.
double xbar = 0.18; // The mean of the differences.
double pairedStandardDeviation = 0.79;
int n = 45; // The sample size.
double alpha = 0.05;
// Create a new two sample paired 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.
TwoSamplePairedTTest test = new TwoSamplePairedTTest(
xbar, pairedStandardDeviation, n, 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);
}
}
}