2 Sampling Distribution
Learning objectives
Define the sampling distribution of a statistic, and explain why it is the central concept of statistical inference.
Distinguish between the population distribution, the sample distribution, and the sampling distribution, three conceptually distinct objects that are easy to confuse.
Use simulation to approximate and explore a sampling distribution, and describe its two key properties: center (bias/unbiasedness) and spread (standard error).
Distinguish between a statistic as a random variable (the estimator) and the specific value it takes in a given sample (the estimate), and explain why this distinction matters.
Explain how sample size affects the precision of an estimate, and describe the law of diminishing returns in sampling.
Use
rep_sample_n()from theinferpackage to simulate a sampling distribution, and usesummarise()to compute the statistic of interest for each sample.
Introduction
In the previous chapter, we learned how to take a random sample and compute a statistic (such as the sample mean) to estimate a population parameter. We pick up with the same shipment of \(50{,}000\) Apple screens (screens_pop) and the sample of \(300\) screens (screens_sample) from before. We also saw that because samples are random, everything about the sample is random, including the statistic we compute from it. We call this sampling variability. Take a look at the code below and notice how two random samples yield different sample proportions.
Since we are using statistics (which are random) to estimate parameters (which are fixed), one could argue that any value we get from a single sample is just a lucky (or unlucky) draw that does not necessarily reflect the true population parameter.
Let’s think this through together! Suppose the true proportion of screens that can withstand a crack pressure of \(750\) psi or more is \(p = 0.95\). Since we cannot test all \(50{,}000\) screens, we have to rely on our single sample. But here is the catch: we already know that a different random sample would have given a different sample proportion. So, how can we possibly trust the one estimate we happen to have?
Imagine a scenario where every possible sample yields a sample proportion, \(\hat{p}\), very close to \(p = 0.95\). In that world, we could relax knowing our single estimate is definitely close to the truth. In this scenario, there is still sampling variability, but since all samples give sample proportions that are very close to the true proportion, the fluctuation is irrelevant.
On the other hand, if different samples produced wildly different proportions (jumping around, say, from \(0.7\) to \(0.8\) or \(0.99\)), our single estimate could be miles away from the truth, and we would have no way of knowing it. In this scenario, the sampling variability is huge, and our single estimate is not reliable at all.
In practice, we are rarely in either of these extreme worlds. We are usually somewhere in between, where some samples yield poor estimates (i.e., far from the true parameter), while other samples yield good estimates (i.e., close to the true parameter). Luckily, most samples give estimates that are reasonably close to the true parameter, and the samples that yield terrible estimates are relatively rare. But how rare? Since we cannot evaluate how good a given estimate is on its own, we need to be able to quantify how likely it is that we get a good estimate versus a bad one.
To properly study this variability, we need to look at the distribution of the statistic (in this case the sample proportion) across all possible samples. This is called the sampling distribution and it is the central concept of statistical inference.
Definition 2.1 (Sampling Distribution) The sampling distribution of a statistic is the distribution of that statistic computed from all possible samples of a given size \(n\) drawn from the population.
Figure 2.1 puts the whole picture together: the population has a fixed (but unknown) parameter; each sample we could draw yields its own statistic; and the sampling distribution is what we get by collecting the statistic from every possible sample. Notice that it is a distribution of statistics (\(\bar{X}\) values), not of the variable of interest (a distinction that trips students up constantly, so keep it in mind as we go forward).
2.1 The Sampling Distribution, Exactly
Let’s start with a small population and a small sample size, so that we can enumerate every possible sample and compute the statistic for each one. This will allow us to see the sampling distribution exactly.
Example 2.1 An aquarium has \(20\) fish. You are responsible for feeding them, and to determine the right amount of food, you need to know their average weight. You decide to estimate the population mean by sampling \(3\) fish at random. The weights of all 20 fish in the population are shown in Table 2.1 (measured in decagrams, dkg).
(Population mean μ = 43.45 dkg)
| Fish | Weight (dkg) | Fish | Weight (dkg) | Fish | Weight (dkg) | Fish | Weight (dkg) |
|---|---|---|---|---|---|---|---|
| Fish #1 | 43 | Fish #6 | 44 | Fish #11 | 26 | Fish #16 | 42 |
| Fish #2 | 46 | Fish #7 | 41 | Fish #12 | 47 | Fish #17 | 36 |
| Fish #3 | 47 | Fish #8 | 40 | Fish #13 | 37 | Fish #18 | 36 |
| Fish #4 | 59 | Fish #9 | 43 | Fish #14 | 42 | Fish #19 | 61 |
| Fish #5 | 24 | Fish #10 | 58 | Fish #15 | 60 | Fish #20 | 37 |
With only \(20\) fish and a sample size of \(n = 3\), there are exactly \(\binom{20}{3} = 1{,}140\) possible samples we could get. The table below lists all \(1{,}140\) possible samples as well as their sample means. Below the table, Figure 2.2 shows the histogram of the sampling distribution (you can click a bar in the histogram to highlight the corresponding samples in the table that yield a sample mean in that bin).
(Click one or more bars in the histogram below to highlight samples.)
□
Exercise 2.1 Using the interactive histogram above, answer the following questions.
(a) What is the smallest sample mean you can find? How many samples give this minimum sample mean? Which fish are in these samples?
- Smallest sample mean: 28.67 dkg (approximately 286.7 grams).
- Number of samples: 2 samples that yield this minimum mean.
- Sample 1: (Fish #5, Fish #11, Fish #17) (weights: 24, 26, and 36 dkg)
- Sample 2: (Fish #5, Fish #11, Fish #18) (weights: 24, 26, and 36 dkg)
The leftmost bar in the histogram corresponds to these two samples, which are among the unluckiest possible samples, giving the worst underestimates of the true population mean (\(\mu = 43.45\) dkg).
(b) Click on bars to select all samples whose mean falls between \(40\) and \(46\) dkg. How many such samples are there?
(c) Which of the following ranges is the most likely to contain the sample mean of a randomly selected sample?
(d) Suppose you select a single random sample of size \(n = 3\) fish. What is the probability of selecting a sample that yields a sample mean of \(49\) dkg or more?
(e) If we select a single random sample of size \(n = 3\), what is the probability of obtaining a sample mean between \(34\) and \(54\) dkg (i.e., \(34 \le \bar{X} < 54\))?
(f) Suppose the aquarium manager wants to find a range around the population mean (\(\mu = 43.45\) dkg) such that at least \(95\%\) of all possible sample means fall within that range. Which of the following ranges satisfies this requirement? (Hint: Select the corresponding bars on the interactive histogram to check the sample count for each range.)
(g) By looking at the sampling distribution, do you have serious concerns of over- or under-estimating the true population mean \(\mu\)?
No, the sampling distribution is roughly centered around the true population mean \(\mu = 43.45\) dkg, which means that roughly half of the possible samples yield a sample mean above the correct value and half below.
□
The fish example is a small, simplified problem designed for illustration. In the real world, populations are typically much larger, making it impossible to enumerate all possible samples. For example, to draw a sample of size \(n = 30\) screens from a population of \(50{,}000\), there are \(\binom{50{,}000}{30} \approx 3.48 \times 10^{108}\) possible samples. This is far too many to enumerate and compute a mean for each one. Consequently, even if we have access to the entire population, we cannot construct the sampling distribution exactly. Instead, we need a way to approximate it.
This is where most students stumble. There are three distributions at play, and they are entirely different things:
Population distribution: The distribution of the variable of interest across all individuals in the population. It is fixed but usually unknown.
Sample distribution: The distribution of the variable of interest in your specific sample. It is observable, but changes every time you take a new sample.
Sampling distribution: The distribution of the statistic (e.g., \(\hat{p}\) or \(\bar{X}\)) across all possible samples of size \(n\). It is theoretical (you can approximate it via simulation), and it describes how much your estimate varies from sample to sample.
2.2 Approximating the Sampling Distribution: The surreal approach
For now, let’s assume once again that we have access to the entire population, but this time, it is not a small one. Instead, we have the population of \(50{,}000\) screens. We want to draw a random sample of size \(n = 300\) and compute the sample mean \(\bar{X}\) to estimate the population mean \(\mu\). While we know we must study the sampling variability of \(\bar{X}\), we can no longer enumerate all possible samples to obtain the exact sampling distribution. So, how can we proceed?
Our best option is to draw multiple samples of size \(n = 300\) from the population, compute the sample mean for each, and examine their distribution. Conceptually, this is equivalent to sampling from the “universe” of all possible samples, similar to selecting a single sample from the fish population (which corresponds to selecting one row from the table of all possible samples, Table 2.2), but on an astronomical scale where the full table is too massive to actually build. See the meta-pattern? In statistics, whenever we cannot observe a distribution or parameter directly, we take a sample to estimate it. Here, because we cannot compute the theoretical sampling distribution of \(\bar{X}\) exactly, we simulate and study \(5{,}000\) samples to estimate it.
We call this the surreal approach because, in practice, we never have access to the entire population. (Indeed, if we did, we wouldn’t need statistical inference or sampling distributions in the first place!) But pretending we have this “omniscient” access lets us study how sampling distributions behave.
Ok, let’s see this approach in practice. Let’s take \(5{,}000\) different random samples of size \(n = 300\) from screens_pop, compute the sample mean \(\bar{X}\) for each, and look at the distribution of those \(5{,}000\) estimates. A useful function for this is rep_sample_n() from the infer package (Couch et al. 2021), which draws multiple random samples of a given size from a data frame. It returns a grouped data frame with a new column called replicate that identifies which sample each row belongs to. We can then compute the sample mean for each sample using summarise().
Now, the list of sample means stored in sampling_dist is our approximation of the sampling distribution of \(\bar{X}\) for \(n = 300\). We can visualize it with a histogram to see how the sample means are distributed.
As you can see, the histogram of the \(5{,}000\) sample means is smooth and approximately bell-shaped. The red dashed line shows the true population mean \(\mu\), which is very close to the center of the sampling distribution. Remember, this is the distribution of the sample mean \(\bar{X}\) across all possible samples of size \(n = 300\). The histogram shows that most sample means are clustered around the true population mean, with fewer sample means in the tails. Isn’t that remarkable?
Ok, great, we have our sampling distribution (actually, the approximation of our sampling distribution). But what can we learn from it? What does it tell us about the sample mean \(\bar{X}\) as an estimator of the population mean \(\mu\)? Let’s explore the key properties of the sampling distribution.
2.3 Properties of the sampling distribution
When statisticians study a sampling distribution, they focus on three key properties.
2.3.1 Center: Bias
The center (technically, the mean) of the sampling distribution is the long-run average of the statistic across all possible samples. If this center equals the true parameter value, the statistic is said to be unbiased.
Definition 2.2 (Unbiased Estimator) A statistic is an unbiased estimator of a parameter \(\theta\) (such as the mean or proportion) if the mean of its sampling distribution equals \(\theta\).
In plain English: an estimator is unbiased if it gets the right answer on average, meaning the overshoots and undershoots perfectly cancel out over infinitely many samples, and the average of all estimates equals the truth. There is no systematic tendency to be too high or too low.
Let’s check whether \(\bar{X}\) is unbiased for \(\mu\):
The mean of the \(5{,}000\) simulated \(\bar{X}\) values is essentially equal to the true \(\mu\). The sample mean is an unbiased estimator of the population mean. It does not systematically over- or underestimate the truth. The small difference you see is due to simulation variability - remember we are approximating the true sampling distribution; if you calculated the exact sampling distribution, the mean would be exactly equal to \(\mu\).
In case you don’t believe me, let’s calculate the mean of the sample means using the true sampling distribution: the mean of all \(1{,}140\) possible sample means from the fish population (listed in Table 2.2). In this case, the true population mean is \(\mu = 43.45\) dkg.
Exercise 2.2 The vector fish_sampling_dist contains all \(1{,}140\) possible sample means from the fish population. Compute the mean of fish_sampling_dist and compare it to the true population mean \(\mu = 43.45\) dkg.
fish_sampling_dist is a numeric vector. Pass it directly to mean().
2.3.2 Spread: Standard error
The spread of a distribution is usually measured by its standard deviation. Because the spread of the sampling distribution measures how much the statistic varies from sample to sample, and this variation represents estimation error (since the population parameter is fixed), we can think of the standard deviation of the sampling distribution as a measure of the typical error in our estimate. So, in the case of a sampling distribution, the standard deviation has a special name: the standard error.
Definition 2.3 (Standard Error (SE)) The standard error (SE) is the standard deviation of the sampling distribution of a statistic. It measures the typical amount of variation in the statistic from sample to sample (the typical estimation error).
A small standard error means the statistic is precise (i.e., different samples give very similar estimates). A large standard error means the estimates jump around a lot from sample to sample. In our running example, for a sample size of \(n = 300\) screens, the standard error of the sample mean is:
We will see later how to use the standard error to quantify uncertainty in our estimate of the population mean. For now, just remember that the standard error is a measure of how much the sample mean \(\bar{X}\) varies from sample to sample.
Students frequently get very confused about standard deviation versus standard error. Remember, standard error is a standard deviation; it is just the standard deviation of the sampling distribution.
However, when we talk about standard errors and standard deviations, we are referring to different concepts. Here is a simple way to remember the difference:
- Standard deviation measures the spread of individual data points in a dataset.
- Standard error measures the spread of a statistic (like the sample mean) across different samples.
The two properties above, Bias and Spread, correspond to a distinction you will often encounter when reading about statistics: accuracy and precision.
- An estimator is accurate if it is centered on the true parameter, i.e., if it is unbiased.
- An estimator is precise if its standard error is small, i.e., different samples give very similar estimates.

The two are seperate concepts. An estimator can be accurate but imprecise (estimates scattered around the truth), or precise but inaccurate (estimates consistently off-target in the same direction). Generally, the precision of an estimator tends to improve as the sample size increases.
2.3.3 Shape
The shape of the sampling distribution is also important. It tells us a lot about the behavior of the statistic, can inform us about the probability of getting a sample mean in a certain range, and it can also help us determine which statistical methods are appropriate for inference.
What determines the shape of the sampling distribution? Two things: the shape of the population distribution and the sample size. For small samples, there’s not much we can say about the sampling distribution of \(\bar{X}\), as it highly depends on the unknown population distribution. However, as the sample size grows, something remarkable happens: the sampling distribution becomes approximately bell-shaped, regardless of the shape of the population distribution. We’ll investigate this further in Module 3.
2.4 Effect of sample size
One of the most important practical questions in statistics is: how large does my sample need to be? Let’s investigate this directly by comparing the sampling distribution of \(\bar{X}\) for different sample sizes.
screens_pop, \(\mu = 1002.7\) psi, \(\sigma = 151.0\) psi). As \(n\) increases, the distribution narrows (i.e., estimates become more precise).
Exercise 2.3 (Explore: The Cost of Precision) Let’s investigate the relationship between sample size, standard error, and cost using the simulator in Figure 2.3. Suppose it costs $5 to collect and test each screen. Increasing the sample size by \(400\) screens costs exactly $2,000 (\(400 \times \$5\)). Suppose you are willing to spend $2,000 to reduce the standard error of your estimate. How much precision do you actually get for your money?
- Scenario A: Suppose your initial sample size is \(n = 100\). You decide to increase it by \(400\) screens to \(n = 500\).
- Scenario B: Suppose your initial sample size is \(n = 1{,}500\). You decide to increase it by \(400\) screens to \(n = 1{,}900\).
In both scenarios, you increase the sample size by exactly 400 screens (spending exactly $2,000).
Which of the following statements best describes the trade-off of spending this $2,000?
□
Exercise 2.3 demonstrates the law of diminishing returns in sampling. While larger samples are always more precise, the reward for increasing your sample size gets progressively smaller. Eventually, the financial or physical cost of collecting more data outweighs the tiny gain in precision. The implications of this are profound: when sampling, what matters is the absolute size of the sample, not its size relative to the population (provided the population is much larger than the sample). Once you have a sufficiently large sample, increasing it further yields very little gain in precision. This is why arguments like “only 5,000 people out of a population of 50 million were surveyed, so the results are not reliable” are statistically unfounded. In large populations, it is mostly the sample size that determines the precision, not the fraction of the population sampled.
2.5 The Estimator as a Random Variable
In Section 2.2, we simulated \(5{,}000\) different samples of size \(n = 300\) and watched the sample mean \(\bar{X}\) vary from sample to sample. This behavior is what makes a statistic like \(\bar{X}\) a random variable.
Definition 2.4 (Random Variable and Realization) A random variable is a quantity whose value is determined by the outcome of a random process. A specific observed value computed from a completed random process is called a realization (or observation).
This gives us an important conceptual distinction:
- The Estimator (the rule “compute the sample mean from a random sample”) is the random variable (e.g., \(\bar{X}\)). We do not know its value in advance.
- The Estimate (a specific observed value like \(\bar{x} = 1{,}012\) psi) is a single, fixed realization of that random variable.
- The Parameter (the truth) is a fixed constant describing the entire population and does not change when we draw a new sample.
Why does this matter? Because it dictates when probability statements are meaningful. Asking “what is the probability that the random variable \(\bar{X}\) is within \(20\) psi of the truth?” makes perfect sense, because \(\bar{X}\) takes a different value each time. But asking “what is the probability that the true mean \(\mu = 1{,}000\) psi?” is meaningless; \(\mu\) is a fixed number, not a random variable. It either is \(1{,}000\) psi or it is not; there is no probability involved.
Let’s put this distinction into practice.
Exercise 2.4 (Sorting Quantities: Random Variable vs. Fixed Constant) Verify if you can classify various statistical quantities based on whether they are random variables (changing from sample to sample) or fixed constants (properties of the design or population).
Play the categorization game below to test your understanding.
2.6 Exercises
Exercise 2.5 A public health researcher takes a random sample of \(250\) adults to estimate the proportion who have been diagnosed with hypertension.
(a) Which of the following quantities is a random variable?
(b) After completing the survey, the researcher reports: “In our sample, \(22\%\) of participants have been diagnosed with hypertension.” Is this \(22\%\) a random variable, or a realization of a random variable?
Exercise 2.6 Look back at the simulation in Section 2.2, where we took \(5{,}000\) different samples of size \(n = 300\) from screens_pop and plotted the resulting \(\bar{X}\) values. Which of the following best describes what that histogram represents?
Exercise 2.7 A regional hospital system recorded the time (in minutes) each patient spent waiting in the emergency department before being seen by a physician. Across \(20{,}000\) visits logged last year, the wait time has a population mean of \(\mu = 45\) minutes and a standard deviation of \(\sigma = 20\) minutes.
We take \(3{,}000\) random samples of size \(n = 50\) and compute the sample mean for each. The results are stored in sampling_dist_wait.
(a) Simulate the sampling distribution of \(\bar{X}\) with \(n = 50\) and \(3{,}000\) repetitions.
Use rep_sample_n() from the infer package. The first blank is the function name; the second and third are the size and reps arguments.
wait_time_pop |>
rep_sample_n(size = ___, reps = ___) |>
summarise(xbar = mean(wait_mins))set.seed(5)
sampling_dist_wait <-
wait_time_pop |>
rep_sample_n(size = 50, reps = 3000) |>
summarise(xbar = mean(wait_mins))
sampling_dist_wait |> head()(b) Compute the mean and the standard error of the sampling distribution you created. Store them in a dataframe called summaries_sampling_dist. Compare the mean to the population mean.
sampling_dist_wait has one column called xbar. Use mean() to get its mean and sd() to get the standard error. For the population mean, apply mean() to wait_time_pop$wait_mins.
summaries_sampling_dist <-
sampling_dist_wait |>
summarise(
mean_xbar = mean(xbar),
se_xbar = sd(xbar)
)
# Population mean
pop_mean_wait <- mean(wait_time_pop$wait_mins)
cat("Population mean:", pop_mean_wait, "\n")
cat("Mean of xbars: ", summaries_sampling_dist$mean_xbar, "\n")(c) Now simulate the sampling distribution for \(n = 200\). How does the standard error change?
□
Exercise 2.8 Two researchers, Alice and Bob, study the same population. Alice uses samples of size \(n = 100\) and Bob uses samples of size \(n = 400\).
(a) Who has the smaller standard error?
□
Exercise 2.9 A real estate platform recorded the sale prices (in thousands of dollars) for \(25{,}000\) homes sold in a major Canadian city last year. The data are stored in home_sales_pop.
(a) Is the population distribution symmetric, left-skewed, or right-skewed?
(b) Simulate the sampling distribution of the sample median for samples of size \(n = 40\) with \(3{,}000\) repetitions.
There are three blanks to fill:
- The sampling function is
rep_sample_n(), withsize = 40andreps = 3000. - Inside
summarise(), usemedian()to compute the sample median.
set.seed(20)
sampling_dist_median <-
home_sales_pop |>
rep_sample_n(size = 40, reps = 3000) |>
summarise(med = median(price_k))
sampling_dist_median |>
ggplot(aes(x = med)) +
geom_histogram(bins = 40, fill = "coral", color = "white") +
labs(
title = "Sampling distribution of the sample median (n = 40)",
x = "Sample median price (thousands of dollars)",
y = "Count"
) +
theme_classic()□
With the help of the surreal approach, we have now explored sampling distribution and its role in statistical inference. However, as the name suggests, the surreal approach is not viable in practice because we never have access to the entire population. In a real study, you have exactly one sample, and there is no going back to the population for more.
Yet everything we have built here still applies. The sampling distribution describes how much an estimate typically varies from the truth, and that description is precisely what we need to quantify uncertainty and draw reliable conclusions. The challenge that remains is approximating the sampling distribution from the single sample we actually have, without the population in hand. There are two principled paths forward: bootstrapping, which uses the sample itself to simulate the sampling process, and the Central Limit Theorem, which provides a mathematical description of the sampling distribution through theory alone. Together, they transform the concepts of this tutorial into the everyday tools of statistical inference. We will start next with bootstrapping in Chapter 2.
2.7 Take-home points
The population distribution (fixed, usually unknown), the sample distribution (observable, changes with each new sample), and the sampling distribution (describes how a statistic varies across all possible samples of size \(n\)) are three distinct and important concepts that are easy to confuse.
Sampling variability: the fact that different random samples produce different statistics, is the reason a single estimate cannot be blindly trusted. The sampling distribution of a statistic quantifies exactly how much that estimate could plausibly vary, which is what lets us judge how trustworthy it is.
The sampling distribution of a statistic describes how the statistic varies across all possible samples of size \(n\). Two key properties:
- Center: A statistic is unbiased if the mean of its sampling distribution equals the true population parameter; it gets the right answer on average, even though any single estimate will typically differ from the truth.
- Spread: The standard error (SE) is the standard deviation of the sampling distribution. Larger sample sizes (\(n\)) yield smaller standard errors and more precise estimates, but with diminishing returns: to halve the standard error, you must quadruple the sample size.
Even with access to the population, the sampling distribution cannot be calculated directly; we can only approximate it via the surreal approach (drawing many samples and computing the statistic for each). In practice, however, we never have access to the entire population, so we must approximate it from the single sample we have. The two main ways to do this are Bootstrapping and the Central Limit Theorem.
Key R function:
rep_sample_n(size = n, reps = B, replace = FALSE)from theinferpackage draws \(B\) independent random samples of size \(n\) from a data frame, with or without replacement. Paired withsummarise(), it is the main tool for simulating a sampling distribution in this course.