NAG CL Interfaceg08acc (test_​median)

Settings help

CL Name Style:

1Purpose

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

2Specification

 #include
 void g08acc (Integer n1, const double x[], Integer n2, const double y[], Integer *below, Integer *above, double *p, NagError *fail)
The function may be called by the names: g08acc, nag_nonpar_test_median or nag_median_test.

3Description

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$.
g08acc 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.
${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{n1}$Integer Input
On entry: the size of the first sample, ${n}_{1}$.
Constraint: ${\mathbf{n1}}\ge 1$.
2: $\mathbf{x}\left[{\mathbf{n1}}\right]$const double Input
On entry: the elements of x must be set to the data values in the first sample.
3: $\mathbf{n2}$Integer Input
On entry: the size of the second sample, ${n}_{2}$.
Constraint: ${\mathbf{n2}}\ge 1$.
4: $\mathbf{y}\left[{\mathbf{n2}}\right]$const double Input
On entry: the elements of y must be set to the data values in the second sample.
5: $\mathbf{below}$Integer * Output
On exit: the number of scores in the first sample which lie below the pooled median, ${i}_{1}$.
6: $\mathbf{above}$Integer * Output
On exit: the number of scores in the first sample which lie above the pooled median, ${i}_{2}$.
7: $\mathbf{p}$double * Output
On exit: the tail probability, $p$, corresponding to the observed dichotomy of the two samples.
8: $\mathbf{fail}$NagError * Input/Output
The NAG error argument (see Section 7 in the Introduction to the NAG Library CL Interface).

6Error 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}}⟩$.

7Accuracy

The probability returned should be accurate enough for practical use.

8Parallelism and Performance

g08acc is not threaded in any implementation.

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

10.2Program Data

Program Data (g08acce.d)

10.3Program Results

Program Results (g08acce.r)