# 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:

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
• You have computed something called the "H-spread" (Tukey, Exploratory Data Analysis, p. 44).
– whuber
Sep 6 '14 at 19:38
• The hinge spread (or H-spread) is not identical to the most usual definitions of the IQR in small samples. If you want R to compute the hinge spread specifically (say for a box-plot), you can use $\hspace{2cm}$ diff(fivenum(x)[c(2,4)]). On your data (diff(fivenum(c(5,8,9,14))[c(2,4)])) that gives 5. Sep 6 '14 at 23:55
• The R IQR function calls the quantile function, which in turn has 9 different algorithms (with one of them used as default if you don't specify your own choice). Results from these algorithms can differ with small data sets such as yours. The R Help pages for IQR and quantile provide the details.
– EdM
Sep 8 '14 at 15:09

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)])).