I have the following data (ordered):

$$0, 1, 1, 2, 3, 4, 4, 7, 9, 23.$$

As far as I know, $Q_1 \text{(median of the upper half)} = 1$; $Q_3 \text{(median of the lower half)} = 7$; Therefore, $\text{IQR} = Q_3-Q_1 = 6$.

But when I boxplot this simple data in 'R', the summary says that, $Q_1 = 1.25$, $Q_3 = 6.25$, and consequently, $\text{IQR} = 6.25-1.25 = 5$!! How is that? I don't think we can question the statistical computation by "R" anyway ... Can anyone tell me what is wrong?

  • 1
    $\begingroup$ This question is probably better suited for stackoverflow: the answer has nothing to do with Mathematics, only the way R calculates the IQR. $\endgroup$ – George V. Williams Feb 15 '13 at 17:48
  • $\begingroup$ Maybe you should read the R manual to see how it computes the quartiles? Note that your interquartile range includes $7$ or $6$ of the numbers in your data set (including the endpoints), while R's range had $5$ out of the $10$ numbers in your data set. $\endgroup$ – Dilip Sarwate Feb 15 '13 at 17:48

R uses the quantile function to do IQR:

Note that this function computes the quartiles using the quantile function rather than following Tukey's recommendations, i.e., $IQR(x) = \mathrm{quantile}(x, 3/4) - \mathrm{quantile}(x, 1/4)$.

  • $\begingroup$ What is Tukey's recommendation? - what you wrote in the "i.e" or something other than that? $\endgroup$ – alancalvitti Feb 15 '13 at 18:08
  • $\begingroup$ I didn't write that, that's a quote from R's documentation. Tukey's recommendation is the $Q_3 - Q_1$. However, there's other definitions of the interquartile range than that. $\endgroup$ – George V. Williams Feb 15 '13 at 18:20
  • $\begingroup$ I noticed it here: inside-r.org/r-doc/stats/IQR $\endgroup$ – ToNoY Feb 15 '13 at 18:20
  • $\begingroup$ @ToNoY, Like I said, Tukey's recommendation is $Q_3 - Q_1$, just like you did. However R does something different to compute the IQR. $\endgroup$ – George V. Williams Feb 15 '13 at 18:21
  • $\begingroup$ @GeorgeV.Williams: Thanks, I just found it in detail from a answer in superuser as you can see from the link below. But is it worth doing it by hand the way R or excel does the computation? $\endgroup$ – ToNoY Feb 15 '13 at 18:33

The answer can be found here (excel also does the same thing):



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.