g08 Chapter Contents
g08 Chapter Introduction
NAG C Library Manual

# NAG Library Function Documentnag_median_test (g08acc)

## 1  Purpose

nag_median_test (g08acc) performs the Median test on two independent samples of possibly unequal size.

## 2  Specification

 #include #include
 void nag_median_test (Integer n1, const double x[], Integer n2, const double y[], Integer *below, Integer *above, double *p, NagError *fail)

## 3  Description

The Median test investigates the difference between the medians of two independent samples of sizes ${n}_{1}$ and ${n}_{2}$, denoted by:
 $x 1 , x 2 , … , x n 1 and x n 1 + 1 , x n 1 + 2 , … , x n , 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 $\le$ 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$.
nag_median_test (g08acc) 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.
${H}_{0}$ is rejected by a test of chosen size $\alpha$ if $p<\alpha$.

## 4  References

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

## 5  Arguments

1:     n1IntegerInput
On entry: the size of the first sample, ${n}_{1}$.
Constraint: ${\mathbf{n1}}\ge 1$.
2:     x[n1]const doubleInput
On entry: the elements of x must be set to the data values in the first sample.
3:     n2IntegerInput
On entry: the size of the second sample, ${n}_{2}$.
Constraint: ${\mathbf{n2}}\ge 1$.
4:     y[n2]const doubleInput
On entry: the elements of y must be set to the data values in the second sample.
5:     belowInteger *Output
On exit: the number of scores in the first sample which lie below the pooled median, ${i}_{1}$.
6:     aboveInteger *Output
On exit: the number of scores in the first sample which lie above the pooled median, ${i}_{2}$.
7:     pdouble *Output
On exit: the tail probability, $p$, corresponding to the observed dichotomy of the two samples.
8:     failNagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).

## 6  Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
NE_INT_ARG_LT
On entry, n1 must not be less than 1: ${\mathbf{n1}}=〈\mathit{\text{value}}〉$.
On entry, n2 must not be less than 1: ${\mathbf{n2}}=〈\mathit{\text{value}}〉$.

## 7  Accuracy

The probability returned should be accurate enough for practical use.

The time taken by nag_median_test (g08acc) 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 (g08acce.c)

### 9.2  Program Data

Program Data (g08acce.d)

### 9.3  Program Results

Program Results (g08acce.r)