1. Summarizing Empirical Data
Before applying parametric modeling or running hypothesis tests, engineers must characterize raw observational data. In systems telemetry, user telemetry, and performance profiling, datasets are rarely idealized bell curves—they are heavily skewed, bounded, multimodal, or contaminated by measurement noise and network timeouts.
text
2. Measures of Central Tendency
2.1 The Arithmetic Mean
For a sample $\mathbf{x} = (x_1, x_2, \dots, x_n)$:
$$\bar{x} = \frac{1}{n} \sum_{i=1}^n x_i$$
- Mathematical Property: The sample mean minimizes the sum of squared Euclidean errors: $$\bar{x} = \arg\min_{c \in \mathbb{R}} \sum_{i=1}^n (x_i - c)^2$$
- Engineering Vulnerability: A single infinite outlier $x_n \to \infty$ pulls $\bar{x} \to \infty$. Its breakdown point is $\epsilon^* = \frac{1}{n} \to 0$.
2.2 The Sample Median
Sorting the observations $x_{(1)} \le x_{(2)} \le \dots \le x_{(n)}$:
$$\tilde{x} = \begin{cases} x_{\left(\frac{n+1}{2}\right)} & \text{if } n \text{ is odd} \ \frac{1}{2}\left(x_{\left(\frac{n}{2}\right)} + x_{\left(\frac{n}{2} + 1\right)}\right) & \text{if } n \text{ is even} \end{cases}$$
- Mathematical Property: The sample median minimizes the sum of absolute errors ($L_1$ loss): $$\tilde{x} = \arg\min_{c \in \mathbb{R}} \sum_{i=1}^n |x_i - c|$$
- Breakdown Point: $\epsilon^* = 50%$. Up to half the dataset can be completely corrupted without shifting the median to infinity.
2.3 The $\alpha$-Trimmed Mean
Discards the smallest $\lfloor \alpha n \rfloor$ and largest $\lfloor \alpha n \rfloor$ observations before computing the arithmetic mean:
$$\bar{x}\alpha = \frac{1}{n - 2k} \sum{i=k+1}^{n-k} x_{(i)}, \quad k = \lfloor \alpha n \rfloor$$
Commonly used in CPU benchmark suites and network latency profiling ($\alpha = 5%$) to eliminate cache warm-up spikes and garbage collection pauses.
3. Measures of Dispersion & Robust Scale
3.1 Sample Variance & Standard Deviation
The sample variance $s^2$ measures average squared deviations from the sample mean:
$$s^2 = \frac{1}{n - 1} \sum_{i=1}^n (x_i - \bar{x})^2$$
The denominator uses $n - 1$ instead of $n$ (Bessel's Correction) to ensure an unbiased estimator of the true population variance ($E[s^2] = \sigma^2$).
3.2 Interquartile Range (IQR)
The difference between the 75th percentile ($Q_3$) and the 25th percentile ($Q_1$):
$$\text{IQR} = Q_3 - Q_1$$
In standard Tukey box plots, observations outside the range $[Q_1 - 1.5 \cdot \text{IQR}, Q_3 + 1.5 \cdot \text{IQR}]$ are flagged as potential outliers.
3.3 Median Absolute Deviation (MAD)
The median of the absolute differences between the data points and the sample median:
$$\text{MAD} = \text{median}\left( |x_i - \tilde{x}| \right)$$
To serve as a consistent estimator of the standard deviation $\sigma$ for normally distributed data, MAD is scaled by the consistency factor $1 / \Phi^{-1}(0.75) \approx 1.4826$:
$$\hat{\sigma}_{\text{MAD}} = 1.4826 \times \text{MAD}$$
MAD has a maximal breakdown point of $50%$, making it the gold standard for robust anomaly detection in observability pipelines (e.g. Datadog, Prometheus).4. Quantiles & Percentiles in Production Observability
In web service level agreements (SLAs), uptime and performance are defined by high quantiles ($p95, p99, p99.9$):
- $p50$ (Median): The typical user experience.
- $p99$: Tail latency experienced by 1 out of every 100 requests.
text
The Distributed Amplification Effect: If a single user request requires fan-out queries to $k = 100$ internal microservice backends, the probability that the user experiences at least one $p99$ backend latency is: $$P(\text{User hits } \ge 1 \text{ slow backend}) = 1 - (1 - 0.01)^{100} = 1 - 0.366 = 0.634 \quad (63.4% !)$$ Even though individual servers run at $p99$, almost two-thirds of user requests suffer severe degradation! This is why $p99$ latency optimization is critical.
5. Diagnostic Plots: Quantile-Quantile (Q-Q) Plots
How do we mathematically verify whether an empirical dataset originates from a theoretical distribution (such as a Gaussian $\mathcal{N}(\mu, \sigma^2)$)?
A Q-Q Plot graphs the ordered empirical quantiles against the theoretical quantiles of the reference distribution:
$$(q_{\text{theoretical}}^{(i)}, x_{(i)}), \quad i = 1, 2, \dots, n$$
where $q_{\text{theoretical}}^{(i)} = F^{-1}\left(\frac{i - 0.5}{n}\right)$.
text
6. Python Implementation: Robust Summaries & Q-Q Diagnostics
python
7. Key Takeaways
- Breakdown Points Matter: The sample mean breaks down with 1 corrupted observation ($0%$); the median and MAD tolerate up to $50%$ corrupted data.
- Never Average Percentiles: Averaging $p99$ across multiple nodes is mathematically invalid; percentiles must be computed across the pooled distribution (or using algorithms like t-digest / DDSketch).
- Q-Q Plots for Normality: Use Q-Q plots to inspect tail behavior before applying parametric tests that assume normality.