hide long namesshow long names
hide short namesshow short names
Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

NAG Toolbox: nag_nonpar_test_median (g08ac)

Purpose

nag_nonpar_test_median (g08ac) performs the Median test on two independent samples of possibly unequal size.

Syntax

[i1, i2, p, ifail] = g08ac(x, n1, 'n', n)
[i1, i2, p, ifail] = nag_nonpar_test_median(x, n1, 'n', n)

Description

The Median test investigates the difference between the medians of two independent samples of sizes n1n1 and n2n2, denoted by:
x1,x2,,xn1
x1,x2,,xn1
and
xn1 + 1, xn1 + 2,, xn,
xn1+ 1, xn1+ 2,, xn,
where n = n1 + n2n=n1+n2.
The hypothesis under test, H0H0, often called the null hypothesis, is that the medians are the same, and this is to be tested against the alternative hypothesis H1H1 that they are different.
The test proceeds by forming a 2 × 22×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 i1i1 i2i2 i1 + i2i1+i2
Scores  pooled median n1i1n1-i1 n2i2n2-i2 n(i1 + i2)n-(i1+i2)
Total n1n1 n2n2 nn
Under the null hypothesis, H0H0, 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 i1i1, to be about n1 / 2n1/2 and i2i2 to be about n2 / 2n2/2.
nag_nonpar_test_median (g08ac) returns:
(a) the frequencies i1i1 and i2i2;
(b) the probability, pp, of observing a table at least as ‘extreme’ as that actually observed, given that H0H0 is true. If n < 40n<40, pp is computed directly (‘Fisher's exact test’); otherwise a χ12χ12 approximation is used (see nag_stat_contingency_table (g01af)).
H0H0 is rejected by a test of chosen size αα if p < αp<α.

References

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

Parameters

Compulsory Input Parameters

1:     x(n) – double array
n, the dimension of the array, must satisfy the constraint n2n2.
The first n1n1 elements of x must be set to the data values in the first sample, and the next n2n2 ( = nn1=n-n1) elements to the data values in the second sample.
2:     n1 – int64int32nag_int scalar
The size of the first sample n1n1.
Constraint: 1n1 < n1n1<n.

Optional Input Parameters

1:     n – int64int32nag_int scalar
Default: The dimension of the array x.
The total of the two sample sizes, nn ( = n1 + n2=n1+n2).
Constraint: n2n2.

Input Parameters Omitted from the MATLAB Interface

w

Output Parameters

1:     i1 – int64int32nag_int scalar
The number of scores in the first sample which lie below the pooled median, i1i1.
2:     i2 – int64int32nag_int scalar
The number of scores in the second sample which lie below the pooled median, i2i2.
3:     p – double scalar
The tail probability pp corresponding to the observed dichotomy of the two samples.
4:     ifail – int64int32nag_int scalar
ifail = 0ifail=0 unless the function detects an error (see [Error Indicators and Warnings]).

Error Indicators and Warnings

Errors or warnings detected by the function:
  ifail = 1ifail=1
On entry,n < 2n<2.
  ifail = 2ifail=2
On entry,n1 < 1n1<1,
orn1nn1n.

Accuracy

The probability returned should be accurate enough for practical use.

Further Comments

The time taken by nag_nonpar_test_median (g08ac) is small, and increases with nn.

Example

function nag_nonpar_test_median_example
x = [13;
     6;
     12;
     7;
     12;
     7;
     10;
     7;
     10;
     7;
     10;
     7;
     10;
     8;
     9;
     8;
     17;
     6;
     16;
     8;
     15;
     8;
     15;
     10;
     15;
     10;
     14;
     10;
     14;
     11;
     14;
     11;
     13;
     12;
     13;
     12;
     13;
     12;
     12];
n1 = int64(16);
[i1, i2, p, ifail] = nag_nonpar_test_median(x, n1)
 

i1 =

                   13


i2 =

                    6


p =

   8.8086e-04


ifail =

                    0


function g08ac_example
x = [13;
     6;
     12;
     7;
     12;
     7;
     10;
     7;
     10;
     7;
     10;
     7;
     10;
     8;
     9;
     8;
     17;
     6;
     16;
     8;
     15;
     8;
     15;
     10;
     15;
     10;
     14;
     10;
     14;
     11;
     14;
     11;
     13;
     12;
     13;
     12;
     13;
     12;
     12];
n1 = int64(16);
[i1, i2, p, ifail] = g08ac(x, n1)
 

i1 =

                   13


i2 =

                    6


p =

   8.8086e-04


ifail =

                    0



PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2013