Click or drag to resize

Wald Wolfowitz Test

The Wald Wolfowitz Test runs test of the null hypothesis that data in the sample are independent and identically distributed concerning being above/below specified value.

This topic contains the following sections:

Wald Wolfowitz Test Specification

For one sample Wald Wolfowitz test we consider the time series HT Time Series

Wald Wolfowitz test is used to test the randomness of a distribution, by taking the data in the given order and marking with + the data greater than the specified value called border (median by default), and with – the data less than the border.

A "run" of a sequence is a maximal non-empty segment of the sequence consisting of adjacent equally marked elements. For example, the sequence "++++−−−+++−−++++++−−−−" consists of six runs, three of which consist of +'s and the others of −'s.

Under the null hypothesis, the number of runs in a sequence of length N is a random variable whose conditional distribution given the observation of n+ positive values and n- negative values (n = n+ + n-) is approximately normal, with:

  • mean HT WWMean

  • variance HT WWVariance

These parameters do not depend on the "fairness" of the process generating the elements of the sequence. Only on the assumption that the elements are independent and identically distributed. If the number of runs is significantly higher or lower than expected, the hypothesis of statistical independence of the elements may be rejected.

  • Tail.Both. In the alternative hypothesis data are not independent or not identically distributed.

  • Tail.Left. In the alternative hypothesis there are too few groups of identical signs to be arbitrary by chance (signs tend to cluster).

  • Tail.Right. In the alternative hypothesis there are too many groups of identical signs to be arbitrary by chance (signs tend to mix).

Note Note

Decision based on P-value and significance level comparison is more exact.

Test statistic is calculated as follows:

HT WWTest Stat

Implementation

The following constructors create an instance of WaldWolfowitzTest class.

Constructor

Description

Performance

two-tailed test, default significance level

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

methodWaldWolfowitzTest

default significance level

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

methodWaldWolfowitzTest(Tail)

two-tailed test, user defined significance level

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

methodWaldWolfowitzTest(Double)

user defined tail and significance level

Creates WaldWolfowitzTest instance with user defined significance level and tail.

methodWaldWolfowitzTest(Double, Tail)

The class provides the following methods:

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 WaldWolfowitzTest class usage:

C#
 1using System;
 2using FinMath.LinearAlgebra;
 3using FinMath.Statistics.HypothesisTesting;
 4using FinMath.Statistics.Distributions;
 5
 6namespace FinMath.Samples
 7{
 8    class WaldWolfowitzTestSample
 9    {
10        static void Main()
11        {
12            //Create an instance of normal distribution.
13            Normal distr = new Normal(0, 1);
14
15            // Generate random series.
16            Vector series = Vector.Random(100, distr);
17
18            // Create an instance of WaldWolfowitzTest.
19            WaldWolfowitzTest test = new WaldWolfowitzTest(0.05, Tail.Both);
20            test.Update(series, 0);
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 WaldWolfowitzTest 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    }
32}

See Also