Foundations to Frontier
Tests
A. Mathematical Foundations › A5 Statistics › Descriptive and inferential statistics

Descriptive Statistics and Data Visualization

Before modelling data, describe it and look at it. Location (mean, median, trimmed mean), spread (sd, IQR, MAD), shape (skewness, kurtosis) and the pictures that show what numbers hide: histograms, boxplots, kernel density estimates and scatter plots. You will learn which summaries survive outliers (robustness and breakdown points), compute variance stably in one pass (Welford), pick histogram bins and KDE bandwidths, and see from Anscombe's quartet why every analysis should start with a plot, then apply robust z-scores to spike detection in telemetry.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

The “average” robot can mislead you

Ten delivery robots finish their routes in 20, 21, 22, 22, 23, 23, 24, 25, 26 and 190 minutes. One robot got stuck. The mean time is 39.6 minutes, longer than nine of the ten robots took! The median, the middle value, is 23 minutes, much closer to what a typical robot does.

Statistics starts with describing data honestly: a typical value, how spread out the values are, and whether anything weird is going on. And always draw a picture, because very different data can share the same summary numbers.

Summaries vs pictures: what outliers do to the mean and sd
n = 500 · mean 9.99 vs median 9.92 · sd 2.11 vs 1.4826·MAD 2.18 · IQR 2.92 · skewness 0.14 · 1 points beyond Tukey's fences
Orange line: mean. Green dashed: median. Below: a boxplot (box = quartiles, whiskers to the last point within 1.5·IQR, dots beyond). Add a few outliers and watch the mean and sd jump while the median and MAD hardly move. For a bimodal shape no single summary describes it, so always look at the picture.
Why engineers care

Telemetry from a spacecraft, timing logs from a robot, or benchmark scores for a model: the first step is always to summarize and plot. A single stuck sensor or crashed run can wreck an average and hide a real problem, or create a fake one.

📝 Quick check (Level 0)
0/3 answered
  1. 1. Which is less affected by one huge value?
  2. 2. Times 20, 21, 22, 190: the mean is…
  3. 3. Before trusting summary numbers you should…

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

Location

  • Mean: xˉ=1n∑xi\bar x = \frac1n\sum x_i.
  • Median: the middle of the sorted data, or the average of the two middle values.
  • Mode: the most frequent value.
  • Trimmed mean: drop the top and bottom 10% (say), then average.

Spread

  • Sample variance: s2=1n−1∑(xi−xˉ)2s^2 = \frac1{n-1}\sum(x_i - \bar x)^2. Dividing by n−1n - 1 makes it unbiased (A5.1-3). The standard deviation is ss.
  • Quantiles: Q1Q_1, the median, Q3Q_3. The IQR is Q3−Q1Q_3 - Q_1.
  • MAD: median⁡∣xi−median⁡(x)∣\operatorname{median}\lvert x_i - \operatorname{median}(x)\rvert. For normal data, 1.4826⋅MAD≈σ1.4826\cdot\text{MAD}\approx\sigma and IQR≈1.349σ\text{IQR}\approx1.349\sigma.

Shape

  • Skewness: 1n∑(x−xˉ)3s3\frac{\frac1n\sum(x - \bar x)^3}{s^3}. Positive means a long right tail, and then the mean is usually above the median.
  • Excess kurtosis: 1n∑(x−xˉ)4s4−3\frac{\frac1n\sum(x - \bar x)^4}{s^4} - 3. Positive means heavier tails than a normal.

Pictures

  • Histogram: counts in bins.
  • Boxplot: quartiles, with whiskers out to 1.5 IQR and points beyond them drawn individually (Tukey, 1977).
  • Scatter plot: for pairs of variables.
  • Time-series plot: for sensor streams.
📝 Quick check (Level 1)
0/3 answered
  1. 1. For normal data, IQR ≈
  2. 2. A long right tail usually puts the mean…
  3. 3. The sample variance divides by…

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 40 minUndergraduate students and practising engineers.

Robustness

The breakdown point is the fraction of data that can be made arbitrarily bad before the estimate goes arbitrarily wrong.

Estimate Breakdown point
mean, sd 0 (one bad point is enough)
10%-trimmed mean 10%
median, MAD 50% (the maximum possible)
IQR 25%

With 5% stuck-sensor values at 500 in data centred at 10, the mean jumps to about 33 while the median stays at 10.1 (Exercise 1).

Robust z-scores zi=(xi−med⁡)/(1.4826 MAD)z_i = (x_i - \operatorname{med})/(1.4826\,\text{MAD}) flag outliers reliably. Ordinary z-scores suffer from masking: the outliers inflate the sd and hide themselves.

Computing variance correctly

The “textbook” formula ∑x2−(∑x)2/nn−1\frac{\sum x^2 - (\sum x)^2/n}{n - 1} subtracts two huge, nearly equal numbers, and for data like 109+noise10^9 + \text{noise} it returns garbage. Welford’s algorithm updates the mean and the sum of squared deviations in one stable pass: δ=x−xˉ\delta = x - \bar x, xˉ+=δ/n\bar x\mathrel{+}=\delta/n, M2+=δ(x−xˉ)M_2\mathrel{+}=\delta(x - \bar x) (Welford, 1962). It’s ideal for streaming telemetry.

Choosing bins and bandwidths

  • Sturges: ⌈log⁡2n+1⌉\lceil\log_2n + 1\rceil bins. It’s fine for small nn but oversmooths large samples.
  • Freedman–Diaconis: width h=2 IQR n−1/3h = 2\,\text{IQR}\,n^{-1/3}. Robust, and it scales properly with nn.
  • Kernel density estimates: f^(x)=1nh∑K(x−xih)\hat f(x) = \frac1{nh}\sum K\big(\frac{x - x_i}h\big). Silverman’s rule h=0.9min⁡(s,IQR/1.349)n−1/5h = 0.9\min(s, \text{IQR}/1.349)n^{-1/5} is a good default that oversmooths multimodal data.
🐍 Exercise 1: classical vs robust summaries, and a stable one-pass variance
Implement quantiles, a summary (mean, median, sd, scaled MAD, IQR, 10%-trimmed mean, skewness, excess kurtosis) and Welford's algorithm. Check the summaries on normal data, then add 5% stuck-at-500 outliers and see which summaries break down.
📝 Quick check (Level 2)
0/3 answered
  1. 1. The median's breakdown point is…
  2. 2. Ordinary z-scores can fail to flag many outliers because…
  3. 3. The Freedman–Diaconis bin width scales like…

Level 3: Advanced

★★★★☆ Advanced⏱ 40 minGraduate level, with full derivations and proofs.

Why the mean and the median minimize different losses

xˉ=arg⁡min⁡c∑(xi−c)2,median⁡=arg⁡min⁡c∑∣xi−c∣\bar x = \arg\min_c\sum(x_i - c)^2, \qquad \operatorname{median} = \arg\min_c\sum\lvert x_i - c\rvert
  • Mean. The derivative of the squared loss, −2∑(xi−c)-2\sum(x_i - c), vanishes at xˉ\bar x.
  • Median. The subgradient of the absolute loss, #{xi>c}−#{xi<c}\#\{x_i > c\} - \#\{x_i<c\}, changes sign at the median.

Squared loss lets one far point pull the estimate without limit. Absolute loss gives each point a bounded “vote”. Huber’s loss interpolates between the two and underlies robust regression and M-estimators (Huber, 1964).

Welford is exact

By induction, if xˉn−1\bar x_{n-1} and M2,n−1=∑i<n(xi−xˉn−1)2M_{2,n-1} = \sum_{i<n}(x_i - \bar x_{n-1})^2 are correct, then xˉn=xˉn−1+δ/n\bar x_n = \bar x_{n-1} + \delta/n. Expanding ∑i≤n(xi−xˉn)2\sum_{i\le n}(x_i - \bar x_n)^2 gives M2,n=M2,n−1+δ(xn−xˉn)M_{2,n} = M_{2,n-1} + \delta(x_n - \bar x_n), with δ=xn−xˉn−1\delta = x_n - \bar x_{n-1}. Each step involves only deviations of moderate size, so there’s no catastrophic cancellation. Chan, Golub and LeVeque (1983) give the parallel-merge version used in distributed systems.

KDE bias and variance

For smooth ff, Ef^(x)−f(x)≈h22f′′(x)∫u2K\mathbb E\hat f(x) - f(x)\approx\frac{h^2}2f''(x)\int u^2K and Var⁡f^(x)≈f(x)nh∫K2\operatorname{Var}\hat f(x)\approx\frac{f(x)}{nh}\int K^2. Balancing the two gives h∝n−1/5h\propto n^{-1/5} and an error rate of n−4/5n^{-4/5}. That’s slower than the parametric n−1n^{-1}: the price of making no assumptions about the shape.

Exercise 3.1: Show that 1.4826·MAD estimates σ for normal data

For X∼N(μ,σ2)X\sim\mathcal N(\mu, \sigma^2), the median of ∣X−μ∣\lvert X - \mu\rvert solves P(∣Z∣≤m/σ)=1/2P(\lvert Z\rvert\le m/\sigma) = 1/2, so m=Φ−1(0.75)σ=0.6745σm = \Phi^{-1}(0.75)\sigma = 0.6745\sigma. Hence σ=m/0.6745=1.4826m\sigma = m/0.6745 = 1.4826m.

📝 Quick check (Level 3)
0/3 answered
  1. 1. The median minimizes the sum of…
  2. 2. The optimal KDE bandwidth scales like…
  3. 3. 1.4826 = 1/Φ⁻¹(?)

Level 4: Expert

★★★★★ Expert⏱ 40 minResearchers: original papers and open problems.

Anscombe’s quartet and spike detection in telemetry

Anscombe (1973) built four datasets with the same mean and variance of x and y, the same correlation (0.816) and the same regression line, y=3+0.5xy = 3 + 0.5x. Plotted, they’re a clean line, a curve, a line with one outlier, and a vertical stack with one far point. Summary statistics alone can’t tell them apart, so plot first. The same holds for telemetry. Health monitoring of spacecraft and robots flags anomalies with robust statistics (median/MAD, quantile bands), because the data are full of the outliers being searched for, and classical z-scores get masked by them (Hampel, 1974; Rousseeuw and Hubert, 2011).

🐍 Exercise 2 (research): Anscombe's quartet and robust spike detection
Verify that Anscombe's four datasets share their means, variances, correlation and regression line. Then inject 6% spikes into a temperature channel and compare robust (median/MAD) z-scores with classical z-scores for detecting them.

Descriptive statistics in AI, robotics and aerospace

  • Exploratory data analysis (Tukey, 1977) comes before modelling. Look for unit errors, clipped sensors, duplicated logs and time-zone shifts before training anything.
  • Benchmark reporting. Report medians and IQRs, or full distributions, over seeds for RL results, which are notoriously heavy-tailed (Henderson et al., 2018; Agarwal et al., 2021 recommend interquartile means and bootstrap intervals).
  • Spacecraft telemetry monitoring. Limit checks and robust trend statistics over thousands of channels. Learned detectors such as LSTM residual thresholds still lean on robust thresholding (Hundman et al., 2018).
  • Latency budgets for robots. Control loops care about the 99th-percentile delay, not the mean. Quantiles are the right summary of a real-time system.
  • Streaming statistics. Welford/Chan updates and quantile sketches (t-digest) summarize data that can’t be stored.

References

  1. J. Tukey (1977). Exploratory Data Analysis. Addison-Wesley.
  2. F. Anscombe (1973). “Graphs in statistical analysis.” The American Statistician, 27(1).
  3. P. Huber (1964). “Robust estimation of a location parameter.” Annals of Mathematical Statistics, 35(1).
  4. F. Hampel (1974). “The influence curve and its role in robust estimation.” JASA, 69(346).
  5. P. Rousseeuw, M. Hubert (2011). “Robust statistics for outlier detection.” WIREs Data Mining and Knowledge Discovery, 1(1).
  6. B. Welford (1962). “Note on a method for calculating corrected sums of squares and products.” Technometrics, 4(3).
  7. T. Chan, G. Golub, R. LeVeque (1983). “Algorithms for computing the sample variance.” The American Statistician, 37(3).
  8. D. Freedman, P. Diaconis (1981). “On the histogram as a density estimator: L2 theory.” Z. Wahrscheinlichkeitstheorie, 57.
  9. B. Silverman (1986). Density Estimation for Statistics and Data Analysis. Chapman & Hall.
  10. R. Agarwal et al. (2021). “Deep reinforcement learning at the edge of the statistical precipice.” NeurIPS.
  11. K. Hundman et al. (2018). “Detecting spacecraft anomalies using LSTMs and nonparametric dynamic thresholding.” KDD.