One Sample Z-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 one sample Z-test class. This tests if a sample
/// comes from a particular population, by comparing means.
/// </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 = 15; // The sample mean.
int n = 25; // The sample size.
double populationStandardDeviation = 2.5;
double populationMean = 16;
double alpha = 0.05;
// Create a new one sample Z-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.
OneSampleZTest test = new OneSampleZTest(
xbar, n, populationStandardDeviation,
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);
}
}
}