# The Median Test

Example:
#A = #B = , Median = , p <=

The observation sequences
A B

Characteristics:
This is the two-sample equivalent of the one-sample Sign-Test and this test is just as crude and insensitive. However, because there are so few assumptions, a statistically significant result is very convincing.

H0:
The median values of the two samples are equal

Assumptions:
None other than H0

Scale:
Ordinal, but only the sign with respect to the combined median is used.

Procedure:
Determine the median value of the combined samples. Count the number of observations in the smallest sample that are smaller than the median (H) and the total number of observations smaller than the median (m).
Together with the number of observations in the smallest sample (n1) and the total number of observations (N), these four numbers are used to calculate the level of significance.

Level of Significance:
The probability of a certain outcome k is:
P( k ) = ( k out m ) * (( n1 - k ) out ( N - m )) / ( n1 out N )
with: ( k out n ) = n! / ( k! * (n-k)! )
If H < ( n1 * m / N ) : sum all P(k=0, H)
If H > ( n1 * m / N ) : sum all P(k=H, m)

Approximation:
If both samples contain more than 10 observations, then the distribution of
Z = ( H + 0.5 - ( n1 * m / N ) / sqrt( n1 * ( N - n1 ) * N * ( N - m ) / ( N ** 2 * ( N - 1 ) ) )
can be approximated by a Standard Normal distribution.

Remarks:
This test for median values is a permutation test. It tries to calculate the level of significance from all possible permutations of the observations with respect to both samples.
When there are observations equal to the median value (i.e., ties) these should be assigned conservatively, i.e., in a way that makes rejection of the H0 less likely. This has been implemented in this example.
In this example, exact probabilities are calculated for .