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_sign (g08aa)


    1  Purpose
    2  Syntax
    7  Accuracy
    9  Example


nag_nonpar_test_sign (g08aa) performs the Sign test on two related samples of size n.


[isgn, n1, p, ifail] = g08aa(x, y, 'n', n)
[isgn, n1, p, ifail] = nag_nonpar_test_sign(x, y, 'n', n)


The Sign test investigates the median difference between pairs of scores from two matched samples of size n, denoted by xi,yi, for i=1,2,,n. The hypothesis under test, H0, often called the null hypothesis, is that the medians are the same, and this is to be tested against a one- or two-sided alternative H1 (see below).
nag_nonpar_test_sign (g08aa) computes:
(a) the test statistic S, which is the number of pairs for which xi<yi;
(b) the number n1 of non-tied pairs xiyi;
(c) the lower tail probability p corresponding to S (adjusted to allow the complement 1-p to be used in an upper one tailed or a two tailed test). p is the probability of observing a value S if S<12n1, or of observing a value <S if S>12n1, given that H0 is true. If S=12n1, p is set to 0.5.
Suppose that a significance test of a chosen size α is to be performed (i.e., α is the probability of rejecting H0 when H0 is true; typically α is a small quantity such as 0.05 or 0.01). The returned value of p can be used to perform a significance test on the median difference, against various alternative hypotheses H1, as follows
(i) H1: median of x median of y. H0 is rejected if 2 × minp,1-p < α .
(ii) H1: median of x> median of y. H0 is rejected if p<α.
(iii) H1: median of x< median of y. H0 is rejected if 1-p<α.


Siegel S (1956) Non-parametric Statistics for the Behavioral Sciences McGraw–Hill


Compulsory Input Parameters

1:     xn – double array
2:     yn – double array
xi and yi must be set to the ith pair of data values, xi,yi, for i=1,2,,n.

Optional Input Parameters

1:     n int64int32nag_int scalar
Default: the dimension of the arrays x, y. (An error is raised if these dimensions are not equal.)
n, the size of each sample.
Constraint: n1.

Output Parameters

1:     isgn int64int32nag_int scalar
The Sign test statistic, S.
2:     n1 int64int32nag_int scalar
The number of non-tied pairs, n1.
3:     p – double scalar
The lower tail probability, p, corresponding to S.
4:     ifail int64int32nag_int scalar
ifail=0 unless the function detects an error (see Error Indicators and Warnings).

Error Indicators and Warnings

Errors or warnings detected by the function:
On entry,n<1.
n1=0, i.e., the samples are identical.
An unexpected error has been triggered by this routine. Please contact NAG.
Your licence key may have expired or may not have been installed correctly.
Dynamic memory allocation failed.


The tail probability, p, is computed using the relationship between the binomial and beta distributions. For n1<120, p should be accurate to at least 4 significant figures, assuming that the machine has a precision of 7 or more digits. For n1120, p should be computed with an absolute error of less than 0.005. For further details see nag_stat_prob_beta (g01ee).

Further Comments

The time taken by nag_nonpar_test_sign (g08aa) is small, and increases with n.


This example is taken from page 69 of Siegel (1956). The data relates to ratings of ‘insight into paternal discipline’ for 17 sets of parents, recorded on a scale from 1 to 5.
function g08aa_example

fprintf('g08aa example results\n\n');

x = [4; 4; 5; 5; 3; 2; 5; 3; 1; 5; 5; 5; 4; 5; 5; 5; 5];
y = [2; 3; 3; 3; 3; 3; 3; 3; 2; 3; 2; 2; 5; 2; 5; 3; 1];

fprintf('Sign test\n\n')
fprintf('Data values\n\n');

[isgn, n1, p, ifail] = g08aa( ...
                              x, y);

fprintf('Test statistic   %5d\n', isgn);
fprintf('Observations     %5d\n', n1);
fprintf('Lower tail prob. %5.3f\n', p);

g08aa example results

Sign test

Data values

  4  4  5  5  3  2  5  3  1  5  5  5  4  5  5  5  5
  2  3  3  3  3  3  3  3  2  3  2  2  5  2  5  3  1

Test statistic       3
Observations        14
Lower tail prob. 0.029

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–2015