IQR Calculator

Methodology

The formulas, conventions, rounding rules and testing behind every number this site produces.

Where calculations happen

This page is the technical companion to what the site is and is not. It records the exact formula behind every number, so a result you disagree with can be traced to a convention rather than argued about.

All of them run in your browser, in JavaScript, using the double-precision floating-point arithmetic the language provides. No data is transmitted anywhere. There is no calculation API and no server-side computation.

Two exceptions to plain floating point: factorials, combinations and permutations use arbitrary-precision integers so their results are exact to the last digit, and every summation uses compensated (Neumaier) addition so that long or badly scaled data sets do not accumulate rounding error.

Quartile conventions

Quartiles have no single agreed definition. Four conventions are in common use and they disagree on ordinary data. All four are implemented. With sorted data x[1..n] and p being 0.25 or 0.75:

MethodRuleMatches
ExclusiveSplit at the median; for odd n the median joins neither half. Q1 and Q3 are the medians of the halves.TI-83/84 1-Var Stats; Moore & McCabe; AP Statistics
InclusiveSplit at the median; for odd n the median joins both halves. These are Tukey's hinges.R fivenum()
Interpolation p(n+1)Value at rank p(n+1), interpolating linearly between neighbours.NIST handbook; Excel QUARTILE.EXC; R quantile(type=6)
Interpolation (n−1)p+1Value at rank (n−1)p+1, interpolating linearly between neighbours.Excel QUARTILE.INC; Google Sheets; NumPy; pandas; R quantile(type=7)

The default is Exclusive. It is the rule taught in most introductory courses, the one a TI-84 returns, and therefore the answer most visitors are checking against. It is stated on the page rather than assumed, and the alternatives are one click away.

For even n, Exclusive and Inclusive always agree. They can only differ when n is odd.

A note on the words "exclusive" and "inclusive"

These two words are used inconsistently across the web. Some tools apply them to the halves rules above; others apply them to Excel's .EXC and .INC functions, which are the two interpolation rules and have nothing to do with whether the median joins a half. This site uses those words only for the halves rules, and names interpolation methods by their rank formula.

Percentiles

Three conventions are offered: the two interpolation rules above, plus nearest rank, which takes the value at position ceil(p × n) with no interpolation and therefore always returns a value that occurs in the data. The default is (n−1)p+1, matching the most widely deployed implementations.

Percentile rank — the inverse question — uses the mid-rank convention for ties: values strictly below count fully and tied values count as half, so rank = (below + 0.5 × equal) ÷ n × 100. This is the definition that places a value tied with the entire data set at the 50th percentile rather than the 0th or 100th.

Outlier fences

lower fence = Q1 − k × IQR upper fence = Q3 + k × IQR k = 1.5 flags outliers; k = 3 flags extreme outliers. Values exactly on a fence are not flagged.

Box-plot whiskers extend to the furthest value still inside the fences; values beyond are plotted individually. This is the modified box plot, which is what statistical software draws by default.

Sample and population

Where the distinction exists it is exposed as an explicit control and never guessed.

Population variance σ² = Σ(x − μ)² ÷ N Sample variance s² = Σ(x − x̄)² ÷ (n − 1)

Standard deviation is the square root of the corresponding variance. The sample default uses the n − 1 divisor (Bessel's correction). Sample variance is reported as undefined, not zero, when n = 1, because the divisor would be zero.

Rounding policy

  • Every calculation is carried out at full double precision. Rounding happens only at display time, never between steps — so intermediate values shown in the working are display roundings of the full-precision numbers actually used.
  • Results are normalised to 12 significant digits before display, which removes binary representation artefacts such as 0.1 + 0.2 showing as 0.30000000000000004.
  • Values are then shown to at most 6 decimal places, with trailing zeros stripped. Integers are shown without a decimal point.
  • Values at or above 10¹² in magnitude, or below 10⁻⁶ and non-zero, switch to scientific notation.
  • Negative zero is displayed as 0.

Input handling

Values may be separated by commas, spaces, tabs, newlines or semicolons, in any mixture, with optional surrounding brackets. Decimals, negatives and scientific notation are accepted.

Comma ambiguity is resolved by inspection rather than assumption. 1,234 is read as two values, because that is what a comma normally means here. It is read as one value only when some other separator is already delimiting the list and every comma in the input sits in a thousands position — and when that happens, the calculator says so rather than deciding silently.

Non-numeric tokens are skipped and named in a notice rather than causing a failure, so one stray label in a pasted column does not discard the rest of the data. The hard limit is 100,000 values.

Testing

The engine is covered by a suite of explicit fixtures run with the Node test runner. Every expected value was derived independently of the implementation — by hand from the published definition of the method, or from a documented worked example in a primary source, with the source cited in the test.

Coverage includes odd and even counts, negative and decimal values, duplicates, zero variance, single-value and empty inputs, values on and beyond the fences, both tails of the outlier rule, all four quartile methods on data sets chosen to make them disagree, and malformed input of every kind the parser accepts or rejects.

One fixture exists specifically to guard against an error published on the previous version of this domain, which stated that the median of 10, 15, 20, 25, 30, 35, 40, 45, 50, 55 was 30. It is 32.5.

Sources

Corrections

If a result here disagrees with a source you trust, that is worth knowing about. Send the data set, the tool, the method selected and the answer you expected to [email protected]. Genuine errors are fixed and noted.