I have two independed samples: df and df8. The first sample df includes points at the data1 and at the data2. These points were earned in an experimental group (n1=20). The second sample df8 includes points at the data1 and at the data2. But these points are correspond to a control group (n2=21).

From boxplot we can see that median1< median2, at the data1 and vice versa at the data2: median1> median2.


I would like to prove this fact with the Brown-Mood median test (First sample is not normal.

The null hypothesis: median1= median2. I have tested the null hypothesis at the data2 and at the data1. In both cases the null hypothesis was rejected:

data1: p-value = 0.9211>0.05

data2: p-value = 0.1378>0.05

It means that median1 < median2 twice, at the data1 and data2.

Could someone please correct me and give an idea how to statistically prove that median1< median2 (at the data1) and vice versa median1> median2 (at the data2)?

df <- data.frame(points1 = c(113,   145,    137,    73, 131,    137,    130,    45, 133,    119,
                             115,   127,    156,    141,    95, 119,    121,    120,    163,    134),
                 points2 = c(173,   216,    188,    0,  195,    215,    209,    62, 186,    206,    
                             194,   216,    207,    193,    244,    228,    217,    203,    204,    207)

    df8 <- data.frame(points1 = c(182,  123,    150,    97, 154,    155,    118,    144,    129,    121,                              153,  104,    153,    125,    151,    162,    170,    133,    126,    127, 165),
                      points2 = c(239,  198,    188,    218,    196,    177,    191,    167,    174,    187,    
                                  195,  180,    168,    205,    211,    208,    185,    189,    180,    144,    233))

boxplot(df$points1, df8$points1, df$points2, df8$points2, ylab ="Points", 
col = c("red", "green", "red", "green"), names = c("exp","con", "exp","con")) 

> # Brown-Mood median test
tmp1 <- data.frame(p1 = c(df$points1,df8$points1), 
g = factor(rep( c("exp", "con"), c(20, 21)))) 
(mt1 <- median_test(p1 ~ g, data = tmp1, alternative = "less", distribution = "exact"))

#        Exact Two-Sample Brown-Mood Median Test

#data:  p1 by g (con, exp)
#Z = 1.0842, p-value = 0.9211>0.05
#alternative hypothesis: true mu is less than 0

 tmp2 <- data.frame(p2 = c(df$points2,df8$points2), 
g = factor(rep( c("exp", "con"), c(20, 21)))) 

(mt1 <- median_test(p2 ~ g, data = tmp2, alternative = "less", distribution = "exact"))

#        Exact Two-Sample Brown-Mood Median Test

#data:  p2 by g (con, exp)
#Z = -1.3854, p-value = 0.1378>0.05
#alternative hypothesis: true mu is less than 0
  • 1
    $\begingroup$ Did you formulate this hypothesis before analyzing the data or in response to what you saw in the boxplots? $\endgroup$
    – whuber
    Apr 14, 2016 at 15:54
  • 1
    $\begingroup$ @whuber, thanks for comment. The experiment was directed on this situation, then I formulated the H0, and did the measures of data and plot the boxplot. $\endgroup$
    – Nick
    Apr 15, 2016 at 0:23
  • $\begingroup$ If your p-values are both > 0.05 why are you concluding a directional difference? $\endgroup$
    – Glen_b
    Apr 15, 2016 at 0:58
  • $\begingroup$ @Glen_b, p-values are both > 0.05 and H0 were rejected twice. But on the boxplot we can see that medians were swapped. I have tried to test H0 with different criterias based on the sum of ranks (Kruskal-Wallis, Wilcox). The Brown-Mood Median Test works with observed points, not ranks. I would like to show statistically that a directional difference exists. Is it possible? $\endgroup$
    – Nick
    Apr 15, 2016 at 1:43
  • $\begingroup$ May not have all the context, but it sounds like you want to show an increase for period_1 and a decrease for period_2. If that's the case, you're describing a cross-over interaction and a regular anova model should be able to handle it $\endgroup$
    – HEITZ
    Apr 15, 2016 at 5:51

1 Answer 1

  1. Did you notice that your code fails on the first line?

  2. You should not be rejecting a null hypothesis of equality of population medians ("The null hypothesis: median1= median2") when p-values are larger than your significance level, but rather when they are smaller than it.

  3. You seem to be trying to do a one tailed test based on the direction of observed difference (which is a complete no-no -- if you didn't specify the direction for the alternative before collecting the data, your test is two tailed), but then in any case it looks like you got the direction wrong on the second test. (Your explanation of what you're doing is very unclear throughout. We can't read your mind. You seem to use "period1" and "data1" to mean the same thing for example, and "con" and "df8" to mean the same thing. This is, to put it plainly, awful practice -- it's very hard to keep things straight if you're not consistent.)

  4. Your title suggests you're looking for a swap in direction, but your body text suggests the opposite (you test the same direction both times). You should make the actual question of interest more clear. Your whole discussion is very vague.

Here I do a straight randomization test of of no difference in population medians against a two tailed alternative, where the difference in sample medians is the test statistic; it should give somewhat similar results to a permutation test based on the Mood median test (and have equally poor power!).

enter image description here

At the 5% level, we would reject the null in the first instance but not the second.

(If instead of taking the absolute difference in medians as the test statistic we were to double the one-tailed p-value we'd get slightly different p-values but the conclusions at the same significance level would be the same)

Unless you're strongly wedded to the median as a measure of location I'd be more inclined to just use a straight Wilcoxon-Mann-Whitney


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.