hide long namesshow long names
hide short namesshow short names
Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

NAG Toolbox: nag_nonpar_test_wilcoxon (g08ag)

Purpose

nag_nonpar_test_wilcoxon (g08ag) performs the Wilcoxon signed rank test on a single sample of size nn.

Syntax

[w, wnor, p, n1, ifail] = g08ag(x, xme, tail, zer, 'n', n)
[w, wnor, p, n1, ifail] = nag_nonpar_test_wilcoxon(x, xme, tail, zer, 'n', n)

Description

The Wilcoxon one-sample signed rank test may be used to test whether a particular sample came from a population with a specified median. It is assumed that the population distribution is symmetric. The data consists of a single sample of nn observations denoted by x1,x2,,xnx1,x2,,xn. This sample may arise from the difference between pairs of observations from two matched samples of equal size taken from two populations, in which case the test may be used to test whether the median of the first population is the same as that of the second population.
The hypothesis under test, H0H0, often called the null hypothesis, is that the median is equal to some given value (Xmed)(Xmed), and this is to be tested against an alternative hypothesis H1H1 which is using a two tailed, upper tailed or lower tailed probability respectively. You select the alternative hypothesis by choosing the appropriate tail probability to be computed (see the description of parameter tail in Section [Parameters]).
The Wilcoxon test differs from the Sign test (see nag_nonpar_test_sign (g08aa)) in that the magnitude of the scores is taken into account, rather than simply the direction of such scores.
The test procedure is as follows
(a) For each xixi, for i = 1,2,,ni=1,2,,n, the signed difference di = xiXmeddi=xi-Xmed is found, where XmedXmed is a given test value for the median of the sample.
(b) The absolute differences |di||di| are ranked with rank riri and any tied values of |di||di| are assigned the average of the tied ranks. You may choose whether or not to ignore any cases where di = 0di=0 by removing them before or after ranking (see the description of the parameter zer in Section [Parameters]).
(c) The number of nonzero didi is found.
(d) To each rank is affixed the sign of the didi to which it corresponds. Let si = sign(di)risi=sign(di)ri.
(e) The sum of the positive-signed ranks, W = si > 0 si = i = 1nmax (si,0.0)W=si>0si=i=1nmax(si,0.0), is calculated.
nag_nonpar_test_wilcoxon (g08ag) returns
(a) the test statistic WW;
(b) the number n1n1 of nonzero didi;
(c) the approximate Normal test statistic zz, where
z = ( (W(n1(n1 + 1))/4)sign(W(n1(n1 + 1))/4) × (1/2))/(sqrt((1/4)i = 1nsi2));
z= (W- n1(n1+1)4)-sign(W- n1(n1+1)4) × 12 14i=1nsi2 ;
(d) the tail probability, pp, corresponding to WW, depending on the choice of the alternative hypothesis, H1H1.
If n180n180, pp is computed exactly; otherwise, an approximation to pp is returned based on an approximate Normal statistic corrected for continuity according to the tail specified.
The value of pp can be used to perform a significance test on the median against the alternative hypothesis. Let αα be the size of the significance test (that is, αα is the probability of rejecting H0H0 when H0H0 is true). If p < αp<α then the null hypothesis is rejected. Typically αα might be 0.050.05 or 0.010.01.

References

Conover W J (1980) Practical Nonparametric Statistics Wiley
Neumann N (1988) Some procedures for calculating the distributions of elementary nonparametric teststatistics Statistical Software Newsletter 14(3) 120–126
Siegel S (1956) Non-parametric Statistics for the Behavioral Sciences McGraw–Hill

Parameters

Compulsory Input Parameters

1:     x(n) – double array
n, the dimension of the array, must satisfy the constraint n1n1.
The sample observations, x1,x2,,xnx1,x2,,xn.
2:     xme – double scalar
The median test value, XmedXmed.
3:     tail – string (length ≥ 1)
Indicates the choice of tail probability, and hence the alternative hypothesis.
tail = 'T'tail='T'
A two tailed probability is calculated and the alternative hypothesis is H1H1: population median XmedXmed.
tail = 'U'tail='U'
An upper tailed probability is calculated and the alternative hypothesis is H1H1: population median > Xmed>Xmed.
tail = 'L'tail='L'
A lower tailed probability is calculated and the alternative hypothesis is H1H1: population median < Xmed<Xmed.
Constraint: tail = 'T'tail='T', 'U''U' or 'L''L'.
4:     zer – string (length ≥ 1)
Indicates whether or not to include the cases where di = 0.0di=0.0 in the ranking of the didi's.
zer = 'Y'zer='Y'
All di = 0.0di=0.0 are included when ranking.
zer = 'N'zer='N'
All di = 0.0di=0.0, are ignored, that is all cases where di = 0.0di=0.0 are removed before ranking.
Constraint: zer = 'Y'zer='Y' or 'N''N'.

Optional Input Parameters

1:     n – int64int32nag_int scalar
Default: The dimension of the array x.
nn, the size of the sample.
Constraint: n1n1.

Input Parameters Omitted from the MATLAB Interface

wrk

Output Parameters

1:     w – double scalar
The Wilcoxon rank sum statistic, WW, being the sum of the positive ranks.
2:     wnor – double scalar
The approximate Normal test statistic, zz, as described in Section [Description].
3:     p – double scalar
The tail probability, pp, as specified by the parameter tail.
4:     n1 – int64int32nag_int scalar
The number of nonzero didi's, n1n1.
5:     ifail – int64int32nag_int scalar
ifail = 0ifail=0 unless the function detects an error (see [Error Indicators and Warnings]).

Error Indicators and Warnings

Errors or warnings detected by the function:

Cases prefixed with W are classified as warnings and do not generate an error of type NAG:error_n. See nag_issue_warnings.

  ifail = 1ifail=1
On entry,tail'T'tail'T', 'U''U' or 'L''L'.
orzer'Y'zer'Y' or 'N''N'.
  ifail = 2ifail=2
On entry,n < 1n<1.
W ifail = 3ifail=3
The whole sample is identical to the given median test value.

Accuracy

The approximation used to calculate pp when n1 > 80n1>80 will return a value with a relative error of less than 10%10% for most cases. The error may increase for cases where there are a large number of ties in the sample.

Further Comments

The time taken by nag_nonpar_test_wilcoxon (g08ag) increases with n1n1, until n1 > 80n1>80, from which point on the approximation is used. The time decreases significantly at this point and increases again modestly with n1n1 for n1 > 80n1>80.

Example

function nag_nonpar_test_wilcoxon_example
x = [19;
     27;
     -1;
     6;
     7;
     13;
     -4;
     3];
xme = 0;
tail = 'Two-tail';
zer = 'Nozeros';
[w, wnor, p, n1, ifail] = nag_nonpar_test_wilcoxon(x, xme, tail, zer)
 

w =

    32


wnor =

    1.8904


p =

    0.0547


n1 =

                    8


ifail =

                    0


function g08ag_example
x = [19;
     27;
     -1;
     6;
     7;
     13;
     -4;
     3];
xme = 0;
tail = 'Two-tail';
zer = 'Nozeros';
[w, wnor, p, n1, ifail] = g08ag(x, xme, tail, zer)
 

w =

    32


wnor =

    1.8904


p =

    0.0547


n1 =

                    8


ifail =

                    0



PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2013