Confidence Intervals
Topic 07 - Confidence Intervals ST1131 1 / 62
1 Introduction
2 Point Estimates
3 Confidence Intervals
4 Confidence Intervals for Population Proportion
Using Confidence Levels Other Than 95%
Interpreting Confidence Intervals
Determining Sample Size
5 Confidence Intervals for Population Mean
The t-distribution
Formula and Assumptions
Determining Sample Size
6 Summary
Topic 07 - Confidence Intervals ST1131 2 / 62
1 Introduction
2 Point Estimates
3 Confidence Intervals
4 Confidence Intervals for Population Proportion
Using Confidence Levels Other Than 95%
Interpreting Confidence Intervals
Determining Sample Size
5 Confidence Intervals for Population Mean
The t-distribution
Formula and Assumptions
Determining Sample Size
6 Summary
Topic 07 - Confidence Intervals ST1131 3 / 62
Statistical Inference
One of the most powerful use of statistics is to make statistical inference
about the population, using sample data.
There are two main types of inference
I estimation of population parameters, and
I testing hypotheses.
Topic 07 - Confidence Intervals ST1131 4 / 62
Types of Estimates
Population parameters have two types of estimates, a point estimate and an
interval estimate.
Definition 1 (Point and Interval Estimates)
A point estimate is a single number that is our best guess for the population
parameter.
An interval estimate is an interval of numbers within which the parameter
value is believed to fall.
Topic 07 - Confidence Intervals ST1131 5 / 62
1 Introduction
2 Point Estimates
3 Confidence Intervals
4 Confidence Intervals for Population Proportion
Using Confidence Levels Other Than 95%
Interpreting Confidence Intervals
Determining Sample Size
5 Confidence Intervals for Population Mean
The t-distribution
Formula and Assumptions
Determining Sample Size
6 Summary
Topic 07 - Confidence Intervals ST1131 6 / 62
Making a Best Guess for a Population Parameter
How do we find a point estimate, for a parameter value?
We can use an appropriate statistic from a random sample.
E.g., for a population mean µ, we can use the sample mean X̄ .
For a population proportion p, we can use the sample proportion p̂.
Topic 07 - Confidence Intervals ST1131 7 / 62
Point Estimates in Breast Cancer Example
Breast Cancer Data, a random sample of 200 PMH users had 79 of them
with breast cancer (BC).
We are interested in p - proportion having BC in the population.
Let p̂ be the proportion of PMH users who developed breast cancer in the
sample, p̂ = 0.395.
This p̂ a point estimate of p.
Topic 07 - Confidence Intervals ST1131 8 / 62
Point Estimate in California Election Example
Let p be the proportion of population voting for Democratic candidate.
From a random sample of 3889 voters, p̂ = 0.531 (mentioned in Topic 06 of
Sampling Distributions).
This p̂ is the point estimate for p.
Topic 07 - Confidence Intervals ST1131 9 / 62
Bill Length of Palmer Penguins
342 Antarctic penguins on the Palmer Archipelago were collected in a study.
The bill length is measured (mm).
Let µ be the average bill length of the population.
From the sample, we obtain X̄ = 43.92.
Topic 07 - Confidence Intervals ST1131 10 / 62
Point Estimates Vary from Sample to Sample
A second sample of size 342 penguins from the same population with
X̄ = 42.5 mm.
Estimates of µ from different samples will not be identical because:
I We are not taking the mean of the entire population.
I We are taking a random sample each time.
A point estimate doesn’t provide an idea about how close it is to the true
value it estimates.
Topic 07 - Confidence Intervals ST1131 11 / 62
A Table of Point Estimates
Recommended sample quantities as point estimates for their population analogs.
Sample quantity Population parameter
X̄ E (X ) or equivalently µ
s2 Var (X ) or equivalently σ 2
s Standard deviation or equivalently σ
X(0.5) q0.5
Topic 07 - Confidence Intervals ST1131 12 / 62
1 Introduction
2 Point Estimates
3 Confidence Intervals
4 Confidence Intervals for Population Proportion
Using Confidence Levels Other Than 95%
Interpreting Confidence Intervals
Determining Sample Size
5 Confidence Intervals for Population Mean
The t-distribution
Formula and Assumptions
Determining Sample Size
6 Summary
Topic 07 - Confidence Intervals ST1131 13 / 62
Interval Estimates
As we pointed out earlier, point estimates are inadequate because they fail
to indicate how close they are to the true population value.
An interval estimate indicates precision by giving an interval of numbers
around the point estimate.
The interval is made up of numbers that are the most believable values for
the unknown parameter, based on the data observed.
Topic 07 - Confidence Intervals ST1131 14 / 62
Confidence Interval
Definition 2
A confidence interval is an interval containing the most believable values for a
parameter. The probability that this method produces an interval that contains
the parameter is called the confidence level.
This is a number chosen to be close to 1. most commonly 0.95. Then the
interval is known as a 95% confidence interval.
Topic 07 - Confidence Intervals ST1131 15 / 62
The General Form for a Confidence Interval
The general form for a confidence interval is
point estimate ± margin of error
Definition 3
I A margin of error measures how accurate the point estimate is likely to be in
estimating a parameter.
I It is a multiple of the standard deviation of the sampling distribution of the point
estimate.
For instance, when the sampling distribution is approximately Normal, a
95% confidence interval has a margin of error equal to 1.96 standard
deviations.
Topic 07 - Confidence Intervals ST1131 16 / 62
1 Introduction
2 Point Estimates
3 Confidence Intervals
4 Confidence Intervals for Population Proportion
Using Confidence Levels Other Than 95%
Interpreting Confidence Intervals
Determining Sample Size
5 Confidence Intervals for Population Mean
The t-distribution
Formula and Assumptions
Determining Sample Size
6 Summary
Topic 07 - Confidence Intervals ST1131 17 / 62
CI for a Population Proportion
Recall that the sampling distribution for sample proportion p̂ was given by
p(1 − p)
p̂ ∼ N p,
n
As such, the formula for the 95% confidence interval for p will be
r
p(1 − p)
p̂ ± 1.96 ×
n
It appears we need the (unknown) p in order to compute the margin of
error!
Topic 07 - Confidence Intervals ST1131 18 / 62
Estimating the Margin of Error
The exact value of the standard deviation of the sampling distribution of a
statistic typically depends on the population parameter values.
To estimate the margin of error, we substitute our best estimate for the
unknown parameter.
Topic 07 - Confidence Intervals ST1131 19 / 62
Back to Formula for Population Proportion
p
The standard error of a sample proportion is then p̂(1 − p̂)/n.
Definition 4 (Confidence Interval for Proportion)
A 95% confidence interval for a population proportion p is
r
p̂(1 − p̂)
p̂ ± 1.96 ×
n
where p̂ denotes the sample proportion based on n observations. This formula
should be used only when n is sufficiently large that np̂(1 − p̂) ≥ 5.
Topic 07 - Confidence Intervals ST1131 20 / 62
Breast Cancer Example
Consider constructing a 95% confidence interval for the proportion of PMH
users who develop breast cancer, p.
r
0.395(1 − 0.395)
0.395 ± 1.96 × = (0.327, 0.463)
200
Topic 07 - Confidence Intervals ST1131 21 / 62
1 Introduction
2 Point Estimates
3 Confidence Intervals
4 Confidence Intervals for Population Proportion
Using Confidence Levels Other Than 95%
Interpreting Confidence Intervals
Determining Sample Size
5 Confidence Intervals for Population Mean
The t-distribution
Formula and Assumptions
Determining Sample Size
6 Summary
Topic 07 - Confidence Intervals ST1131 22 / 62
Where Did 1.96 Come From?
Assume n is large enough. Let SE denote the standard error of p̂ then
p̂ − p
p̂ ∼ N p, SE2 ,
hence, ∼ N(0, 1).
SE
From N(0, 1), we have
p̂ − p
P(−1.96 ≤ ≤ 1.96) = 0.95, which is equivalent to
SE
P p̂ − 1.96SE ≤ p ≤ p̂ + 1.96SE = 0.95
Topic 07 - Confidence Intervals ST1131 23 / 62
Where Did 1.96 Come From?
For a 95% CI, the value 1.96 comes from the N(0, 1): 95% of the area
under a N(0, 1) curve is containing within the interval (-1.96, 1.96).
This ensures that there is a 0.95 probability that the interval contains the
true p.
Topic 07 - Confidence Intervals ST1131 24 / 62
Increasing the Confidence Level
If a 99% CI is required, then we have to identify the interval within which
the area for a N(0, 1) is 0.99, and then use that multiplier for margin of
error.
Topic 07 - Confidence Intervals ST1131 25 / 62
General Procedure for Confidence Interval for Proportion
Let x be the confidence level, e.g. x = 0.95. To find a 100x% CI, the steps are:
1 Find p̂ from the given sample.
2 Ensure that np̂(1 − p̂) ≥ 5. Otherwise, obtain more observations.
3 Find α = 1 − x.
eg, 95% interval --> alpha = 0.05 --> q_0.975
4 Find quantile q1−α/2 from N(0, 1). This q1−α/2 from N(0, 1) is also
denoted as zα/2 .
5 Return the desired confidence interval as
r
p̂(1 − p̂)
p̂ ± q1−α/2 ×
n
Topic 07 - Confidence Intervals ST1131 26 / 62
Computing Confidence Interval of Desired Level
A 99% CI for p — population proportion voting for Jerry Brown is
r
0.531(1 − 0.531)
0.531 ± 2.58 × = (0.51, 0.552)
q_0.995
3889
A 95% confidence interval for p is
r
0.531(1 − 0.531)
0.531 ± 1.96 × = (0.515, 0.547)
q_0.975 3889
An 80% confidence interval for p is
r
0.531(1 − 0.531)
0.531 ± 1.28 × = (0.52, 0.54)
q_0.9 3889
Which interval is wider?
Topic 07 - Confidence Intervals ST1131 27 / 62
1 Introduction
2 Point Estimates
3 Confidence Intervals
4 Confidence Intervals for Population Proportion
Using Confidence Levels Other Than 95%
Interpreting Confidence Intervals
Determining Sample Size
5 Confidence Intervals for Population Mean
The t-distribution
Formula and Assumptions
Determining Sample Size
6 Summary
Topic 07 - Confidence Intervals ST1131 28 / 62
Having “95% Confidence”
The confidence refers to a long-run interpretation.
It describes how well the method performs over many different random
samples.
If we form many 95% confidence intervals for p, then in the long run 95%
of these intervals would contain the true p.
Topic 07 - Confidence Intervals ST1131 29 / 62
The Interpretation for a Specific CI
In the California Election example, we could say: we are 99% confident that
the proportion voting for Jerry Brown in the population falls in (0.51, 0.552).
For the Breast Cancer example, we could say: we are 95% confident that
the proportion of having breast cancer in the population of PMH users falls
in (0.327, 0.463).
Topic 07 - Confidence Intervals ST1131 30 / 62
Error Probability
For a 95% confidence interval, there is a probability of 0.05 that it does not
contain the true parameter.
Hence, if we are dissatisfied with this value, we can increase the confidence
level of the interval.
The consequence is that the interval will become wider.
Topic 07 - Confidence Intervals ST1131 31 / 62
Why Not Use a 100% Interval?
The only confidence interval that for sure will cover the population
proportion is the 100% CI, the interval of [0,1].
But we could have this interval without any sample!
It is better to accept a lower level of confidence, like 99% or 95%, so that
we can significantly narrow down the range of values for the population
parameter.
Topic 07 - Confidence Intervals ST1131 32 / 62
How Does Sample Size Affect Confidence Intervals?
Notice that the formula for a confidence interval is
r
p̂(1 − p̂)
p̂ ± q1−α/2 ×
n
If we kept everything the same but increased the sample size n, then we
would have a smaller margin of error.
For the California Election example, suppose p̂ = 0.531 had been obtained
from a sample of size 50 instead of 3889. Then, a 99% CI would be
r
0.531(1 − 0.531)
0.531 ± 2.58 × = (0.35, 0.71)
50
The length of the confidence interval increases when we reduce the
sample size.
Topic 07 - Confidence Intervals ST1131 33 / 62
Factors Affecting the Length of CI for p
The sample size: the larger the sample size, n, the narrower the interval will
be.
The confidence level: the higher the confidence level (smaller α), the wider
the interval will be.
The true value of p in the underlying population (which we cannot change).
Topic 07 - Confidence Intervals ST1131 34 / 62
1 Introduction
2 Point Estimates
3 Confidence Intervals
4 Confidence Intervals for Population Proportion
Using Confidence Levels Other Than 95%
Interpreting Confidence Intervals
Determining Sample Size
5 Confidence Intervals for Population Mean
The t-distribution
Formula and Assumptions
Determining Sample Size
6 Summary
Topic 07 - Confidence Intervals ST1131 35 / 62
Confidence Interval’s Length/Width
For a (1 − α)100% CI, the formula is
r
p(1 − p)
p̂ ± q1−α/2 ×
n
The length/width of this interval is
r
p(1 − p)
2 × q1−α/2 ×
n
Topic 07 - Confidence Intervals ST1131 36 / 62
How to Determine n?
If we want a (1 − α)100% CI with the length is ≤ D, then solving for n
gives us
2 × q1−α/2 2
n≥ p(1 − p)
D
What value of p to use?
If p is unknown, we use p = 0.5, as it corresponds to the largest possible
value of margin of error for a given α.
It will give us the smallest possible n we should have for the sample.
Topic 07 - Confidence Intervals ST1131 37 / 62
Sample Size in California Election Example
In the California Election example, suppose before starting the survey, we
did not know how many voters to take, but we knew that we wanted to
make a 95% CI, and it should have length of at most 0.1.
Then before collecting sample, we could compute
2
2 × 1.96
n≥ 0.5(0.5) = 384.16
0.1
Thus we only needed to sample (at least) 385 people.
Topic 07 - Confidence Intervals ST1131 38 / 62
1 Introduction
2 Point Estimates
3 Confidence Intervals
4 Confidence Intervals for Population Proportion
Using Confidence Levels Other Than 95%
Interpreting Confidence Intervals
Determining Sample Size
5 Confidence Intervals for Population Mean
The t-distribution
Formula and Assumptions
Determining Sample Size
6 Summary
Topic 07 - Confidence Intervals ST1131 39 / 62
Introduction
Let µ denote the population mean of a quantitative variable.
The method resembles that for a population proportion. The confidence
interval for µ again has the form:
point estimate ± margin of error
The point estimate of µ is sample mean, X̄ .
Topic 07 - Confidence Intervals ST1131 40 / 62
Introduction
In Topic 06 (Sampling Distributions), we saw that the variance of X̄ is σ 2 /n
where σ 2 – the population variance is unknown.
From X̄ ∼ N(µ, σ 2 /n), if we estimate σ 2 by s 2 , then we’ll have
X̄ − µ
√ ∼ tn−1 ,
s/ n
which was fully proved.
tn−1 is used to denote a t-distribution with (n − 1) degrees of freedom.
Topic 07 - Confidence Intervals ST1131 41 / 62
1 Introduction
2 Point Estimates
3 Confidence Intervals
4 Confidence Intervals for Population Proportion
Using Confidence Levels Other Than 95%
Interpreting Confidence Intervals
Determining Sample Size
5 Confidence Intervals for Population Mean
The t-distribution
Formula and Assumptions
Determining Sample Size
6 Summary
Topic 07 - Confidence Intervals ST1131 42 / 62
Properties of the t-distribution
The t-distribution is symmetric about 0, just like a N(0, 1) distribution.
The probabilities under the t-distribution depends on the degrees of
freedom, df .
The t-distribution has thicker tails and more variability than that of N(0, 1).
The larger the value of df , the closer the t-distribution gets to the N(0, 1).
When df is 30 or more, tdf are nearly identical to N(0, 1).
Topic 07 - Confidence Intervals ST1131 43 / 62
Comparing t and N(0, 1)
When df is larger, the tdf -distribution will closer to N(0, 1).
Topic 07 - Confidence Intervals ST1131 44 / 62
Constructing Confidence Interval for µ
√
Since (X̄ − µ)/(s/ n) follows tn−1 , we have
X̄ − µ
P(−tn−1,0.975 ≤ √ ≤ tn−1,0.975 ) = 0.95,
s/ n
where tn−1,0.975 is quantile of probability 0.975 from a tn−1 .
Hence,
s s
P X̄ − tn−1,0.975 √ ≤ µ ≤ X̄ + tn−1,0.975 √ = 0.95
n n
The 95% CI for µ is then
s
X̄ ± tn−1,0.975 √ .
n
Topic 07 - Confidence Intervals ST1131 45 / 62
Quantile values from t-Distribution
For instance,
I t6,0.975 = 2.447 when df = 6.
I t1000,0.975 = 1.962 when df = 1000.
In R, we just need to get
> qt(0.975, 6)
[1] 2.446912
> qt(0.975,1000)
[1] 1.962339
Topic 07 - Confidence Intervals ST1131 46 / 62
1 Introduction
2 Point Estimates
3 Confidence Intervals
4 Confidence Intervals for Population Proportion
Using Confidence Levels Other Than 95%
Interpreting Confidence Intervals
Determining Sample Size
5 Confidence Intervals for Population Mean
The t-distribution
Formula and Assumptions
Determining Sample Size
6 Summary
Topic 07 - Confidence Intervals ST1131 47 / 62
Constructing a 95% Confidence Interval for the Mean
Definition 5 (Confidence Interval for Mean)
Suppose that we have a sample of size n
1 This sample must be obtained by randomization, either by a random sample
or a randomized experiment.
2 The distribution of the data should be approximately normal or symmetric.
Then a 95% confidence interval for a population mean µ is
s
X̄ ± tn−1,0.975 × √
n
where tn−1,0.975 corresponds to the 0.975-quantile of a t-distribution with
(n − 1) degrees of freedom.
Topic 07 - Confidence Intervals ST1131 48 / 62
Baby Weights
Example 1 (Sample of Birth Weights)
We have a random sample of n = 47 weights (in kg) of babies born in
August.
The descriptive summary output for this data is given in the next slide.
We would want to form a 95% confidence interval for µ - mean weight of
all newborn babies in population that are born in August.
Topic 07 - Confidence Intervals ST1131 49 / 62
Summary Output - Baby Weights
Topic 07 - Confidence Intervals ST1131 50 / 62
Constructing a 95% Confidence Interval
From the output, we can see that sample mean X̄ = 3.208 kg, sample
standard deviation s = 0.506, n = 47.
From the t-distribution with df = 46, we have t46,0.975 = 2.01.
Hence the 95% confidence interval is
0.506
3.208 ± 2.01 × √ = (3.06, 3.36)
47
We are 95% confident that the interval (3.06, 3.36) contains µ.
Topic 07 - Confidence Intervals ST1131 51 / 62
General Procedure for Confidence Interval for Mean
Let x be the confidence level. To find a 100x% CI for µ, the steps are:
1 Find X̄ from the given sample.
2 Check the assumptions.
3 Find α = 1 − x and derive tn−1,1−α/2 .
4 Return the desired confidence interval as X̄ ± tn−1,1− α2 × √s
n
Note: If n is large enough and σ is known, then the margin of error is
√
zα/2 (σ/ n) instead.
Topic 07 - Confidence Intervals ST1131 52 / 62
Robustness of Assumptions
Definition 6 (Robustness of Assumptions)
A statistical method is said to be robust with respect to a particular assumption
if it performs adequately even when that assumption is modestly violated.
In slide 48, the statistical method to produce a CI for µ involves 2 assumptions.
The 1st assumption, sample obtained by randomization, is crucial. The
method is not robust to this.
The 2nd assumption, data distribution be normal or symmetric, is not
crucial. The method is robust to this assumption.
If sample size is large enough, we only need to ensure that there’s no
extreme outlier in the sample, and we can proceed.
Topic 07 - Confidence Intervals ST1131 53 / 62
Factors Affecting the Length of CIs for µ
The sample size:the large n the narrower the interval will be.
The confidence level: the higher the confidence level the wider the interval
will be.
The variance σ 2 of the population distribution: we cannot change this
factor.
Topic 07 - Confidence Intervals ST1131 54 / 62
1 Introduction
2 Point Estimates
3 Confidence Intervals
4 Confidence Intervals for Population Proportion
Using Confidence Levels Other Than 95%
Interpreting Confidence Intervals
Determining Sample Size
5 Confidence Intervals for Population Mean
The t-distribution
Formula and Assumptions
Determining Sample Size
6 Summary
Topic 07 - Confidence Intervals ST1131 55 / 62
Intervals of a Pre-specified Length
√
Generally, the length of the CI for µ is of 2 × tn−1,1−α/2 × s/ n.
Suppose we plan to collect a sample which should give us a (1 − α)100%
CI whose length is ≤ D. What size n this sample should have?
We solve
2
2tn−1,1−α/2 s
s
2 × tn−1,1−α/2 × √ ≤ D to get n ≥ .
n D
However, we do not know the RHS when both n and s are unknown!
Topic 07 - Confidence Intervals ST1131 56 / 62
Approximating the Sample Size
In slide 56, there are two unknowns preventing us from computing n:
I Unknown tn−1,1−α/2 : We replace this by q1−α/2 from a N(0, 1) distribution.
We should reduce the impact of this approximation by making sure n will be
at least 30.
I Unknown s: We can estimate s by looking for s from a similar study, or by
conducting a pilot study to get an initial estimate.
Thus the formula to use in practice is
2
2q1−α/2 s
n≥
D
Topic 07 - Confidence Intervals ST1131 57 / 62
Computing Sample Size
Suppose we wish to perform a new study to assess the mean weight of
babies, born to first-time mothers.
We are instructed to obtain a sample with size n such that the length of the
95% CI is at most 0.2 kg. What n should we use for the new sample?
Topic 07 - Confidence Intervals ST1131 58 / 62
Computing Sample Size
Say we are willing to assume that the variability of the weight of babies
born to first-time mothers is as similar as the variability of the weight of
babies born in August (Example 1), then we can estimate s by = 0.5064.
We use q0.975 = 1.96.
Then we should collect n observations for the new study where
2 2
2q1−α/2 s
2(1.96)0.5064
n≥ = = 98.5
D 0.2
Thus, we should collect a new sample which has size n ≥ 99.
Topic 07 - Confidence Intervals ST1131 59 / 62
1 Introduction
2 Point Estimates
3 Confidence Intervals
4 Confidence Intervals for Population Proportion
Using Confidence Levels Other Than 95%
Interpreting Confidence Intervals
Determining Sample Size
5 Confidence Intervals for Population Mean
The t-distribution
Formula and Assumptions
Determining Sample Size
6 Summary
Topic 07 - Confidence Intervals ST1131 60 / 62
What You Should Know
We have learnt how to compute (1 − α)100% Confidence Intervals for the
population mean and for a population proportion.
Given a sample, you should know whether we should have p̂ or X̄ .
Would you be able to apply the following formulas?
r
p̂(1 − p̂)
p̂ ± q1−α/2
n
s
X̄ ± tn−1,1−α/2 × √
n
2
2q1−α/2 s
n≥
D
2 × q1−α/2 2
n≥ p(1 − p)
D
Do you know how to interpret a specific confidence interval?
Topic 07 - Confidence Intervals ST1131 61 / 62
THANK YOU!
Topic 07 - Confidence Intervals ST1131 62 / 62