Brighton Webs Ltd.
Statistics for Energy and the Environment
Home Index About

Quartiles

A set numbers, e.g. test scores, wind speed, height of women wearing red high heels can be divided into four equally sized groups by three values, the lower quartile, median and the upper quartile:

Minimum, Quartiles and Maximum

If your value is between the lower quartile and the median, you're in the second quartile.  25% of values are less than or equal to the lower quartile and 25% are greater than or equal to the upper quartile.  50% of values are between the lower quartile and the upper quartile and so on.

Example

Quartiles are an intuitive and convenient way of summarising a set of numbers.  Three values give an indication of the range, central tendency and dispersion. and simple way to compare datasets.  The graph below shows the distribution of wind speed at some location in the Northern Hemisphere.

Quartiles - Example Data

By adding the minimum and maximum values to give the extremes, the data can be summarised in five values:

Minimum 0 knots
Lower Quartile 3 knots
Median 5 knots
Upper Quartile 9 knots
Maximum 30 knots

Quartiles are often display graphically using a box-and-whisker diagram;

Quartiles - Box and Whisker Diagram

The diagram has been drawn to show the maximum and minimum values from the example dataset.  In some case, the maximum and minimum values are anomalies and it may be appropriate to use the 05/95 or 10/90 percentiles.

In the graphic below the monthly wind speed has been summarised as box-and-whisker diagrams.

Quartiles - Box and Whisker Time Series

This clear shows the nature of the seasonality of the wind speed at this location.  The median value is more or less constant, however, there is much greater variation in the upper quartile and maximum values.

Calculation

MS Excel and the GoogleDocs spreadsheet both have quartile functions.  These offer a relatively accessible way of creating consistent results.  There maybe differences in the methods used by various software packages.  The description below is more of interest for programmers who are building the functionality into software.

The first step in deriving the quartiles for a set numbers is to sort them into ascending order.

If the dataset is large (say, greater than 1,000 values), approximate values can be obtained from an array of N items, using integer division to get the array indexes::

Lower Quartile N\4
Median N\2
Upper Quartile (3*N)\4

For smaller datasets, the two stage Excel algorithm can be used.  The first step is to determine where to select the items and then, as this is unlikely to be an integer value, use linear interpolation to get the required values.

The sample data is a set of ten numbers:

3,5,7,8,10,13,15,16,17,19

Step 1 - Determine where to select:

Quartile Item Number Example Calc. Example Result
Lower 0.25*(N+3) 0.25*(10+3) 3.25
Median 0.50*(N+1) 0.50*(10+1) 5.50
Upper 0.25*(3*N+1) 0.25*(3*10+1) 7.75

Step 2 - Interpolation

In the example, the item numbers are not integers, to get the required values, we interpolate from the values with item numbers above and below the calculated values, e.g. the lower quartile is formed from items 3 and 4 which have the values 7 and 8, the interpolated value being 7.25.  The formula for this is:

Step 2 - Interpolation - Formula

The floor function returns the integer below N (e.g. floor(3.25) is 3) and the Ceiling function returns the integer above N (e.g. ceiling(3.25) is 4).  As always, this is clearer with an example:

Step 2 - Interpolation - Example

Spreadsheets

Both MS Excel and Google Doc's spreadsheet have a quartile function which determines the 1st, 2nd and 3rd quartiles together with the maximum and minimum values, e.g.

Sample formula Result
=quartile(A1:A100,0) Minimum
=quartile(A1:A100,1) Lower Quartile
=quartile(A1:A100,2) Median
=quartile(A1:A100,3) Upper Quartile
=quartile(A1:A100,4) Maximum

Similar results can also be obtained using the percentile function.

Page updated: 02-May-2012