Method and source check
Last checked:
Automated source and implementation review, including worked examples and documented numerical limits. This review does not provide professional advice or specialist approval.
Method
Sort finite values, average the two middle values for even count, and compute Q1 and Q3 by linear interpolation at zero-based position (n−1)p for p=.25 and .75; IQR is Q3−Q1.
median = middle sorted value (odd n) or average of two middle values (even n)
Q(p) = linear interpolation at position (n−1)p
IQR = Q3−Q1
Variables and units
- n
- number of values
- p
- quantile proportion (.25 or .75)
- Q1,Q3
- first and third quartiles
Worked example
For sorted data 1,2,3,4, median is 2.5, Q1 is 1.75, Q3 is 3.25, and IQR is 1.5.
Limitations
Median, quartiles, IQR, and listed values are shown to four decimal places. Math.round retains the existing half-tie convention; if scaling for four-place rounding would overflow, the finite representable value is retained. Locale formatting is applied after numerical calculation.
- Quartile methods vary between references and software; values can differ for small data sets.
- This page uses (n−1)p interpolation, not the median-of-halves method.
- Derived values outside the supported finite numerical range are rejected with a localized input-field error.
- At least two finite values are required.
- For 1,2,3,4,5 the median is 3, Q1 is 2, Q3 is 4.