NAG Library Routine Document

g08aaf (test_sign)

1
Purpose

g08aaf performs the Sign test on two related samples of size n.

2
Specification

Fortran Interface
Subroutine g08aaf ( x, y, n, isgn, n1, p, ifail)
Integer, Intent (In):: n
Integer, Intent (Inout):: ifail
Integer, Intent (Out):: isgn, n1
Real (Kind=nag_wp), Intent (In):: x(n), y(n)
Real (Kind=nag_wp), Intent (Out):: p
C Header Interface
#include <nagmk26.h>
void  g08aaf_ (const double x[], const double y[], const Integer *n, Integer *isgn, Integer *n1, double *p, Integer *ifail)

3
Description

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).
g08aaf 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<α.

4
References

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

5
Arguments

1:     xn – Real (Kind=nag_wp) arrayInput
2:     yn – Real (Kind=nag_wp) arrayInput
On entry: xi and yi must be set to the ith pair of data values, xi,yi, for i=1,2,,n.
3:     n – IntegerInput
On entry: n, the size of each sample.
Constraint: n1.
4:     isgn – IntegerOutput
On exit: the Sign test statistic, S.
5:     n1 – IntegerOutput
On exit: the number of non-tied pairs, n1.
6:     p – Real (Kind=nag_wp)Output
On exit: the lower tail probability, p, corresponding to S.
7:     ifail – IntegerInput/Output
On entry: ifail must be set to 0, -1 or 1. If you are unfamiliar with this argument you should refer to Section 3.4 in How to Use the NAG Library and its Documentation for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value -1 or 1 is recommended. If the output of error messages is undesirable, then the value 1 is recommended. Otherwise, if you are not familiar with this argument, the recommended value is 0. When the value -1 or 1 is used it is essential to test the value of ifail on exit.
On exit: ifail=0 unless the routine detects an error or a warning has been flagged (see Section 6).

6
Error Indicators and Warnings

If on entry ifail=0 or -1, explanatory error messages are output on the current error message unit (as defined by x04aaf).
Errors or warnings detected by the routine:
ifail=1
On entry, n=value.
Constraint: n1.
ifail=2
On entry, the samples are identical, i.e., n1=0.
ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 3.9 in How to Use the NAG Library and its Documentation for further information.
ifail=-399
Your licence key may have expired or may not have been installed correctly.
See Section 3.8 in How to Use the NAG Library and its Documentation for further information.
ifail=-999
Dynamic memory allocation failed.
See Section 3.7 in How to Use the NAG Library and its Documentation for further information.

7
Accuracy

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 g01eef.

8
Parallelism and Performance

g08aaf is not threaded in any implementation.

9
Further Comments

The time taken by g08aaf is small, and increases with n.

10
Example

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.

10.1
Program Text

Program Text (g08aafe.f90)

10.2
Program Data

Program Data (g08aafe.d)

10.3
Program Results

Program Results (g08aafe.r)