Click or drag to resize

Z-Test

One sample z-test of the null hypothesis that data in the sample are a random sample from a normal distribution with specified supposed mean and standard deviation, against the alternative that the mean is different.

This topic contains the following sections:

Z-Test Specification

For one sample z-test we consider the time series HT Time Series

Test statistic is calculated as follows:

HT ZTest Stat

where standard error SE:

HT ZTestSE

Default supposed values of mean and variance are 0 and 1 correspondingly.

Implementation

The following constructors create an instance of ZTest class.

Constructor

Description

Performance

two-tailed test, default significance level

Constructor without parameters. Creates ZTest instance with default significance level for two-tailed test.

methodZTest

default significance level

Creates ZTest instance with default significance level and user defined tail.

methodZTest(Tail)

two-tailed test, user defined significance level

Creates ZTest instance for two-tailed test and user-defined significance level.

methodZTest(Double)

user defined tail and significance level

Creates ZTest instance with user defined significance level and tail.

methodZTest(Double, Tail)

The class provides the following methods:

Method

Description

Performance

update

Update sample by double array part, user specifies offset and number of the elements to use:

methodUpdate(Double, Int32, Int32)

update mean and variance

Updates test statistic using provided sample and supposition about mean and variance.

Double array sample:

methodUpdate(Double, Double, Double)

Vector sample:

methodUpdate(Vector, Double, Double)

The class provides the following properties:

Property

Description

Performance

region of acceptance

We fail to reject null hypothesis if test statistics is between left and right borders of region of acceptance.

Region of acceptance left border:

PropertyAcceptanceRegionLeft

Region of acceptance right border:

PropertyAcceptanceRegionRight

p-value

The probability of obtaining a test statistic at least as extreme as the one that was actually observed, assuming that the null hypothesis is true.

PropertyPValue

Code Sample

The example of ZTest class usage:

C#
 1using System;
 2using FinMath.LinearAlgebra;
 3using FinMath.Statistics.HypothesisTesting;
 4using FinMath.Statistics.Distributions;
 5
 6namespace FinMath.Samples
 7{
 8    class ZTestSample
 9    {
10        static void Main()
11        {
12            // Create an instance of normal distribution.
13            Normal distr = new Normal(3, 1);
14
15            // Generate random sample from normal distribution.
16            Vector series = Vector.Random(100, distr);
17
18            // Create an instance of ZTest.
19            ZTest test = new ZTest(0.05, Tail.Both);
20            test.Update(series, 3, 1);
21
22            Console.WriteLine("Test Result:");
23            // Test decision
24            Console.WriteLine($"  The null hypothesis failed to be rejected: {test.Decision}");
25            // The statistic of ZTest test.
26            Console.WriteLine($"  Statistics = {test.Statistics:0.000}");
27            // The p-value of the test statistic.
28            Console.WriteLine($"  P-Value = {test.PValue:0.000}");
29        }
30    }
31}

See Also