Lecture 23 – The Central Limit Theorem, Choosing Sample Sizes
DSC 10, Fall 2022
Announcements
Lab 7 is due tomorrow at 11:59pm.
Homework 7 is due on Tuesday 11/22 at 11:59pm.
The Final Project is due on Tuesday 11/29 at 11:59pm.
Agenda
The Central Limit Theorem.
Using the CLT to create confidence intervals.
Using CLT-based confidence intervals for hypothesis testing.
Choosing sample sizes.
The Central Limit Theorem
The Central Limit Theorem
The Central Limit Theorem (CLT) says that the probability distribution of the sum or mean of a large random sample drawn with replacement will be roughly normal, regardless of the distribution of the population from which the sample is drawn.
The distribution of the sample mean is centered at the population mean, and its standard deviation is
When we collect a single sample, we won't know the population mean or SD, so we'll use the sample mean and SD as approximations.
Key idea: The CLT allows us to estimate the distribution of the sample mean, given just a single sample, without having to bootstrap!
Confidence intervals
Confidence intervals
Previously, we bootstrapped to construct confidence intervals.
Strategy: Collect one sample, repeatedly resample from it, calculate the statistic on each resample, and look at the middle 95% of resampled statistics.
But, if our statistic is the mean, we can use the CLT.
Computationally cheaper – no simulation required!
In both cases, we use just a single sample to construct our confidence interval.
Constructing a 95% confidence interval through bootstrapping
Let's draw one sample then bootstrap to generate 2000 resample means.
One approach to computing a confidence interval for the population mean involves taking the middle 95% of this distribution.
Middle 95% of a normal distribution
But we didn't need to bootstrap to learn what the distribution of the sample mean looks like. We could instead use the CLT, which tells us that the distribution of the sample mean is normal. Further, its mean and standard deviation are approximately:
So, the distribution of the sample mean is approximately:
Question: What interval on the -axis captures the middle 95% of this distribution?
Recall: Normal approximations
As we saw last class, if a variable is roughly normal, then approximately 95% of its values are within 2 standard deviations of its mean.
Let's use this fact here!
Computing a 95% confidence interval using the CLT
Approximately 95% of a normal curve's area falls within 2 SDs of the mean.
🚨 Don't confuse the sample SD with the SD of the sample mean's distribution!
Visualizing the CLT-based confidence interval
Comparing confidence intervals
We've constructed two confidence intervals for the population mean:
One using bootstrapping,
and one using the CLT.
In both cases, we only used information in my_sample, not the population.
The intervals created using each method are slightly different, because there are some approximations involved:
Bootstrap-based confidence intervals are approximate because they are based on an empirical distribution of many resample means, not all possible resample means.
CLT-based confidence intervals are approximate because the percentage of values that fall within 2 SDs of the mean in a normal distribution is approximately, but not exactly, 95%.
Recap: Confidence intervals for the population mean
A 95% confidence interval for the population mean is given by
This CI doesn't require bootstrapping, and it only requires three numbers – the sample mean, the sample SD, and the sample size!
Bootstrapping vs. the CLT
Bootstrapping still has its uses!
| Bootstrap | CLT | |
|---|---|---|
| Pro | Works for many sample statistics (mean, median, standard deviation). | Only requires 3 numbers – the sample mean, sample SD, and sample size. |
| Con | Very computationally expensive (requires drawing many, many samples from the original sample). | Only works for the sample mean (and sum). |
Activity
We just saw that when , the following is a 95% confidence interval for the population mean.
Question: What value of should we use to create an 80% confidence interval? 90%?
Concept Check ✅ – Answer at cc.dsc10.com
Which one of these histograms corresponds to the distribution of the sample mean for samples of size 100 drawn from a population with mean 50 and SD 20?

Hypothesis testing, revisited
Hypothesis testing for the mean
Before, we bootstrapped to create confidence intervals, which we could use for hypothesis tests.
We can do the same thing with our CLT-based confidence intervals, as well.
Using a confidence interval for hypothesis testing
Null Hypothesis: The population parameter is equal to some value, .
Alternative Hypothesis: The population parameter is not equal to .
Cutoff for p-value: p%.
Strategy:
Construct a (100-p)% confidence interval for the population parameter.
If is not in the interval, we reject the null hypothesis.
If is in the interval, we fail to reject the null hypothesis (since our results are consistent with the null).
Example: Body temperature 🌡
It is widely accepted that the mean human body temperature is 98.6 ºF (or 37 ºC).
We have a dataset of body temperatures, and want to see if our data set is consistent with that belief.
Setting up a hypothesis test
Null Hypothesis: The mean body temperature of all people is 98.6 ºF.
Alternative Hypothesis: The mean body temperature of all people is not 98.6 ºF.
The mean body temperature of all people is a population mean!
CI for mean body temperature
A 95% confidence interval for population mean is given by:
Thanks to the CLT, we have an understanding of the distribution of the sample mean, even though we don't know anything about the distribution of body temperatures.
We don't need to assume that body temperatures are normally distributed to use the CLT!
Careful! This doesn't mean that 95% of temperatures in our sample (or the population) fall in this range!
Conclusion
Using the standard p-value cutoff of 0.05, we reject the null hypothesis because 98.6 ºF is not in the 95% confidence interval for mean body temperature.
What happened?
98.6 ºF is due to Carl Reinhold August Wunderlich, a 19th century physician, who conducted a study when thermometers were new.
This LA Times article states that it's likely that Wunderlich's thermometer was miscalibrated.
A recent article by the Yale School of Medicine states that the average body temperature has declined slightly over the last 150 years by 1.5 ºF, and that body temperature depends on the time of day, age, and sex, among other things.
Choosing sample sizes

Example: Polling
You want to estimate the proportion of UCSD students that use BeReal.
To do so, you will ask a random sample of UCSD students whether or not they use BeReal.
You want to create a confidence interval that has:
A 95% confidence level.
A width of at most 0.06.
The interval (0.21, 0.25) would be fine, but the interval (0.21, 0.28) would not.
Question: How big of a sample do you need? 🤔
Aside: Proportions are just means
The sample we collect will consist of only two unique values:
1, if the student uses BeReal.
0, if they don't use BeReal.
We're interested in the proportion of values in our sample that are 1.
This proportion is the same as the mean of our sample!
For instance, suppose our sample is . Then of the values are . The sample mean is
Key takeaway: The CLT applies in this case as well! The distribution of the proportion of 1s in our sample is roughly normal.
Our strategy
We will:
Collect a random sample.
Compute the sample mean (i.e., the proportion of people who say "yes").
Compute the sample standard deviation.
Construct a 95% confidence interval for the population mean:
Note that the width of our CI is the right endpoint minus the left endpoint:
Our strategy
We want a CI whose width is at most 0.06.
The width of our confidence interval depends on two things: the sample SD and the sample size.
If we know the sample SD, we can find the appropriate sample size by re-arranging the following inequality:
Problem: Before polling, we don't know the sample SD, because we don't have a sample! We don't know the population SD either.
Solution: Find an upper bound – i.e. the largest possible value – for the sample SD and use that.
Upper bound for the standard deviation of a sample
Without any information about the values in a sample, we can't make any guarantees about the standard deviation of the sample.
However, in this case, we know that the only values in our sample will be 0 ("no") and 1 ("yes").
In Homework 7, we introduced a formula for the standard deviation of a collection of 1s and 0s:
Fact: The largest possible value of the SD of a collection of 0s and 1s is 0.5. (This happens when half the values are 0 and half are 1.)
Choosing a sample size
In the sample we will collect, the maximum possible SD is 0.5.
Earlier, we saw that to construct a confidence interval with the desired confidence level and width, our sample size needs to satisfy:
Notice that as the sample SD increases, the required sample size increases.
By using the maximum possible SD above, we ensure that we collect a large enough sample, no matter what the population and sample look like.
Choosing a sample size
By substituting 0.5 for the sample size, we get
While any sample size that satisfies the above inequality will give us a confidence interval that satisfies the necessary properties, it's time-consuming to gather larger samples than necessary. So, we'll pick the smallest sample size that satisfies the above inequality.
Conclusion: We must sample 1112 people to construct a 95% CI for the population mean that is at most 0.06 wide.
Activity
Suppose we instead want an a 95% CI for the population mean that is at most 0.03 wide. What is the smallest sample size we could collect?
Hint: Use the fact that we must sample 1112 people for a 95% CI for the population mean that is at most 0.06 wide.
Click here to see the answer after you've attempted the question yourself.
, so the smallest sample size we could collect is 4445.
Summary, next time
Summary
A 95% confidence interval for the population mean is given by
If we want to construct a confidence interval of a particular width and confidence level for a population proportion:
Choose a confidence level (e.g. 95%) and maximum width (e.g. 0.06).
Solve for the minimum sample size that satisfies both conditions.
Collect a sample of that size.
Use the formula above to construct an interval.
What we've learned about inference
At a high level, the second half of this class has been about statistical inference – using a sample to draw conclusions about the population.
To test whether a sample came from a known population distribution, use "standard" hypothesis testing.
To test whether two samples came from the same unknown population distribution, use permutation testing.
To estimate a population parameter given a single sample, construct a confidence interval using bootstrapping (for most statistics) or the CLT (for the sample mean).
To test whether a population parameter is equal to a particular value, , construct a confidence interval using bootstrapping (for most statistics) or the CLT (for the sample mean), and check whether is in the interval.
Next time
We'll switch our focus to prediction – given a sample, what can I predict about data not in that sample?
In the next 3 lectures, we'll focus on linear regression, a prediction technique that tries to find the best "linear relationship" between two numerical variables.
Along the way, we'll address another idea – correlation.
You will see linear regression in many more courses – it is one of the most important tools in the data science toolkit.