naginterfaces.library.nonpar.test_median(x, n1)[source]

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

For full information please refer to the NAG Library document for g08ac

xfloat, array-like, shape

The first elements of must be set to the data values in the first sample, and the next () elements to the data values in the second sample.


The size of the first sample .


The number of scores in the first sample which lie below the pooled median, .


The number of scores in the second sample which lie below the pooled median, .


The tail probability corresponding to the observed dichotomy of the two samples.

(errno )

On entry, .

Constraint: .

(errno )

On entry, and .

Constraint: .


In the NAG Library the traditional C interface for this routine uses a different algorithmic base. Please contact NAG if you have any questions about compatibility.

The Median test investigates the difference between the medians of two independent samples of sizes and , denoted by:


where .

The hypothesis under test, , often called the null hypothesis, is that the medians are the same, and this is to be tested against the alternative hypothesis that they are different.

The test proceeds by forming a frequency table, giving the number of scores in each sample above and below the median of the pooled sample:

Sample 1

Sample 2


Scores pooled median

Scores pooled median


Under the null hypothesis, , 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 , to be about and to be about .

test_median returns:

  1. the frequencies and ;

  2. the probability, , of observing a table at least as ‘extreme’ as that actually observed, given that is true. If , is computed directly (‘Fisher’s exact test’); otherwise a approximation is used (see stat.contingency_table).

is rejected by a test of chosen size if .


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