# NAG FL Interfaceg08acf (test_​median)

## ▸▿ Contents

Settings help

FL Name Style:

FL Specification Language:

## 1Purpose

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

## 2Specification

Fortran Interface
 Subroutine g08acf ( x, n, n1, w, i1, i2, p,
 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
#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.

## 3Description

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:
1. (a)the frequencies ${i}_{1}$ and ${i}_{2}$;
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$.

## 4References

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

## 5Arguments

1: $\mathbf{x}\left({\mathbf{n}}\right)$Real (Kind=nag_wp) array Input
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: $\mathbf{n}$Integer Input
On entry: the total of the two sample sizes, $n$ ($\text{}={n}_{1}+{n}_{2}$).
Constraint: ${\mathbf{n}}\ge 2$.
3: $\mathbf{n1}$Integer Input
On entry: the size of the first sample ${n}_{1}$.
Constraint: $1\le {\mathbf{n1}}<{\mathbf{n}}$.
4: $\mathbf{w}\left({\mathbf{n}}\right)$Real (Kind=nag_wp) array Workspace
5: $\mathbf{i1}$Integer Output
On exit: the number of scores in the first sample which lie below the pooled median, ${i}_{1}$.
6: $\mathbf{i2}$Integer Output
On exit: the number of scores in the second sample which lie below the pooled median, ${i}_{2}$.
7: $\mathbf{p}$Real (Kind=nag_wp) Output
On exit: the tail probability $p$ corresponding to the observed dichotomy of the two samples.
8: $\mathbf{ifail}$Integer Input/Output
On entry: ifail must be set to $0$, $-1$ or $1$ to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of $0$ causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of $-1$ means that an error message is printed while a value of $1$ means that it is not.
If halting is not appropriate, the value $-1$ or $1$ is recommended. If message printing is undesirable, then the value $1$ is recommended. Otherwise, the value $0$ is recommended. When the value $-\mathbf{1}$ 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).

## 6Error Indicators and Warnings

If on entry ${\mathbf{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:
${\mathbf{ifail}}=1$
On entry, ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{n}}\ge 2$.
${\mathbf{ifail}}=2$
On entry, ${\mathbf{n1}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$.
Constraint: $1\le {\mathbf{n1}}<{\mathbf{n}}$.
${\mathbf{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.
${\mathbf{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.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

## 7Accuracy

The probability returned should be accurate enough for practical use.

## 8Parallelism and Performance

Background information to multithreading can be found in the Multithreading documentation.
g08acf is not threaded in any implementation.

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

## 10Example

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.1Program Text

Program Text (g08acfe.f90)

### 10.2Program Data

Program Data (g08acfe.d)

### 10.3Program Results

Program Results (g08acfe.r)