Dataplot Vol 1 Vol 2

# MEDIAN TEST

Name:
MEDIAN TEST (LET)
Type:
Analysis Command
Purpose:
Perform the median k-sample test for equal medians.
Description:
The median test is a special case of the chi-square test for independence. Given k samples with n1, n2, ..., nk observations, compute the grand median of all n1 + n2 + ... + nk observations. Then construct a 2xk contingency table where row one contains the number of observations above the grand median for each of the k samples and row two contains the number of observations below or equal to the grand median for each of the k samples. The chi-square test for independence can then be applied to this table. More specifically

H0: All k populations have the same median
Ha: All least two of the populations have different medians
Test Statistic: $$\frac{N^2}{ab} \sum_{i=1}^{k}{\frac{(O_{1i} - n_{i}a/N)^2}{n_{i}}}$$

where

 a the number of observations greater than the median for all samples b the number of observations less than or equal to the median for all samples N the total number of observations O1i the number of observations greater than the median for sample i
Significance Level: $$\alpha$$
Critical Region: $$T > \chi_{1-\alpha;k-1}^{2}$$

where $$\chi^{2}$$ is the percent point function of the chi-square distribution and k-1 is the degrees of freedom

Conclusion: Reject the independence hypothesis if the value of the test statistic is greater than the chi-square value.

Note that the chi-square critical value is a large sample approximation. Conover recommends dropping all samples with only one observation from the analysis in order for the approximation to be valid.

Syntax 1:
MEDIAN TEST <y> <x>             <SUBSET/EXCEPT/FOR qualification>
where <y> is the response variable;
<x> is the group-id variable;
and where the <SUBSET/EXCEPT/FOR qualification> is optional.
Syntax 2:
MULTIPLE MEDIAN TEST <y1> ... <yk>
<SUBSET/EXCEPT/FOR qualification>
where <y1> ... <yk> is a list of 2 to 30 response variables;
and where the <SUBSET/EXCEPT/FOR qualification> is optional.

This syntax can be used when the data for each sample is in a separate variable. This syntax supports the TO syntax for the variable list and also supports matrix arguments.

Examples:
MEDIAN TEST Y X
MULTIPLE MEDIAN TEST Y1 TO Y5
Note:
This test is based on the following assumptions.

1. sample is a random sample.

2. The samples are independent of each other.

3. The measurement scale is at least ordinal (i.e., the data can be ranked).

4. If all populations have the same median, the all populations have the same probability of an observation exceeding the grand median.
Note:
The following information is written to the file dpst1f.dat (in the current directory):

 Column 1: group-id Column 2: the number of observations above the median for group k Column 3: the total number of observations for group k

In addition, the following internal parameters are saved

 STATVAL: the value of the test statistic STATCDF: the CDF of the test statistic PVALUE: the p-value CUTOFF0: the 0-th percentile of the reference chi-square distribution CUTOFF50: the 50-th percentile of the reference chi-square distribution CUTOFF75: the 75-th percentile of the reference chi-square distribution CUTOFF90: the 90-th percentile of the reference chi-square distribution CUTOFF95: the 95-th percentile of the reference chi-square distribution CUTOF975: the 97.5-th percentile of the reference chi-square distribution CUTOFF99: the 99-th percentile of the reference chi-square distribution CUTOF999: the 99.9-th percentile of the reference chi-square distribution
Note:
The following statistics are also supported:

LET A = MEDIAN TEST Y X
LET A = MEDIAN TEST CDF Y X
LET A = MEDIAN TEST PVALUE Y X

In addition to the above LET command, built-in statistics are supported for about 20+ different commands (enter HELP STATISTICS for details).

Note:
Conover recomends the following procedure for performing multiple comparisons.

If the median test indicates the medians are not all equal, you can determine which pairs of medians are not equal by performing the median test on each pairwise set of observations. For example, you could do something like

MULTIPLE MEDIAN TEST Y1 Y2 Y3 Y4
MEDIAN TEST Y1 Y2
MEDIAN TEST Y1 Y3
MEDIAN TEST Y1 Y4
MEDIAN TEST Y2 Y4
MEDIAN TEST Y3 Y4
Note:
Although this command is typically used to test for equal medians, you can also use it to test for other quantile values by entering the command

SET MEDIAN TEST QUANTILE <value>

where <value> is a quantile between 0 and 1. The default value is 0.5 (i.e., the median).

Default:
None
Synonyms:
None
Related Commands:
 MEDIAN CONFIDENCE LIMITS = Compute confidence intervals for the median. CHI-SQUARE INDEPENDENCE TEST = Perform a chi-square test for independence. ODDS RATIO INDEPENDENCE TEST = Perform a log(odds ratio) test for independence. FISHER EXACT TEST = Perform Fisher's exact test. ASSOCIATION PLOT = Generate an association plot.
Reference:
Conover (1999), "Practical Nonparametric Statistics," Third Edition, Wiley, pp. 218-224.
Applications:
Nonparameteric Analysis
Implementation Date:
2011/5
Program 1:

. Purpose: Test Median Test command
.
. Step 1: Read Data (example 1 from pp. 304-305 of Conover)
.
let y1 = data 10.8 11.1 10.4 10.1 11.3
let y2 = data 10.8 10.5 11.0 10.9 10.8 10.7 10.8
.
let y x = stacked y1 y2
set write decimals 4
.
.  Step 2: Check the statistic
.
let stat2 = median test         y x
let cdf2  = median test cdf     y x
let pval2 = median test pvalue  y x
print stat2 cdf2 pval2
.
median test y x

The following output is generated.
 PARAMETERS AND CONSTANTS--

STAT2   --         0.1714
CDF2    --         0.3212
PVAL2   --         0.6788

Median Test

Response Variable: Y
Group-ID Variable: X
H0: Samples Have Equal Medians
Ha: At Least Two Samples Have Different Medians

Summary Statistics:
Original Number of Observations:                            12
Number of Observations After Omitting
Groups With Less Than Two Observations:                     12
Number of Groups:                                            2
Grand Median:                                               11
Number of Points > the Grand Median:                         4
Number of Points <= the Grand Median:                        8

Median Test Statistic Value:                            0.1714
CDF of Test Statistic:                                  0.3211
P-Value:                                                0.6788

Percent Points of the Chi-Square Reference Distribution
-----------------------------------
Percent Point               Value
-----------------------------------
0.0    =          0.000
50.0    =          0.455
75.0    =          1.322
90.0    =          2.706
95.0    =          3.841
97.5    =          5.024
99.0    =          6.634
99.9    =         10.827

Upper-Tailed Test: Chi-Square Approximation

H0: Medians Are Equal; Ha: Medians Are Not Equal
------------------------------------------------------------
Null
Significance           Test       Critical     Hypothesis
Level      Statistic      Value (>)     Conclusion
------------------------------------------------------------
90.0%         0.1714         2.7055         ACCEPT
95.0%         0.1714         3.8414         ACCEPT
97.5%         0.1714         5.0238         ACCEPT
99.0%         0.1714         6.6348         ACCEPT
99.9%         0.1714        10.8275         ACCEPT

Program 2:

. Purpose: Test Median Test command
.
. Step 1: Read Data (example 1 from pp. 221 of Conover)
.
let y1 = data 83 91 94 89 89 96 91 92 90
let y2 = data 91 90 81 83 84 83 88 91 89 84
let y3 = data 101 100 91 93 96 95 94
let y4 = data 78 82 81 77 79 81 80 81
.
.  Step 2: Check the statistic
.
.  stat = 17.6, pvalue = 0.001
.
set write decimals 4
multiple median test y1 y2 y3 y4

The following output is generated.
            Median Test

H0: Samples Have Equal Medians
Ha: At Least Two Samples Have Different Medians

Summary Statistics:
Original Number of Observations:                            34
Number of Observations After Omitting
Groups With Less Than Two Observations:                     34
Number of Groups:                                            4
Grand Median:                                               89
Number of Points > the Grand Median:                        16
Number of Points <= the Grand Median:                       18

Median Test Statistic Value:                           17.5430
CDF of Test Statistic:                                  0.9994
P-Value:                                                0.0005

Percent Points of the Chi-Square Reference Distribution
-----------------------------------
Percent Point               Value
-----------------------------------
0.0    =          0.000
50.0    =          2.366
75.0    =          4.107
90.0    =          6.251
95.0    =          7.815
97.5    =          9.348
99.0    =         11.345
99.9    =         16.265

Upper-Tailed Test: Chi-Square Approximation

H0: Medians Are Equal; Ha: Medians Are Not Equal
------------------------------------------------------------
Null
Significance           Test       Critical     Hypothesis
Level      Statistic      Value (>)     Conclusion
------------------------------------------------------------
90.0%        17.5430         6.2513         REJECT
95.0%        17.5430         7.8147         REJECT
97.5%        17.5430         9.3484         REJECT
99.0%        17.5430        11.3448         REJECT
99.9%        17.5430        16.2662         REJECT


NIST is an agency of the U.S. Commerce Department.

Date created: 09/15/2011
Last updated: 11/04/2015