Home
Products
Support
Blog
Resources
Company
NMath Stats User's Guide
TOC |  Previous |  Next |  Index

6.1 Common Interface

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.

Static Properties

All hypothesis test classes have static DefaultAlpha properties that get and set the default alpha level associated with tests of that type. The default value is 0.01. For instance:

OneSampleTTest test1 = new OneSampleTTest();
// test1.Alpha == 0.01
OneSampleTTest.DefaultAlpha = 0.05;
OneSampleTTest test2 = new OneSampleTTest();
// test2.Alpha == 0.05

Similarly, all hypothesis test classes have static DefaultType properties that get and set the default form of the alternative hypothesis. The form is specified using the HypothesisType enumeration, with the following enumerated values:

The default value for all test classes is HypothesisType.TwoSided. For example:

OneSampleTTest test1 = new OneSampleTTest();
// test1.Type == HypothesisType.TwoSided
OneSampleTTest.DefaultType = HypothesisType.Left;
OneSampleTTest test2 = new OneSampleTTest();
// test2.Type == HypothesisType.Left

Creating Hypothesis Test Objects

All hypothesis test classes provide two paths for constructing instances of that type:

NOTE- In the data-based method, once sample parameters have been computed from the given data, the data is discarded, and cannot be recovered from the test object.

For example, a one-sample z-test compares a single sample mean to an expected mean from a normal distribution with known standard deviation. This code constructs a OneSampleZTest object by explicitly specifying a sample mean, sample size, population mean, and population standard deviation:

double xbar = 112.8;
int n = 9;
double mu0 = 100;
double sigma = 15;
OneSampleZTest test = new OneSampleZTest( xbar, n, mu0, sigma );

This code constructs a OneSampleZTest object by supplying a vector of sample data, and the necessary population parameters:

DoubleVector data =
  new DoubleVector( "[ 116 110 111 113 112 113 111 109 121 ]" );
double mu0 = 100;
double sigma = 15;
OneSampleZTest test = new OneSampleZTest( data, mu0, sigma );

In this case, the sample mean and sample size are calculated from the given data. The data-based method supports sample data in vectors, arrays, and data frame columns.

In both the parameter-based method and the data-based method, the alpha level for the hypothesis test is set to the current value specified by the static DefaultAlpha property, and the form of the hypothesis test is set to the current DefaultType, as described above.

Constructors are also provided for all test classes that enable you to set the alpha level and hypothesis type to non-default values. For example:

OneSampleZTest test = new OneSampleZTest( data, mu0, sigma, 0.05, 
  HypothesisType.Left );

Properties of Hypothesis Test Objects

All hypothesis test classes provide the following read-only properties:

The following read-write properties are also provided:

Additionally, each hypothesis test provides properties for accessing the specific sample and population parameters that define the test. For example, a OneSampleZTest has additional properties for accessing the sample mean, Xbar, the sample size, N, the population mean, Mu0, and the population standard deviation, Sigma.

Modifying Hypothesis Test Objects

All hypothesis test classes provide Update() methods for modifying a test with new sample parameters or sample data, and new population parameters. For example, if test is a TwoSampleFTest instance, this code updates the test with two new samples, taken from two columns in a data frame df:

test.Update( df[3], df[7]  );

Printing Results

All hypothesis test classes provide a ToString() method that returns a formatted string representation of the test results. For instance:

DoubleVector data1 = new DoubleVector( "9.21 11.51 12.79 11.85 9.97 
  8.79 9.69 9.68 9.19" );
DoubleVector data2 = new DoubleVector( "7.53 7.48 8.08 8.09 10.15 
  8.40 10.88 6.13 7.90 7.05 7.48 7.58 8.11" );
TwoSampleFTest test = new TwoSampleFTest( data1, data2, 0.05, 
  HypothesisType.TwoSided );
Console.WriteLine( test.ToString() );

The output is:

Two Sample F Test
-----------------

Sample Sizes = 9 and 13
Standard Deviations = 1.39787139767736 and 1.23808008936914
Variances = 1.95404444444444 and 1.53284230769231
Ratio of Variances = 1.27478504125206
Computed F statistic: 1.27478504125206, num df = 8, denom df = 12

Hypothesis type: two-sided
Null hypothesis: true ratio of variances = 1
Alt hypothesis: true ratio of variances != 1
P-value: 0.679745985376403
RETAIN the null hypothesis for alpha = 0.05
0.95 confidence interval: 0.363002872041806 5.3536732579205

TOC |  Previous |  Next |  Index

Copyright © 2008 CenterSpace Software, LLC. All rights reserved.
All trademarks and registered trademarks mentioned on this web site are the property of their respective owners.
Contact Webmaster