Find interquartile range of these data 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:


*

*Find median, which is 8.5

*Split the data around the median into two groups, like this: (5, 8), (9, 14)

*Find the median of these two groups, which are 6.5 and 11.5, respectively

*Subtract 6.5 from 11.5, which yields 5
 A: 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)])).
