Five-Number Summary¶
- five_number_summary(data, precision=4)¶
Calculates the five number summary of a given data set: minimum, first quartile, median, third quartile, and maximum
- Parameters
data (list of int or float) – List of numbers to analyze
precision (int, default=4) – Maximum number of digits that can appear after the decimal place of the result
- Raises
TypeError – First argument must be a 1-dimensional list
TypeError – Elements of first argument must be integers or floats
ValueError – Last argument must be a positive integer
- Returns
summary[‘minimum’] (float) – Smallest value from the data set
summary[‘q1’] (float) – First quartile of the data set, below which 25% of the data fall
summary[‘median’] (float) – Middle value of the data set, splitting the data evenly in half
summary[‘q3’] (float) – Third quartile of the data set, above which 25% of the data fall
summary[‘maximum’] (float) – Largest value from the data set
Notes
Set of numbers: \(a_i = \{ a_1, a_2, \cdots, a_n \}\)
Minimum: \(a_{min} \leq a_j, \forall a_j \in a_i\)
Maximum: \(a_{max} \geq a_j, \forall a_j \in a_i\)
For sets with an odd amount of numbers:
First quartile: \(Q_1 = a_{\lceil n/4 \rceil}\)
Median: \(M = a_{\lceil n/2 \rceil}\)
Third quartile: \(Q_3 = a_{\lceil 3n/4 \rceil}\)
For sets with an even amount of numbers:
If \(n \text{ mod } 4 \neq 0\):
First quartile: \(Q_1 = a_{\lceil n/4 \rceil}\)
Median: \(M = \frac{a_{n/2} + a_{n/2 + 1}}{2}\)
Third quartile: \(Q_3 = a_{\lceil 3n/4 \rceil}\)
If \(n \text{ mod } 4 = 0\):
First quartile: \(Q_1 = \frac{a_{n/4} + a_{n/4 + 1}}{2}\)
Median: \(M = \frac{a_{n/2} + a_{n/2 + 1}}{2}\)
Third quartile: \(Q_3 = \frac{a_{3n/4} + a_{3n/4 + 1}}{2}\)
Examples
- Import five_number_summary function from regressions library
>>> from regressions.statistics.summary import five_number_summary
- Determine the five number summary of the set [21, 53, 3, 68, 43, 9, 72, 19, 20, 1]
>>> summary_even = five_number_summary([21, 53, 3, 68, 43, 9, 72, 19, 20, 1]) >>> print(summary_even['q1']) 9.0 >>> print(summary_even['maximum']) 72.0
- Determine the five number summary of the set [12, 81, 13, 8, 42, 72, 91, 20, 20]
>>> summary_odd = five_number_summary([12, 81, 13, 8, 42, 72, 91, 20, 20]) >>> print(summary_odd['q3']) 76.5 >>> print(summary_odd['minimum']) 8.0