G08ACF (PDF version)
G08 Chapter Contents
G08 Chapter Introduction
NAG Library Manual

NAG Library Routine Document


Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

+ Contents

    1  Purpose
    7  Accuracy

1  Purpose

G08ACF performs the Median test on two independent samples of possibly unequal size.

2  Specification

REAL (KIND=nag_wp)  X(N), W(N), P

3  Description

The Median test investigates the difference between the medians of two independent samples of sizes n1 and n2, denoted by:
xn1+ 1, xn1+ 2,, xn,
where n=n1+n2.
The hypothesis under test, H0, often called the null hypothesis, is that the medians are the same, and this is to be tested against the alternative hypothesis H1 that they are different.
The test proceeds by forming a 2×2 frequency table, giving the number of scores in each sample above and below the median of the pooled sample:
  Sample 1 Sample 2 Total
Scores < pooled median i1 i2 i1+i2
Scores  pooled median n1-i1 n2-i2 n-i1+i2
Total n1 n2 n
Under the null hypothesis, H0, we would expect about half of each group's scores to be above the pooled median and about half below, that is, we would expect i1, to be about n1/2 and i2 to be about n2/2.
G08ACF returns:
(a) the frequencies i1 and i2;
(b) the probability, p, of observing a table at least as ‘extreme’ as that actually observed, given that H0 is true. If n<40, p is computed directly (‘Fisher's exact test’); otherwise a χ12 approximation is used (see G01AFF).
H0 is rejected by a test of chosen size α if p<α.

4  References

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

5  Parameters

1:     X(N) – REAL (KIND=nag_wp) arrayInput
On entry: the first n1 elements of X must be set to the data values in the first sample, and the next n2 (=N-n1) elements to the data values in the second sample.
2:     N – INTEGERInput
On entry: the total of the two sample sizes, n (=n1+n2).
Constraint: N2.
3:     N1 – INTEGERInput
On entry: the size of the first sample n1.
Constraint: 1N1<N.
4:     W(N) – REAL (KIND=nag_wp) arrayWorkspace
5:     I1 – INTEGEROutput
On exit: the number of scores in the first sample which lie below the pooled median, i1.
6:     I2 – INTEGEROutput
On exit: the number of scores in the second sample which lie below the pooled median, i2.
7:     P – REAL (KIND=nag_wp)Output
On exit: the tail probability p corresponding to the observed dichotomy of the two samples.
8:     IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to 0, -1​ or ​1. If you are unfamiliar with this parameter you should refer to Section 3.3 in the Essential Introduction 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 parameter, 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:
On entry,N<2.
On entry,N1<1,

7  Accuracy

The probability returned should be accurate enough for practical use.

8  Further Comments

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

9  Example

This example is taken from page 112 of Siegel (1956). The data relate to scores of ‘oral socialisation anxiety’ in 39 societies, which can be separated into groups of size 16 and 23 on the basis of their attitudes to illness.

9.1  Program Text

Program Text (g08acfe.f90)

9.2  Program Data

Program Data (g08acfe.d)

9.3  Program Results

Program Results (g08acfe.r)

G08ACF (PDF version)
G08 Chapter Contents
G08 Chapter Introduction
NAG Library Manual

© The Numerical Algorithms Group Ltd, Oxford, UK. 2012