STATISTICAL WORKSHEETS

Checking a quartile that falls between observed values

Follow the linear interpolation rule on a four-value list to see why a quartile can land between observations, then compare a five-value list where it does not.

The rule this calculator implements

The Quartile Calculator uses linear interpolation between order statistics, known as Hyndman and Fan type 7. For a sorted list of n values, the position for a probability p is h equal to (n minus 1) times p, counted from zero. The quantile is the value at the whole-number part of h, plus the fractional part of h times the gap to the next value. For quartiles, p is 0.25, 0.5 and 0.75. This is the default method in R and in NumPy's linear option, and it matches the inclusive quartile and percentile functions in common spreadsheets. It is one convention among several, so naming it matters when results are compared. Hyndman and Fan numbered the conventions from 1 to 9, and type 7 is the one this page describes. The same rule gives percentiles through p equal to the percentile divided by 100.

The four-value list 1, 2, 3, 4

With n equal to 4, the positions are h equal to 3 times 0.25, which is 0.75, then 1.5, then 2.25. The first quartile lies three quarters of the way from the first value to the second: 1 plus 0.75 times 1, which is 1.75. The median sits halfway between the second and third values, 2.5. The third quartile is a quarter of the way from the third value to the fourth: 3 plus 0.25 times 1, which is 3.25. The tool returns 1.75, 2.5 and 3.25. None of the three quartiles is a value from the input, though all lie within its range. The interquartile range, third quartile minus first, is 1.5 for this list. The input does not have to be sorted or free of ties, and the tool orders it before applying the rule, so entering 4, 2, 1, 3 gives the same quartiles.

The five-value list 1, 2, 3, 4, 5

With n equal to 5, the positions are 4 times 0.25, which is 1, then 2, then 3. These are whole numbers, so the quartiles coincide with observations. The first quartile is the second value, 2. The median is the third, 3. The third quartile is the fourth, 4. The tool returns 2, 3 and 4. A list whose length is one more than a multiple of four always places its quartile positions on observations, which is why this control is useful as a comparison with the even list above.

An uneven list with six values

Take 3, 5, 8, 13, 21 and 34, where n is 6 and (n minus 1) is 5. The first quartile position is 1.25, between the second value, 5, and the third, 8: 5 plus 0.25 times 3, which is 5.75. The median position is 2.5, halfway between 8 and 13, giving 10.5. The third quartile position is 3.75, between 13 and 21: 13 plus 0.75 times 8, which is 19. The three quartiles are 5.75, 10.5 and 19. The interquartile range, third minus first, is 13.25. Positions that fall between values are common, and the answers are sensitive to the interpolation weights.

Why quartile methods disagree

Statistical software offers at least nine documented ways to compute sample quantiles, described by Hyndman and Fan in a 1996 paper in The American Statistician. Some pick observed values, some average neighbors, and some interpolate at different positions. For the list 1, 2, 3, 4, a method that takes the median of each half returns a first quartile of 1.5 and a third quartile of 3.5, while this tool returns 1.75 and 3.25. Neither is wrong. The disagreement is about the convention, and it shrinks as the list gets longer. Always record the method with the list when you exchange quartiles. In a long list of, say, 1,000 values, the methods usually differ in the second or third decimal place or not at all, so the choice matters mainly for short lists like the ones on this page.

Matching the method when you compare software

When your result differs from another package, check the method before suspecting an error. Spreadsheets provide an inclusive quartile function that follows type 7, and an exclusive version that uses a different position rule and can differ noticeably on short lists. Some textbooks teach the median-of-halves method. To compare, run a small list such as 1, 2, 3, 4 through both tools: a first quartile of 1.75 identifies this convention. Keeping that test list on hand is a quick way to identify which rule an unfamiliar tool uses.

Where quartiles come from historically and in practice

Quartiles belong to the family of quantiles, which divide a sorted list into parts of equal proportion. The box plot, introduced by John Tukey in the 1970s as part of exploratory data analysis, draws a box from the first to the third quartile with a line at the median. The outlier rule that appears on another page of this site uses the same quartiles to set its fences. Reports of income, response time and test scores often quote quartiles because the middle half of the data is easier to describe than the whole distribution, and because it is resistant to a few unusual values.

Using quartiles in summaries

Quartiles describe the middle half of a distribution without being pulled by extreme values. They form the basis of the box plot and of the interquartile range, a spread measure that is resistant to outliers. Because the values can be interpolated, a quartile should not be described as a data point that someone observed. When reporting, say that the first quartile is the value below which about a quarter of the data lies under the stated method. For small samples the position rule can change the figure enough to affect a conclusion.

What the examples cover

The two controls show the position formula at work on an even-length list and an odd-length list. They do not suggest that any particular method is preferable, and they do not evaluate the data. The calculator sorts the values, applies the rule and returns the three quartiles. It does not detect data entry errors or missing values, so check the list for mistakes before interpreting the result. A stray extra digit in one entry can move a quartile on a short list by a visible amount, and the tool has no way to tell that it was a typo.

Reproduce the checks

Even list with interpolated positions

Open the Quartile Calculator and enter:

Numbers
1,2,3,4

Expected output:

Q1

1.75

Q2

2.5

Q3

3.25

Quarter positions lie between observations.

Odd equally spaced control

Open the Quartile Calculator and enter:

Numbers
1,2,3,4,5

Expected output:

Q1

2

Q2

3

Q3

4

The quarter positions now coincide with observations.

References and implementation scope

The examples describe the behavior of the linked Computandum tools. A successful local check does not establish that another application accepts the same format or applies the same limits.

Sources

Related tasks