# Interquartile range

In descriptive statistics, the interquartile range (IQR) is a measure of statistical dispersion, which is the spread of the data. The IQR may also be called the midspread, middle 50%, fourth spread, or H‑spread. It is defined as the difference between the 75th and 25th percentiles of the data. To calculate the IQR, the data set is divided into quartiles, or four rank-ordered even parts via linear interpolation. These quartiles are denoted by Q$_1$ (also called the lower quartile), Q$_2$ (the median), and Q$_3$ (also called the upper quartile). The lower quartile corresponds with the 25th percentile and the upper quartile corresponds with the 75th percentile, so IQR = Q$_3$ − Q$_1$$_.$
The IQR is an example of a trimmed estimator, defined as the 25% trimmed range, which enhances the accuracy of dataset statistics by dropping lower contribution, outlying points. It is also used as a robust measure of scale It can be clearly visualized by the box on a box plot.

## Use

Unlike total range, the interquartile range has a breakdown point of 25% and is thus often preferred to the total range.
The IQR is used to build box plots, simple graphical representations of a probability distribution.
The IQR is used in businesses as a marker for their income rates.
For a symmetric distribution (where the median equals the midhinge, the average of the first and third quartiles), half the IQR equals the median absolute deviation (MAD).
The median is the corresponding measure of central tendency.
The IQR can be used to identify outliers (see below). The IQR also may indicate the skewness of the dataset.
The quartile deviation or semi-interquartile range is defined as half the IQR.

## Algorithm

The IQR of a set of values is calculated as the difference between the upper and lower quartiles, Q$_3$ and Q$_1$. Each quartile is a median calculated as follows.
Given an even 2n or odd 2n+1 number of values
    first quartile Q$_1$ = median of the n smallest values
    third quartile Q$_3$ = median of the n largest values
The second quartile Q$_2$ is the same as the ordinary median.

## Examples
### Data set in a table

The following table has 13 rows, and follows the rules for the odd number of entries.
| i | x[i] | Median | Quartile |
| 1 | 7 | Q$_2$=87 (median of whole table) | Q$_1$=31 (median of lower half, from row 1 to 6) |
| 2 | 7 | Q$_2$=87 (median of whole table) | Q$_1$=31 (median of lower half, from row 1 to 6) |
| 3 | 31 | Q$_2$=87 (median of whole table) | Q$_1$=31 (median of lower half, from row 1 to 6) |
| 4 | 31 | Q$_2$=87 (median of whole table) | Q$_1$=31 (median of lower half, from row 1 to 6) |
| 5 | 47 | Q$_2$=87 (median of whole table) | Q$_1$=31 (median of lower half, from row 1 to 6) |
| 6 | 75 | Q$_2$=87 (median of whole table) | Q$_1$=31 (median of lower half, from row 1 to 6) |
| 7 | 87 | Q$_2$=87 (median of whole table) | |
| 8 | 115 | Q$_2$=87 (median of whole table) | Q$_3$=119 (median of upper half, from row 8 to 13) |
| 9 | 116 | Q$_2$=87 (median of whole table) | Q$_3$=119 (median of upper half, from row 8 to 13) |
| 10 | 119 | Q$_2$=87 (median of whole table) | Q$_3$=119 (median of upper half, from row 8 to 13) |
| 11 | 119 | Q$_2$=87 (median of whole table) | Q$_3$=119 (median of upper half, from row 8 to 13) |
| 12 | 155 | Q$_2$=87 (median of whole table) | Q$_3$=119 (median of upper half, from row 8 to 13) |
| 13 | 177 | Q$_2$=87 (median of whole table) | Q$_3$=119 (median of upper half, from row 8 to 13) |
For the data in this table the interquartile range is IQR = Q$_3$ − Q$_1$ = 119 - 31 = 88.

### Data set in a plain-text box plot

For the data set in this box plot:
* Lower (first) quartile Q$_1$ = 7
* Median (second quartile) Q$_2$ = 8.5
* Upper (third) quartile Q$_3$ = 9
* Interquartile range, IQR = Q$_3$ - Q$_1$ = 2
* Lower 1.5*IQR whisker = Q$_1$ - 1.5 * IQR = 7 - 3 = 4. (If there is no data point at 4, then the lowest point greater than 4.)
* Upper 1.5*IQR whisker = Q$_3$ + 1.5 * IQR = 9 + 3 = 12. (If there is no data point at 12, then the highest point less than 12.)
* Pattern of latter two bullet points: If there are no data points at the true quartiles, use data points slightly "inland" (closer to the median) from the actual quartiles.
This means the 1.5*IQR whiskers can be uneven in lengths. The median, minimum, maximum, and the first and third quartile constitute the Five-number summary.

## Distributions

The interquartile range of a continuous distribution can be calculated by integrating the probability density function (which yields the cumulative distribution function—any other means of calculating the CDF will also work). The lower quartile, Q$_1$, is a number such that integral of the PDF from -∞ to Q$_1$ equals 0.25, while the upper quartile, Q$_3$, is such a number that the integral from -∞ to Q$_3$ equals 0.75; in terms of the CDF, the quartiles can be defined as follows:
    $Q_{1}={\text{CDF}}^{-1}(0.25),$
    $Q_{3}={\text{CDF}}^{-1}(0.75),$
where CDF$^{−1}$ is the quantile function.
The interquartile range and median of some common distributions are shown below
| Distribution | Median | IQR |
| Normal | μ | 2 Φ$^{−1}$(0.75)σ ≈ 1.349σ ≈ (27/20)σ |
| Laplace | μ | 2b ln(2) ≈ 1.386b |
| Cauchy | μ | 2γ |

### Interquartile range test for normality of distribution

The IQR, mean, and standard deviation of a population P can be used in a simple test of whether or not P is normally distributed, or Gaussian. If P is normally distributed, then the standard score of the first quartile, z$_1$, is −0.67, and the standard score of the third quartile, z$_3$, is +0.67. Given mean = ${\bar {P}}$ and standard deviation = σ for P, if P is normally distributed, the first quartile
    $Q_{1}=(\sigma \,z_{1})+{\bar {P}}$
and the third quartile
    $Q_{3}=(\sigma \,z_{3})+{\bar {P}}$
If the actual values of the first or third quartiles differ substantially from the calculated values, P is not normally distributed. However, a normal distribution can be trivially perturbed to maintain its Q1 and Q2 std. scores at 0.67 and −0.67 and not be normally distributed (so the above test would produce a false positive). A better test of normality, such as Q–Q plot would be indicated here.

## Outliers

The interquartile range is often used to find outliers in data. Outliers here are defined as observations that fall below Q1 − 1.5 IQR or above Q3 + 1.5 IQR. In a boxplot, the highest and lowest occurring value within this limit are indicated by whiskers of the box (frequently with an additional bar at the end of the whisker) and any outliers as individual points.