nag_median_test (g08acc) (PDF version)
g08 Chapter Contents
g08 Chapter Introduction
NAG C Library Manual

NAG Library Function Document

nag_median_test (g08acc)

+ Contents

    1  Purpose
    7  Accuracy

1  Purpose

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

2  Specification

#include <nag.h>
#include <nagg08.h>
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  pooled median i 1 i 2 i 1 + i 2
Scores  pooled median n 1 - i 1 n 2 - i 2 n - i 1 + i 2
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 χ 1 2  approximation is used.
H 0  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:     n1IntegerInput
On entry: the size of the first sample, n 1 .
Constraint: n11 .
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: n21 .
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: n1=value .
On entry, n2 must not be less than 1: n2=value .

7  Accuracy

The probability returned should be accurate enough for practical use.

8  Further Comments

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)


nag_median_test (g08acc) (PDF version)
g08 Chapter Contents
g08 Chapter Introduction
NAG C Library Manual

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