PDF version (NAG web site
, 64-bit version, 64-bit version)
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
Description
The Median test investigates the difference between the medians of two independent samples of sizes
and
, denoted by:
and
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 |
Total |
Scores pooled median |
|
|
|
Scores pooled median |
|
|
|
Total |
|
|
|
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
.
nag_nonpar_test_median (g08ac) returns:
(a) |
the frequencies and ; |
(b) |
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 nag_stat_contingency_table (g01af)). |
is rejected by a test of chosen size if .
References
Siegel S (1956) Non-parametric Statistics for the Behavioral Sciences McGraw–Hill
Parameters
Compulsory Input Parameters
- 1:
– double array
-
The first
elements of
x must be set to the data values in the first sample, and the next
(
) elements to the data values in the second sample.
- 2:
– int64int32nag_int scalar
-
The size of the first sample .
Constraint:
.
Optional Input Parameters
- 1:
– int64int32nag_int scalar
-
Default:
the dimension of the array
x.
The total of the two sample sizes, ().
Constraint:
.
Output Parameters
- 1:
– int64int32nag_int scalar
-
The number of scores in the first sample which lie below the pooled median, .
- 2:
– int64int32nag_int scalar
-
The number of scores in the second sample which lie below the pooled median, .
- 3:
– double scalar
-
The tail probability corresponding to the observed dichotomy of the two samples.
- 4:
– int64int32nag_int scalar
unless the function detects an error (see
Error Indicators and Warnings).
Error Indicators and Warnings
Errors or warnings detected by the function:
-
-
-
-
-
An unexpected error has been triggered by this routine. Please
contact
NAG.
-
Your licence key may have expired or may not have been installed correctly.
-
Dynamic memory allocation failed.
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 .
Example
This example is taken from page 112 of
Siegel (1956). The data relate to scores of ‘oral socialisation anxiety’ in
societies, which can be separated into groups of size
and
on the basis of their attitudes to illness.
Open in the MATLAB editor:
g08ac_example
function g08ac_example
fprintf('g08ac example results\n\n');
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];
n = numel(x);
n1 = int64(16);
n2 = n-n1;
fprintf('Median test\n\n');
fprintf('Data values\n\n');
fprintf(' Group 1 ');
for j = 1:floor(n1/8)
i1 = (j-1)*8 + 1;
i2 = min(n1,i1+7);
fprintf('%4.0f',x(i1:i2));
fprintf('\n ');
end
fprintf('\n Group 2 ');
for j = 1:floor(n2/8)
i1 = (j-1)*8 + 1;
i2 = min(n2,i1+7);
fprintf('%4.0f',x(i1+n1:i2+n1));
fprintf('\n ');
end
[i1, i2, p, ifail] = g08ac( ...
x, n1);
fprintf('\n%6d scores below median in group 1\n',i1);
fprintf('%6d scores below median in group 2\n\n',i2);
fprintf(' Significance %10.5f\n',p);
g08ac example results
Median test
Data values
Group 1 13 6 12 7 12 7 10 7
10 7 10 7 10 8 9 8
Group 2 17 6 16 8 15 8 15 10
15 10 14 10 14 11 14 11
13 12 13 12 13 12 12
13 scores below median in group 1
6 scores below median in group 2
Significance 0.00088
PDF version (NAG web site
, 64-bit version, 64-bit version)
© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015