Click or drag to resize

Wilcoxon Signed Rank Test

One sample Wicoxon signed rank test of the null hypothesis that the distribution is symmetric with respect to the supposed median, i.e. there are equal probabilities to get sample greater than m+x and less than m−x, where m is supposed median.

This topic contains the following sections:

Wilcoxon Signed Rank Test Specification

Tail.Both must be set if in the alternative hypothesis distribution is not symmetric or median is not equal to the supposed median.

Tail.Left must be set if in the alternative hypothesis distribution is not symmetric or median is less than the supposed median.

Tail.Right must be set if in the alternative hypothesis distribution is not symmetric or median is greater than the supposed median.

The following method is applied:

  1. The elements of the sample which are greater than median are reduced by the median value and the result is placed in the sample1.

    The elements of the sample which are less than median are subtracted from the median value and the result is placed in the sample2.

    The elements equal to the median value are ignored.

    Both samples are sorted in non-decreasing order.

  2. The ranks of the elements in the combined sample are obtained.

  3. A method for handling ties is used. (A tie is counted when two observations are within fuzz of each other.) The average rank of the tied observations is calculated for handling tied observations between sample1 and sample2.

  4. The rank sum function is computed as the sum of the ranks in the sample1.

  5. Tie adjustment is computed using the following formula:

    HT WilcoxonRSTie Adj

    where tiesi means the number of tied elements in tie i.

  6. Mean and standard deviation are calculated:

    HT WilcoxonSRMean

    HT WilcoxonSRSt Dev

    where n is the sum of sizes of sample1 and sample2.

  7. Test statistic is calculated as (rank sum - μ)/σ.

  8. When one performs a Wilcoxon test for small samples, p-value is calculated exactly using the combinatorial method. For larger samples, a Normal distribution approximation is used and p-value is calculated approximately. Therefore, in general, decision based on p-value and significance level comparison is more exact.

Implementation

The following constructors create an instance of WilcoxonSignedRankTest class.

Constructor

Description

Performance

two-tailed test, default significance level

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

methodWilcoxonSignedRankTest

default significance level

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

methodWilcoxonSignedRankTest(Tail)

two-tailed test, user defined significance level

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

methodWilcoxonSignedRankTest(Double)

user defined tail and significance level

Creates WilcoxonSignedRankTest instance with user defined significance level and tail.

methodWilcoxonSignedRankTest(Double, Tail)

The class provides the following methods:

Method

Description

Performance

update

Updates test statistic using provided sample and supposition about median.

Double array series:

methodUpdate(Double, Double)

Vector series:

methodUpdate(Vector, 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 WilcoxonSignedRankTest class usage: -

C#
 1using System;
 2using FinMath.LinearAlgebra;
 3using FinMath.Statistics.HypothesisTesting;
 4using FinMath.Statistics.Distributions;
 5
 6namespace FinMath.Samples
 7{
 8    class WilcoxonSignedRankTestSample
 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);
17
18            // Create an instance of WilcoxonSignedRankTest.
19            WilcoxonSignedRankTest test = new WilcoxonSignedRankTest(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 WilcoxonSignedRankTest 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