NAG FL Interface
g08acf (test_​median)

1 Purpose

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

2 Specification

Fortran Interface
Subroutine g08acf ( x, n, n1, w, i1, i2, p, ifail)
Integer, Intent (In) :: n, n1
Integer, Intent (Inout) :: ifail
Integer, Intent (Out) :: i1, i2
Real (Kind=nag_wp), Intent (In) :: x(n)
Real (Kind=nag_wp), Intent (Out) :: w(n), p
C Header Interface
#include <nag.h>
void  g08acf_ (const double x[], const Integer *n, const Integer *n1, double w[], Integer *i1, Integer *i2, double *p, Integer *ifail)
The routine may be called by the names g08acf or nagf_nonpar_test_median.

3 Description

The Median test investigates the difference between the medians of two independent samples of sizes n1 and n2, denoted by:
x1,x2,,xn1  
and
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:
  1. (a)the frequencies i1 and i2;
  2. (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 Arguments

1: xn Real (Kind=nag_wp) array Input
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 Integer Input
On entry: the total of the two sample sizes, n (=n1+n2).
Constraint: n2.
3: n1 Integer Input
On entry: the size of the first sample n1.
Constraint: 1n1<n.
4: wn Real (Kind=nag_wp) array Workspace
5: i1 Integer Output
On exit: the number of scores in the first sample which lie below the pooled median, i1.
6: i2 Integer Output
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 Integer Input/Output
On entry: ifail must be set to 0, -1 or 1. If you are unfamiliar with this argument you should refer to Section 4 in the Introduction to the NAG Library FL Interface 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: n2.
ifail=2
On entry, n1=value and n=value.
Constraint: 1n1<n.
ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
ifail=-399
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
ifail=-999
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

7 Accuracy

The probability returned should be accurate enough for practical use.

8 Parallelism and Performance

g08acf is not threaded in any implementation.

9 Further Comments

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

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

10.1 Program Text

Program Text (g08acfe.f90)

10.2 Program Data

Program Data (g08acfe.d)

10.3 Program Results

Program Results (g08acfe.r)