Exploring Patterns · Lesson 2 of 5
Distributions
~16 min
The Concept
You plot a histogram of all five years of nitrate readings from Bluewater Basin's fifteen wells. The shape surprises you: instead of a smooth bell curve, there's a long right tail, most readings cluster between 2 and 15 mg/L, but a small number extend out to 60, 80, even 120 mg/L.
Your supervisor points at the tail. 'That's not random noise. Those extreme values almost certainly come from specific wells, specific seasons, or specific rainfall events. A mean of the whole distribution would tell you almost nothing useful, you need to know what's driving the tail.'
A distribution (the overall pattern of how spread out and clustered a set of values is) is the pattern of values a variable takes, how spread out they are, where they concentrate, whether they're symmetric or skewed. Understanding a distribution before any modelling is essential because most statistical models make assumptions about distribution shape (especially normality, meaning a classic symmetric bell-curve shape) and can produce badly wrong results when those assumptions are violated.
Environmental data is almost never normally distributed. Nitrate, streamflow, and pollutant concentrations all tend to be right-skewed (lopsided, with a long tail of rare high values): most values are low, but rare extreme events create a long right tail. The mean of a skewed distribution is pulled toward the tail and doesn't represent 'typical' well, the median (the middle value when everything is lined up in order) is often more useful.
The Analogy
Picture the take-home pay of everyone in a small town, including one billionaire who happens to live there. The average income looks huge, skewed upward by one person. The median, the income of the person right in the middle of the line, tells you what a typical resident actually earns. Nitrate levels behave the same way: a few extreme readings can drag the average far from what is typical.
The Math (optional)
Three key statistics describe where a distribution is centred and how spread it is:
Sample mean
The arithmetic average. Pulled toward extreme values in skewed distributions.
Sample variance
The average squared deviation from the mean. We divide by n−1 (not n) to get an unbiased estimate of the population variance.
Skewness
Positive skew means a long right tail (more extreme high values than low). Most environmental concentrations have positive skew.
Try It
Drag the skewness and sample size sliders to see how Bluewater Basin's nitrate distribution changes, and when the mean diverges from the median.
Right skew pulls the tail toward high values — common in contamination data where most readings are low but rare events are extreme.
With small samples, the histogram looks ragged and the mean is unstable. Watch how it stabilises as n grows.
Code (optional)
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
nitrate = pd.read_csv("bluewater_nitrate_clean.csv")["nitrate_mgL"]
print("=== Distribution summary ===")
print(f"Mean: {nitrate.mean():.2f} mg/L")
print(f"Median: {nitrate.median():.2f} mg/L")
print(f"Std dev: {nitrate.std():.2f} mg/L")
print(f"Skew: {nitrate.skew():.2f}")
print(f"Min/Max: {nitrate.min():.1f} / {nitrate.max():.1f} mg/L")
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(10, 4))
# Raw histogram
ax1.hist(nitrate, bins=40, color="#1D6E73", alpha=0.8)
ax1.axvline(nitrate.mean(), color="#D4A72C", linestyle="--", label="Mean")
ax1.axvline(nitrate.median(), color="#A97452", linestyle="-", label="Median")
ax1.legend()
ax1.set_title("Nitrate distribution, all wells")
# Log-transform for right-skewed data
ax2.hist(np.log1p(nitrate), bins=40, color="#4C7A6B", alpha=0.8)
ax2.set_title("Log-transformed (more symmetric)")
plt.tight_layout()
plt.savefig("nitrate_distribution.png", dpi=150)Line by line
- We compute the five-number summary plus skewness: if skew > 1, the distribution is substantially right-tailed.
- Plotting both raw and log-transformed data side by side reveals whether log-transformation brings the distribution closer to symmetric.
- Marking both the mean and median shows how far they diverge, large divergence signals skew that matters for modelling choices later.
- plt.savefig saves the figure for the methods section of the eventual research paper.
Why Real Researchers Care
Most water quality variables, nitrate, phosphorus, turbidity, bacterial counts, follow approximately log-normal distributions in real watersheds. Many regression and statistical test procedures work better after log-transforming these variables, because the transformed data is closer to normal. Understanding your distribution in EDA directly informs which model you'll choose in Mission 06.
Quick Check
Q1. Bluewater Basin's nitrate data has a mean of 14.2 mg/L and a median of 8.7 mg/L. What does this tell you?
Your Goal
The five wells closest to the agricultural zone have nitrate readings: [18.3, 22.7, 31.4, 8.9, 45.2]. The five wells furthest from farmland have: [4.1, 3.8, 5.2, 4.6, 6.1]. Calculate the mean and median for each group. What does this tell you about where the nitrate is coming from?
Hint: Sort each list, find the middle value for median, add and divide by 5 for mean. The difference between groups is the signal.
Teach It Back
Explain to a non-statistician why the median can be more informative than the mean for environmental concentration data, using Bluewater Basin as your example.