4
$\begingroup$

I have plotted the boxplots of the distributions of certain groups and I was bewildered to see that the means appear outside the boxplots. How could this be explained?

Since boxplots are a mainstream visualization technique of distributions, I felt that my question fit the scope of this Forum.

My code is the following:

fun_mean <- function(x){
  return(data.frame(y=round(mean(x), digits = 3),label=mean(x,na.rm=T)))}

ggplot(my_data, aes(x = as.factor(viotiko), y = pd_1year, fill = as.factor(viotiko))) + geom_boxplot() +
  labs(title="Does the PD differ significantly by 'Viotiko' group?",x="Viotiko Group", y = "PD (pd_1year)") +
  coord_cartesian(ylim = c(0,0.05))  + stat_summary(fun.y = mean, geom="point",colour="darkred", size=3) +
  stat_summary(fun.data = fun_mean, geom="text", vjust=-0.7)

The boxplot is the one shown below (I apologize for the cluttering of the text depicting means but I am still searching a way to repair this.)

boxplot depicting means as red asterisks

Your advice will be appreciated.

$\endgroup$
  • 7
    $\begingroup$ Boxplots aren't supposed to display means: they display medians. There is no general relationship between these two summaries of data. By clipping off the extremely high outliers at the tops of your boxes, you have obscured the evidence that your means ought to be substantially greater than your medians. $\endgroup$ – whuber Mar 24 '17 at 18:17
  • 2
    $\begingroup$ Excellent points from @whuber. Further, box plots often disappoint with very skewed distributions if the idea is that they are the final presentation graph. Much of their point is to be exploratory and show you broad characteristics of distributions that then suggest or imply looking at them on a transformed scale. Although you're naturally concerned with the high values, note that in 6 out of 9 groups there is no lower tail, i.e. at least 25% of values are equal to the minimum. What might work better is one or more of working on logarithmic scale, histograms and quantile plots. $\endgroup$ – Nick Cox Mar 24 '17 at 18:54
  • 1
    $\begingroup$ Guessing a bit more, there seems to some granularity in the data, whereby multiples of 0.09 or so occur. Else why are 6 of the medians equal to each other? Where such fine structure exists, a spikeplot representation can help. stats.stackexchange.com/questions/86297/… $\endgroup$ – Nick Cox Mar 24 '17 at 18:56
  • 1
    $\begingroup$ See stats.stackexchange.com/questions/140090/… for another example in which there were many ties for minimum and one way to show that explicitly. $\endgroup$ – Nick Cox Mar 24 '17 at 19:05
5
$\begingroup$

The box bounds are at the upper and lower hinges, which may be thought of as a particular definition of sample upper and lower quartiles.

It's quite easy for sample means to fall above the upper quartile or below the lower quartile. Note in particular that if you have a few large observations that can pull the mean up without necessarily affecting the quartiles at all. (Samples where this tends to happen would typically be described as skewed -- specifically, when you have enough large values to pull the mean above the upper quartile, you'd usually describe it as right-skew.)

Look what happens with these 9 numbers as a sample:

 1   2    3    4    5    6   7   8    9

The lower hinge is 3, the upper hinge is 7 and the mean and median are both 5. Now move those two largest observations up to 13 and 23 (say)

 1   2    3    4    5    6   7   13   23

Now the median and the hinges/quartiles are the same as before (3,5,7) but the mean is now just above 7, so it would fall outside the box.

boxplot with mean added showing how in the second case the mean moves above the upper hinge

[The boxplot of the top sample is symmetric, so the mean is right in the middle. The lower boxplot has had its two largest values moved up, which affects the mean, and now it appears to be right-skewed, in a way that leaves the mean "outside the box". Similarly, if the lowest values were sufficiently low, they could pull the mean below the box.]

If you move the two largest observations (or even just the largest one) higher still, the mean can be pulled as far away from the box as you like - it can be any number of interquartile ranges above the upper quartile. The median and hinges (/quartiles) are not affected by extreme values (as long as there's no more than $\lfloor (n-1)/4 \rfloor$ of them), but the mean certainly is.

$\endgroup$
2
$\begingroup$

The bounds of a boxplot are the lower and upper quartiles of the data, so the mean will be outside the boxplot so long as it's under the lower quartile or over the upper quartile. A simple example is the vector $(0, 1, 2, 3, 100)$. Here, the quartiles are $(1, 2, 3)$, but the mean is $21.2$, which is much greater than $3$.

$\endgroup$
  • $\begingroup$ Almost everyone here should know what you mean, but "lower" and "upper" are more common terms for quartiles than bottom and top and thus preferable. It would be unconventional, but in my view it wouldn't be crazy, to regard the minimum as the bottom quartile and the maximum as the top; that is one reason why those words are not quite so good. $\endgroup$ – Nick Cox Mar 24 '17 at 20:27
  • $\begingroup$ @NickCox: Okay. $\endgroup$ – Kodiologist Mar 25 '17 at 0:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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