Skip to main content

Population, sample and simple random sampling

A table is a sample from something larger. Name the target population, the sampling frame and the sample, tell a parameter from a statistic, and see why a simple random sample has means that average out to the population mean.
S01.2.1L1 Core25 minIn review

Before this lesson

S01.1 Data types and measurement M01.8 Counting and combinatorics P02.9 Reproducible notebooks (planned)

After this lesson you can

  • Name the target population, the sampling frame and the sample behind a data set, and say which units could never have been drawn.
  • Tell a parameter from a statistic, writing the population mean as mu and the sample mean as x-bar.
  • State what makes a sample simple random: every set of n units has the same chance of being the sample.
  • List every sample of two from a small population and show that their means average exactly to the population mean.
  • Draw a simple random sample in Python, first by shuffling from scratch and then with NumPy and pandas.

In review. The maths and code on this page are checked by automated tests on every change, but an independent reader has not signed it off yet. Spot a mistake or a confusing step? Tell us.

The question

The flats table holds nine flats, and their mean rent is 10 (hundreds of euros a month). Does that tell you the typical rent of a flat in the city? It depends on one thing the table does not show: how those nine flats got into it. Every model in machine learning faces the same question about its training rows.

Intuition

The flats table of module S01.1 was never the point in itself. Nobody cares about nine particular flats. We care about the flats of the city, and the nine are a window onto them. This lesson names the parts of that window.

Left: a large grey oval titled Target population: every flat to let in the city, filled with about seventy hollow grey dots. Inside it a dashed oval, labelled Sampling frame: the listings of one website, holds some of the dots, and nine of the dots inside the dashed oval are filled blue: the sample, the nine flats of the table. Right: a number line of rent from 4 to 12. A black triangle at 8.3 is labelled mu equals 8.3, a parameter of the population, fixed and usually unknown. A vermillion bar at 10 is labelled x-bar equals 10, a statistic of the sample, which changes from sample to sample.
S01.2.1-F1

Three layers. The target population is what the question is about, the sampling frame is the list the sample was drawn from, and the sample is what ended up in the table. On the right, the population’s mean is a fixed number; the sample’s mean is one draw of a number that changes with the sample.

Read the picture from the outside in.

  1. The target population is every unit the question is about: here every flat to let in the city. It is fixed by the question, not by the data.
  2. The sampling frame is the list you can actually draw from: here the listings of one website. A flat that is not on the website can never reach the table, however carefully the draw is made.
  3. The sample is the units that were drawn: here the nine flats of the table.

A number that describes the whole population is a parameter. The population mean rent is written \(\ctruth{\mu}\) (Greek mu). It is one fixed number, and in real life it is usually unknown, because nobody has measured every flat. A number computed from the sample is a statistic. The sample mean is written \(\cmodel{\bar{x}}\) (x-bar). It is known as soon as you have the table, but draw a different sample and it changes.

For the course we built an invented city of 500 flats, so we know its mean: \(\ctruth{\mu} = 8.3\). The nine flats give \(\cmodel{\bar{x}} = 10\). From here on the course keeps the two kinds of letter apart: Greek letters for a population, Latin letters for a sample.

Build it up

The city is too big to work with by hand, so we shrink it. Take a population of just five flats, five of the nine from the table, with rents 4, 7, 8, 9 and 12. We write \(N = 5\) for the size of a population and \(n\) for the size of a sample.

Step 1. The parameter. With all five flats in front of us, the population mean is a plain average: the rents add to 40, so \(\ctruth{\mu} = 40 / 5 = 8\).

Step 2. One sample. Write the five names on slips, mix them in a hat and draw two. Suppose F1 and F2 come out, with rents 7 and 12. The sample mean is \(\cmodel{\bar{x}} = 19 / 2 = 9.5\), which misses \(\ctruth{\mu}\) by 1.5.

Two number lines from 3 to 13. Top, titled The population, N equals 5 flats: five blue dots labelled F8 at 4, F1 at 7, F6 at 8, F7 at 9 and F2 at 12, with a black triangle at 8 and the sum mu equals (4 plus 7 plus 8 plus 9 plus 12) over 5 equals 8. Bottom, titled One sample of n equals 2, drawn by lot, F1 and F2: only F1 and F2 are filled blue, the other three are hollow grey, a vermillion bar marks 9.5, and the sum reads x-bar equals (7 plus 12) over 2 equals 9.5. The black triangle stays at 8.
S01.2.1-F2

The population mean stays at 8 (triangle). The mean of one sample of two, F1 and F2, is 9.5 (bar).

Step 3. Another draw, another answer. Put the slips back and draw again: perhaps F8 and F6, with mean 6. The statistic moved; the parameter did not. That is the whole difference between them.

Step 4. How many samples are there? A sample of two is a set of two flats, in no order, so the number of possible samples is the number of ways to choose 2 from 5, which lesson M01.8.3 counts:

\[ \binom{5}{2} = \frac{5 \times 4}{2} = 10. \]

Drawing slips from a well-mixed hat makes each of these ten sets equally likely, with chance \(1/10\) each. That property has a name.

The formal statement

NoteDefinitions

A population is a set of \(N\) units with values \(x_1, \dots, x_N\). Its mean is the parameter

\[ \ctruth{\mu} = \frac{1}{N} \sum_{i=1}^{N} x_i . \]

A sample is a set of \(n\) of those units. Its mean is the statistic \(\cmodel{\bar{x}}\): the sum of the \(n\) sampled values divided by \(n\).

A sample is a simple random sample of size \(n\) when every set of \(n\) units has the same chance of being the sample. There are \(\binom{N}{n}\) such sets, so each has chance \(1 / \binom{N}{n}\).

In a simple random sample a unit is drawn at most once: the five slips do not go back into the hat until the sample is complete. Drawing without replacement is the default meaning of “simple random sample” in this course.

Consequence 1: every unit has the same chance, \(n/N\). Fix one unit, say F2. A sample that contains F2 is F2 plus \(n - 1\) of the other \(N - 1\) units, so \(\binom{N-1}{n-1}\) samples contain it. Its chance of being drawn is the share of samples that contain it:

\[ \begin{aligned} \frac{\binom{N-1}{n-1}}{\binom{N}{n}} &= \frac{(N-1)!}{(n-1)!\,(N-n)!} \\ &\qquad \cdot \frac{n!\,(N-n)!}{N!} \\ &= \frac{(N-1)!}{N!} \cdot \frac{n!}{(n-1)!} \\ &= \frac{1}{N} \cdot n = \frac{n}{N}. \end{aligned} \]

The first two lines write both counts out in factorials, the third cancels \({(N - n)!}\), and the last uses \(N! = N \cdot {(N-1)!}\) and \(n! = n \cdot {(n-1)!}\). For the five flats and \(n = 2\): \(\binom{4}{1} = 4\) samples contain each flat, out of 10, a chance of \(4/10 = 2/5\).

Consequence 2: the sample means average exactly to \(\ctruth{\mu}\). List all \(\binom{N}{n}\) samples and add up their means. Each mean is a sum over its sample divided by \(n\), so the total is

\[ \frac{1}{n} \sum_{\text{samples}} \; \sum_{i \,\in\, \text{sample}} x_i . \]

In the double sum each unit’s value is counted once for every sample that contains it, which is \(\binom{N-1}{n-1}\) times (Consequence 1). So the double sum equals \(\binom{N-1}{n-1}\) times the population total. Dividing the total of the means by the number of samples gives their average:

\[ \begin{aligned} \text{average of } \cmodel{\bar{x}} &= \frac{\binom{N-1}{n-1}}{\binom{N}{n}} \cdot \frac{1}{n} \sum_{i=1}^{N} x_i \\ &= \frac{n}{N} \cdot \frac{1}{n} \sum_{i=1}^{N} x_i \\ &= \frac{1}{N} \sum_{i=1}^{N} x_i = \ctruth{\mu}. \end{aligned} \]

No single sample has to hit \(\ctruth{\mu}\). But taken over every sample the draw could produce, the sample mean is centred exactly on it. A method of choosing that has this property cannot lean one way: the next lesson calls it having no bias.

Go deeper: what changes if the slips go back into the hat

Drawing with replacement puts each slip back before the next draw, so a flat can appear twice. Then the \(N^n\) ordered draws are equally likely: 25 of them for two draws from five flats. Each flat appears as the first draw in 5 of them and as the second draw in 5 of them, so the total of the 25 means is \(\tfrac{1}{2}{({5 \cdot 40} + {5 \cdot 40})} = 200\), and their average is \(200 / 25 = 8\) again. The centre is still \(\ctruth{\mu}\). What changes is the spread of the means, which lesson S01.3.3 measures, and which matters when the sample is a large part of a small population. Sampling with replacement is also the setting of the bootstrap (S02.8).

Worked example

All samples of two from the five flats. The ten sets, with their means, are traced below.

A table with one row per sample. Five columns of circles are headed F8 (rent 4), F1 (7), F6 (8), F7 (9) and F2 (12). In each of ten rows two circles are filled blue, and the row ends with the sample mean in vermillion: (4 plus 7) over 2 equals 5.5, (4 plus 8) over 2 equals 6, (4 plus 9) over 2 equals 6.5, (4 plus 12) over 2 equals 8, (7 plus 8) over 2 equals 7.5, (7 plus 9) over 2 equals 8, (7 plus 12) over 2 equals 9.5, (8 plus 9) over 2 equals 8.5, (8 plus 12) over 2 equals 10, (9 plus 12) over 2 equals 10.5. Below the rows each column shows the count 4: four samples hold each flat. A last line says the ten means add to 80, so they average 8, the population mean.
S01.2.1-F3

The ten samples of two. Each column has four filled circles, so each flat is in four samples, and the ten means add to 80.

Add the ten means in the order of the trace:

\[ \begin{aligned} &5.5 + 6 + 6.5 + 8 + 7.5 \\ &\quad + 8 + 9.5 + 8.5 + 10 + 10.5 = 80 . \end{aligned} \]

Their average is \(80 / 10 = 8\), which is \(\ctruth{\mu}\), as Consequence 2 promised. The shortcut gives the same total without the list: each flat is in 4 samples, so the ten sample sums add to \({4 \times 40} = 160\), and halving each sum to make a mean gives 80.

A number line from 5 to 11 with ten vermillion dots, one per sample mean, at 5.5, 6, 6.5, 7.5, 8, 8 (stacked two high), 8.5, 9.5, 10 and 10.5. A black triangle under the line marks mu equals 8. Pointers mark the smallest mean, 5.5, and the largest, 10.5.
S01.2.1-F4

The ten sample means as dots. They run from 5.5 to 10.5 and balance on \(\ctruth{\mu} = 8\), yet only two of the ten land on it.

Two things show in the dot plot. The means are spread out: a sample of two can miss by as much as 2.5 either way. And they are spread evenly about 8, with nothing pulling them to one side. The next lesson gives each of those two things a number.

Code

First a simple random sample from scratch. Shuffle the units, then keep the first \(n\). The shuffle walks from the last position to the first and swaps each item with one at a random position at or before it (the Fisher-Yates shuffle), which makes every order of the units equally likely.

import itertools
import numpy as np

ids = ["F8", "F1", "F6", "F7", "F2"]
rent = {"F8": 4, "F1": 7, "F6": 8, "F7": 9, "F2": 12}

def shuffle(items, rng):
    items = list(items)
    for i in range(len(items) - 1, 0, -1):
        j = int(rng.integers(0, i + 1))      # a position from 0 to i
        items[i], items[j] = items[j], items[i]
    return items

def simple_random_sample(units, n, rng):
    return shuffle(units, rng)[:n]

rng = np.random.default_rng(2026)
counts = {}
for _ in range(10_000):
    pair = frozenset(simple_random_sample(ids, 2, rng))
    counts[pair] = counts.get(pair, 0) + 1
print("different samples seen:", len(counts))
print("smallest and largest count:", min(counts.values()), max(counts.values()))
different samples seen: 10
smallest and largest count: 935 1040

In 10,000 draws all ten samples turn up, each close to 1,000 times. Now list them exactly, as in the worked example, and check both consequences.

samples = list(itertools.combinations(ids, 2))
means = [(rent[a] + rent[b]) / 2 for a, b in samples]
mu = sum(rent.values()) / len(rent)
print("number of samples:", len(samples))
print("means:", sorted(means))
print("average of the means:", sum(means) / len(means), " mu:", mu)
print("samples holding each flat:", [sum(f in s for s in samples) for f in ids])
number of samples: 10
means: [5.5, 6.0, 6.5, 7.5, 8.0, 8.0, 8.5, 9.5, 10.0, 10.5]
average of the means: 8.0  mu: 8.0
samples holding each flat: [4, 4, 4, 4, 4]

The library calls do the shuffle for you. NumPy’s Generator.choice must be told replace=False, because its default draws with replacement. pandas’ DataFrame.sample draws without replacement by default and takes a seed as random_state.

import pandas as pd

rng = np.random.default_rng(7)
print("numpy:", rng.choice(ids, size=2, replace=False))

flats = pd.DataFrame({"id": ids, "rent": [rent[f] for f in ids]})
draw = flats.sample(n=2, random_state=7)
print(draw)
print("sample mean:", draw["rent"].mean())
numpy: ['F7' 'F2']
   id  rent
0  F8     4
3  F7     9
sample mean: 6.5

Which two flats a seed gives is not worth remembering, and a new version of a library may give others. What matters is that the same seed gives the same sample every time the script runs on the same versions, so a result can be checked (P02.9).

Explore

This module’s interactive, the sampling bench, lives in the next lesson. There you draw sample after sample from a population of 48 flats and watch where the sample means land.

Pitfalls

Two number lines from 5 to 11, each with a black triangle at mu equals 8. Left, marked with a cross and titled First two rows: ten vermillion dots stacked in one column at 5.5, with the notes sorted by rent, always F8 and F1, mean 5.5, and ten draws, one answer. Right, marked with a tick and titled Shuffle, then take two: ten vermillion dots spread from 5.5 to 10.5 and centred on 8, with the note all ten possible pairs, their means average 8.
S01.2.1-F5

Wrong beside right. Taking the first rows of a list sorted by rent gives the same sample every time, far below \(\ctruth{\mu}\). Shuffling first gives every pair a chance, and the means centre on 8.

“The first rows of the file are as good as any other rows.”

Only if the file is in random order, and files rarely are. They are sorted by date, by price, by postcode or by whoever entered them. Taking the head of a list sorted by rent gives F8 and F1 every time, a mean of 5.5. The same mistake in machine learning is to split a file into training and test rows without shuffling it first.

“rng.choice(units, size=n) draws a simple random sample.”

Its default is replace=True, so a unit can be drawn twice and the sample can hold fewer than \(n\) different units. Pass replace=False. DataFrame.sample has the opposite default.

“Every flat has the same chance of being picked, so the sample is simple random.”

Equal chances for each unit are not enough. Seat the five flats round a table and pick one pair of neighbours at random: F8 and F1, F1 and F6, F6 and F7, F7 and F2, or F2 and F8. Every flat is in two of the five pairs, so each has chance \(2/5\), exactly as before. But F8 and F6 can never be drawn together, so not every set of two has the same chance. Simple random means equal chances for every set of \(n\) units.

Check yourself

Recall

1. What are the target population, the sampling frame and the sample for the flats table?

Show answer

The target population is every flat to let in the city, the sampling frame is the listings of one website, and the sample is the nine flats of the table.

2. Which of these is a parameter and which a statistic: the mean rent of the city’s 500 flats, and the mean rent of the nine flats?

Show answer

The city’s mean, \(\mu = 8.3\), is a parameter: fixed, and usually unknown. The nine flats’ mean, \(\bar{x} = 10\), is a statistic: it changes from sample to sample.

3. What makes a sample of size \(n\) a simple random sample?

Show answer

Every set of \(n\) units of the population has the same chance of being the sample.

4. In a simple random sample of \(n\) from \(N\), what is the chance that one given unit is drawn?

Show answer

\(n / N\), because \(\binom{N-1}{n-1}\) of the \(\binom{N}{n}\) samples contain it, and that ratio is \(n / N\).

5. The ten samples of two from the rents 4, 7, 8, 9, 12 have means from 5.5 to 10.5. What do they average, and why?

Show answer

Exactly 8, the population mean. Each flat is in four of the ten samples, so every rent counts equally in the total of the means.

Exercises

1. ★ A population of four flats has rents 3, 7, 9 and 13. List every simple random sample of two with its mean, and check that the means average to \(\mu\).

Show solution

\(\mu = 32 / 4 = 8\). There are \(\binom{4}{2} = 6\) samples: \(\{3, 7\}\) mean 5, \(\{3, 9\}\) mean 6, \(\{3, 13\}\) mean 8, \(\{7, 9\}\) mean 8, \(\{7, 13\}\) mean 10 and \(\{9, 13\}\) mean 11. The means add to 48, and \(48 / 6 = 8 = \mu\).

2. ★★ From the five flats (rents 4, 7, 8, 9, 12) we now draw simple random samples of three. How many samples are there, how many contain F2, and what do the sample means average? Answer without listing the samples.

Show solution

There are \(\binom{5}{3} = 10\) samples. Those that contain F2 add two of the other four flats, so there are \(\binom{4}{2} = 6\) of them, a chance of \(6/10 = 3/5 = n/N\). Each flat is in 6 samples, so the ten sample sums add to \({6 \times 40} = 240\). Each mean is a sum divided by 3, so the means add to 80 and average \(80 / 10 = 8 = \mu\).

3. ★★★ In the round-table scheme of the third pitfall, list the five possible samples with their means. Show that the means average to \(\mu = 8\) and name the five sets of two that can never be drawn. Is this scheme a simple random sample?

Show solution

The pairs are F8 and F1, mean \({(4 + 7)/2} = 5.5\); F1 and F6, mean 7.5; F6 and F7, mean 8.5; F7 and F2, mean 10.5; F2 and F8, mean 8. The means add to 40, and \(40 / 5 = 8\), because each flat is in exactly two pairs. The sets that can never be drawn are F8 and F6, F8 and F7, F1 and F7, F1 and F2, and F6 and F2. Half of the ten sets have chance 0 and the other half chance \(1/5\), so this is not a simple random sample, even though each flat has chance \(2/5\) and the means are centred on \(\mu\).

Summary card

A table is a sample: say from what, and how it was drawn.

The anchor figure again: an oval of grey dots for every flat in the city, a dashed oval inside it for the listings of one website, nine filled blue dots for the sample, and a number line with the parameter mu equals 8.3 and the statistic x-bar equals 10.
S01.2.1-F1

Population, frame, sample; parameter, statistic.

  • Parameter \(\mu\), of the population: fixed, usually unknown. Statistic \(\bar{x}\), of the sample: it varies.
  • Simple random sample: each of the \(\binom{N}{n}\) sets of \(n\) units has chance \(1 / \binom{N}{n}\).
  • Each unit is drawn with chance \(n / N\).
  • Over all samples the mean of \(\bar{x}\) is exactly \(\mu\).

Sources and next steps

Sources. Each was opened and checked against this lesson on 12 November 2026.

  • David Diez, Mine Cetinkaya-Rundel and Christopher Barr, OpenIntro Statistics, 4th edition (free PDF). Section 1.3.1 defines the target population and the sample, and Section 1.3.3 describes a simple random sample as a raffle and warns that a sample picked by hand can be biased without meaning to be.
  • Barbara Illowsky and Susan Dean, Introductory Statistics 2e, OpenStax, Section 1.2. Its definition of a simple random sample is the one used here: any group of \(n\) individuals is as likely to be chosen as any other group of \(n\).
  • NumPy, numpy.random.Generator.choice: replace defaults to True, so a value can be selected more than once.
  • pandas, pandas.DataFrame.sample: replace defaults to False, and random_state takes a seed.

Next. S01.2.2 Two ways to be wrong: sampling variability and bias puts numbers on the two things the dot plot of the ten means showed: how far the means scatter, and whether they are centred on the truth.

This lesson unlocks

S01.2.2 Two ways to be wrong: sampling variability and bias

Your progress is saved in this browser only. No account, no tracking.
Back to top