data science / statistics
Statistics for Data Analysis: Why the Average Lies, With Worked Examples
This is the applied side of statistics: reading a summary number critically before you act on it. Two small datasets show an average that describes nobody and a result that reverses when you split the data, and a table of checks tells you what to run first. Free books and courses follow.
A working analyst spends little time proving theorems and a lot of time deciding whether a number can be trusted. That skill is a set of habits more than a body of math: look at the distribution before the mean, ask what groups the data hides, and be suspicious of any single figure offered without its spread. If you want the university-course route instead, with ordered syllabi from MIT, Harvard and Stanford, that lives on the CS statistics page. This page is for people who have a spreadsheet or a DataFrame open right now.
01 · A MISLEADING AVERAGE
Ten salaries, one average, and nobody earns it
A startup advertises that its employees earn an average of $85,800. Here are the ten salaries behind the claim, in thousands of dollars: 42, 45, 47, 48, 50, 52, 55, 58, 61 and 400. The 400 is the founder.
import pandas as pd s = pd.Series([42, 45, 47, 48, 50, 52, 55, 58, 61, 400], name="salary_k") print(s.mean(), s.median(), s.std().round(1)) print((s < s.mean()).sum(), "of", len(s), "below the mean") trimmed = s.drop(s.idxmax()) print(trimmed.mean().round(1), trimmed.median(), trimmed.std().round(1))
| Measure | All ten | Without the founder |
|---|---|---|
| Mean | 85.8 | 50.9 |
| Median | 51.0 | 50.0 |
| Standard deviation | 110.6 | 6.2 |
| Employees below the mean | 9 of 10 | - |
One value moved the mean by almost 35 while moving the median by 1. The standard deviation (110.6) is bigger than the mean, which is itself a warning that the distribution is lopsided. In skewed data such as salaries, home prices and response times, report the median, and show the spread or the percentiles next to it. Series.describe() gives the quartiles in one call, and the pandas reference documents the options.
02 · THE SPLIT THAT REVERSES
When the better design loses overall
A product team tests two checkout designs on 1,000 visitors each. Design B converts better on desktop and better on mobile, yet Design A wins in the totals. This is Simpson's paradox, and the numbers below are constructed (they illustrate the effect, they are not a real study):
| Design | Device | Visitors | Orders | Rate |
|---|---|---|---|---|
| A | desktop | 800 | 96 | 12.0% |
| A | mobile | 200 | 6 | 3.0% |
| B | desktop | 200 | 28 | 14.0% |
| B | mobile | 800 | 40 | 5.0% |
| A overall | 1,000 | 102 | 10.2% | |
| B overall | 1,000 | 68 | 6.8% |
B wins on each device (14.0 vs 12.0 on desktop, 5.0 vs 3.0 on mobile), but B's traffic was mostly mobile, where everyone converts poorly, while A's was mostly desktop. The overall rate mixes two populations of very different quality. Which number is right depends on the question. If device mix is a fact you cannot change, compare within device. If you control who sees which design, the test was badly randomized and should be rerun with equal mixes.
03 · BEFORE YOU REPORT A NUMBER
Six checks, in the order to run them
| Check | How | What it catches |
|---|---|---|
| Look at the shape | Histogram or describe() | Skew, outliers, impossible values |
| Median next to mean | Compare the two | Skew pulling the mean around |
| Spread | Standard deviation, IQR, percentiles | A mean that hides wide variation |
| Sample size | count() per group | Averages built on a handful of rows |
| Segment by the obvious variable | groupby device, region, month | Simpson's paradox, mix shifts |
| Uncertainty | Confidence interval or a test from scipy.stats | Differences that are just noise |
For the last check, SciPy's statistics tutorial covers distributions and hypothesis tests with runnable examples. The caveat is the theme of Alex Reinhart's book: a p-value answers a narrow question and is easy to misuse, and the book's chapters cover stopping rules, truth inflation and hiding the data.
04 · FREE MATERIAL
Books and courses for applied analysis
Choose one book as your spine and use the others as second explanations. The first group assumes you can read a little Python or R code.
- Think Stats, 2nd edition (Allen Downey) ↗An introduction to probability and statistics for Python programmers. Green Tea Press offers the book as a PDF and to read online, with the code in a GitHub repository.greenteapress.com
- OpenIntro Statistics ↗A conventional introductory textbook with a free PDF alongside paperback options; its page also lists datasets and teaching resources.openintro.org
- ModernDive: Statistical Inference via Data Science ↗Regression and inference taught with R and the tidyverse. Licensed CC BY-NC-SA 4.0 and available to read on the site.moderndive.com
- Statistics Done Wrong (Alex Reinhart) ↗A short guide to the errors working scientists make: stopping rules, truth inflation, hiding the data. Licensed CC BY 4.0.statisticsdonewrong.com
- SciPy tutorial: statistics (scipy.stats) ↗Distributions, descriptive statistics and tests, with code you can run.docs.scipy.org
If you prefer video and visuals, these three work well beside a book.
- StatQuest with Josh Starmer ↗Short video explanations of statistics and machine learning concepts on YouTube.youtube.com
- Khan Academy: Statistics and Probability ↗Self-paced lessons with practice problems, from descriptive statistics through inference. A free account tracks progress.khanacademy.org
- Seeing Theory (Brown University) ↗Interactive visual chapters on probability, distributions, frequentist and Bayesian inference, and regression. The site is marked as archived for reference but remains readable.seeing-theory.brown.edu
05 · TRY IT
Audit a number you already trust
06 · FAQ
Frequently asked questions
Should I report the mean or the median?
Report the median when the data is skewed, as with salaries, prices or response times, because a few extreme values drag the mean away from typical cases. Show the spread or percentiles beside it. The mean is fine for roughly symmetric data without large outliers.
What is Simpson's paradox?
It is when a trend that holds inside every subgroup reverses once the groups are combined. It happens when group sizes differ between the things being compared, as when one checkout design gets mostly mobile visitors who convert less. Compare within groups, or fix the mix.
How much statistics do I need for data analysis?
Enough to describe distributions, compare groups, understand uncertainty and avoid common errors such as misreading p-values. Descriptive statistics, sampling, confidence intervals, hypothesis tests and basic regression cover most analyst work.
What is the best free book for learning applied statistics?
Think Stats suits readers who know some Python, ModernDive suits R users, and OpenIntro Statistics is a conventional textbook with a free PDF. Add Statistics Done Wrong as a short guide to common mistakes.