Statistics Intro
Statistics is the science of learning from data. It gives you tools to collect information, summarise it, and draw conclusions that go beyond the numbers you actually observed, while being honest about how uncertain those conclusions are.
You meet statistics every day: a weather app saying "70% chance of rain", a survey claiming "6 in 10 people prefer remote work", a clinical trial reporting that a new drug lowers blood pressure. Behind each of these statements is a statistical method.
What can statistics do?
| Question | Statistical tool |
|---|---|
| What does my data look like? | Tables, charts, averages, spread |
| How typical is this value? | Percentiles, standard scores |
| What is true for everyone, if I only asked some people? | Estimation and confidence intervals |
| Is this difference real or just luck? | Hypothesis testing |
| Do two things move together? | Correlation and regression |
These fall into two big families:
- Descriptive statistics summarise the data you have: "the 30 runners in our club ran 5 km in 27.4 minutes on average."
- Inferential statistics use a sample to say something about a larger group: "runners in our city probably average between 26 and 31 minutes."
Statistics in Python
This course explains each idea first and then shows how to compute it. Python is a natural fit: the built-in statistics module covers the basics, while NumPy, SciPy and pandas handle bigger datasets and advanced tests. Every example on this site runs in your browser.
Here is a first taste. Imagine a small bakery recorded how many croissants it sold on seven days:
import statistics
croissants = [42, 38, 51, 47, 39, 60, 45]
print("Days recorded:", len(croissants))
print("Total sold:", sum(croissants))
print("Average per day:", round(statistics.mean(croissants), 2))
print("Middle value:", statistics.median(croissants))
print("Lowest / highest:", min(croissants), "/", max(croissants))Days recorded: 7
Total sold: 322
Average per day: 46
Middle value: 45
Lowest / highest: 38 / 60
Five lines of output already tell a story: on a typical day the bakery sells a little under 50 croissants, and sales never dropped below 38.
Data with uncertainty
Statistics becomes really interesting when the data is noisy. Below we simulate 1000 rolls of a fair six-sided die. The random generator is seeded (default_rng(7)), which makes it produce the same "random" numbers on every run, so your output always matches the one shown here.
import numpy as np
rng = np.random.default_rng(7)
rolls = rng.integers(1, 7, size=1000) # numbers from 1 to 6
values, counts = np.unique(rolls, return_counts=True)
for v, c in zip(values, counts):
print(f"face {v}: {c:4d} times ({c / len(rolls):.1%})")
print("average roll:", rolls.mean())face 1: 157 times (15.7%)
face 2: 163 times (16.3%)
face 3: 164 times (16.4%)
face 4: 160 times (16.0%)
face 5: 176 times (17.6%)
face 6: 180 times (18.0%)
average roll: 3.575
A fair die should show each face 1/6 of the time (about 16.7%) and average 3.5. The simulated results are close but not exact. That gap between what we expect and what we observe is exactly what statistics teaches you to reason about: is it ordinary randomness, or a sign that the die is loaded?
Note: Seeded generators appear throughout this course. In real analyses you would collect real data; the seed simply makes the lessons reproducible.
How this course is organised
- Statistics Tutorial: the vocabulary: data, samples, populations, study designs and data types.
- Descriptive Statistics: tables, charts, averages and measures of spread.
- Inferential Statistics: the normal and t distributions, confidence intervals and hypothesis tests.
- Beyond the Basics: probability, the central limit theorem, correlation, regression, chi-square, ANOVA and common mistakes.
- Reference tables, Exercises and a Mini Project that analyses an A/B test from start to finish.
You do not need advanced mathematics. Formulas are written in plain text, such as mean = sum(x) / n, and each one is computed in code right after it is introduced so you can see the numbers move.
Test yourself
Which statement is an example of *inferential* statistics?
- Our 12 employees worked 41 hours on average last week.
- Based on a survey of 500 voters, between 44% and 50% of all voters support the proposal.
- The tallest student in the class is 191 cm.
- We sold 340 tickets yesterday.
Why do the examples in this course use np.random.default_rng(7) with a number inside?
- It makes the numbers more random
- The seed makes the generator reproduce the same sequence every run
- It limits the numbers to 0–7
- It is required by NumPy
A fair die is rolled 1000 times and face 6 appears 181 times instead of the expected ~167. What is the best first reaction?
- The die is definitely loaded
- Ask whether a difference this size is plausible by chance alone
- Ignore it, statistics can't help here
- Roll it 1000 more times and keep only the second result