G08 Chapter Contents
G08 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentG08ACF

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.

## 1  Purpose

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

## 2  Specification

 SUBROUTINE G08ACF ( X, N, N1, W, I1, I2, P, IFAIL)
 INTEGER N, N1, I1, I2, IFAIL 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 ${n}_{1}$ and ${n}_{2}$, denoted by:
 $x1,x2,…,xn1$
and
 $xn1+ 1, xn1+ 2,…, xn,$
where $n={n}_{1}+{n}_{2}$.
The hypothesis under test, ${H}_{0}$, often called the null hypothesis, is that the medians are the same, and this is to be tested against the alternative hypothesis ${H}_{1}$ 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 ${i}_{1}$ ${i}_{2}$ ${i}_{1}+{i}_{2}$ Scores $\ge$ pooled median ${n}_{1}-{i}_{1}$ ${n}_{2}-{i}_{2}$ $n-\left({i}_{1}+{i}_{2}\right)$ Total ${n}_{1}$ ${n}_{2}$ $n$
Under the null hypothesis, ${H}_{0}$, 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 ${i}_{1}$, to be about ${n}_{1}/2$ and ${i}_{2}$ to be about ${n}_{2}/2$.
G08ACF returns:
 (a) the frequencies ${i}_{1}$ and ${i}_{2}$; (b) the probability, $p$, of observing a table at least as ‘extreme’ as that actually observed, given that ${H}_{0}$ is true. If $n<40$, $p$ is computed directly (‘Fisher's exact test’); otherwise a ${\chi }_{1}^{2}$ approximation is used (see G01AFF).
${H}_{0}$ is rejected by a test of chosen size $\alpha$ if $p<\alpha$.
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 ${n}_{1}$ elements of X must be set to the data values in the first sample, and the next ${n}_{2}$ ($\text{}={\mathbf{N}}-{n}_{1}$) elements to the data values in the second sample.
2:     N – INTEGERInput
On entry: the total of the two sample sizes, $n$ ($\text{}={n}_{1}+{n}_{2}$).
Constraint: ${\mathbf{N}}\ge 2$.
3:     N1 – INTEGERInput
On entry: the size of the first sample ${n}_{1}$.
Constraint: $1\le {\mathbf{N1}}<{\mathbf{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, ${i}_{1}$.
6:     I2 – INTEGEROutput
On exit: the number of scores in the second sample which lie below the pooled median, ${i}_{2}$.
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\text{​ 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\text{​ 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 $-\mathbf{1}\text{​ or ​}\mathbf{1}$ is used it is essential to test the value of IFAIL on exit.
On exit: ${\mathbf{IFAIL}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

## 6  Error Indicators and Warnings

If on entry ${\mathbf{IFAIL}}={\mathbf{0}}$ or $-{\mathbf{1}}$, explanatory error messages are output on the current error message unit (as defined by X04AAF).
Errors or warnings detected by the routine:
${\mathbf{IFAIL}}=1$
 On entry, ${\mathbf{N}}<2$.
${\mathbf{IFAIL}}=2$
 On entry, ${\mathbf{N1}}<1$, or ${\mathbf{N1}}\ge {\mathbf{N}}$.

## 7  Accuracy

The probability returned should be accurate enough for practical use.

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)