Solved – Find interquartile range of these data

descriptive statisticsinterquartilemedianr

Take these data:

5, 8, 9, 14

R says the interquartile range is 3:

IQR(c(5, 8, 9, 14))
# 3

…but I make it 5. What am I doing wrong? Here are the steps I've taken:

  1. Find median, which is 8.5
  2. Split the data around the median into two groups, like this: (5, 8), (9, 14)
  3. Find the median of these two groups, which are 6.5 and 11.5, respectively
  4. Subtract 6.5 from 11.5, which yields 5

Best Answer

Your difficulty is that in order to find IQR you must first find the two quartiles. And there are many different formulas for quantiles (including quartiles) in common use.

In particular, major statistical software packages disagree on which methods to implement as their default: (a) SAS, (b) Minitab and SPSS, and (c) R (and its parent S) use three different methods. Furthermore, these methods differ from methods found in reputable elementary texts. (Adding to the confusion: Tukey's 'fourths', sometimes used in making boxplots and often considered essentially the same as quartiles, use yet other criteria.)

Generally speaking the differences among these methods become negligible for large sample sizes. However, there can be marked differences for small samples. Fortunately, it is for large samples that quantiles make the most sense. (Roughly, quartiles are intended to divide a sample into four 'chunks' of equal size: how do you do that with a sample of size 10?)

In R, you can type ? quantile to see the nine different types of quantiles supported by R (using an extra argument), mentioned just now by @EdM. The default result from quantile is min, Q1, med, Q3, max, so once you have selected a type you could define your own IQR function based on the idea in the @Glen_b Comment and code like as.numeric(diff(quantile(x, type=5)[c(2,4)])).

Related Question