You are on page 1of 253

STAT 2000 – Unit 1

Carrie Madden

Carrie Madden STAT 2000 – Unit 1 1 / 253


Carrie Madden STAT 2000 – Unit 1 2 / 253
Unit 1 – Inference for the Mean of a Single Population

Unit 1 – Inference for the Mean of a Single


Population

Carrie Madden STAT 2000 – Unit 1 3 / 253


Unit 1 – Inference for the Mean of a Single Population

Probablity Distribution

Definition
The probability distribution of a random variable X tells us what values X
can take and how to assign probabilities to those values.

So, if, X ∼ N (µ, σ) – we can say that X follows a normal probability


distribution.

Carrie Madden STAT 2000 – Unit 1 4 / 253


Unit 1 – Inference for the Mean of a Single Population

Distribution of the Sample Mean

Suppose that, rather than being interested in probability calculations for


some variable on a single individual, we are instead interested in taking a
random sample of size n, and calculating the probability that the sample
mean falls within some range of values.

To calculate such probabilities, we must examine the distribution of the


sample mean.

Carrie Madden STAT 2000 – Unit 1 5 / 253


Unit 1 – Inference for the Mean of a Single Population

Distribution of the Sample Mean

Motivation
What would happen if we repeatedly took samples of the same size, n,
from the population and calculated the sample mean, x̄ .

Carrie Madden STAT 2000 – Unit 1 6 / 253


Unit 1 – Inference for the Mean of a Single Population

Distribution of the Sample Mean

To answer this, we take a random sample of size n from a normal


distribution with mean µ and standard deviation σ. Record the value of
the sample mean. Take another sample of the same size, from the same
distribution and again record the value of the sample mean.

Keep doing this and after you have a sufficiently large number of sample
means, plot their values.

Carrie Madden STAT 2000 – Unit 1 7 / 253


Unit 1 – Inference for the Mean of a Single Population

Distribution of the Sample Mean – Example

Example
The label on a can of Pepsi says the can contains 355 ml. Suppose that in
fact, the fill volumes of cans of Pepsi follow a normal distribution with
mean 355 ml and standard deviation 2 ml.

Carrie Madden STAT 2000 – Unit 1 8 / 253


Unit 1 – Inference for the Mean of a Single Population

Example Continued – Pepsi


R Code for your information:

The set.seed command tells us the number to begin generating a


sequence of random values.
rnorm says we are taking a random sample of n = 1 from a
population with µ = 355 and σ = 2.
Thus we have X ∼ N(355, 2). Histogram of the individual X ’s are on
the next slide.

set.seed(1)
x<-rnorm(1,355,2)
for(i in 1:1000)
{
x<-c(x,rnorm(1, 355, 2))
}

Carrie Madden STAT 2000 – Unit 1 9 / 253


Unit 1 – Inference for the Mean of a Single Population

Example Continued – Pepsi


Histogram of x
200
150
Frequency

100
50
0

350 355 360

Carrie Madden STAT 2000 – Unit 1 10 / 253


Unit 1 – Inference for the Mean of a Single Population

Example Continued – Pepsi

mean(x)

## [1] 354.979

sd(x)

## [1] 2.070066

Carrie Madden STAT 2000 – Unit 1 11 / 253


Unit 1 – Inference for the Mean of a Single Population

Example Continued – Pepsi

Say, we take one sample of 100 cans and calculate the mean fill level x̄ .
We then take a second sample of 100 cans and calculate the mean of that
sample. We repeat this for a large number of samples of size 100, then
make a histogram of all the x̄ ’s we made.
This is what the R code would look like:

Note, we are now taking a sample of n = 100

set.seed(1)
xbar<-mean(rnorm(100,355,2))
for(i in 1:1000)
{
xbar<-c(xbar,mean(rnorm(100, 355, 2)))
}

Carrie Madden STAT 2000 – Unit 1 12 / 253


Unit 1 – Inference for the Mean of a Single Population

Example Continued – Pepsi


Histogram of x−bars
200
150
Frequency

100
50
0

354.4 354.6 354.8 355.0 355.2 355.4 355.6

xbars

Carrie Madden STAT 2000 – Unit 1 13 / 253


Unit 1 – Inference for the Mean of a Single Population

Example Continued – Pepsi

We notice three things:

The distribution of the sample mean X̄ is still normal.


The mean of the distribution of X̄ is the same as the mean of the
population distribution of X . In other words,

µ = 355

The standard deviation of X̄ is equal to


σ 2
√ =√ = 0.2
n 100

Carrie Madden STAT 2000 – Unit 1 14 / 253


Unit 1 – Inference for the Mean of a Single Population

Example Continued – Pepsi

From R, we can actually see:

mean(xbar)

## [1] 354.9955

sd(xbar)

## [1] 0.1933137

Carrie Madden STAT 2000 – Unit 1 15 / 253


Unit 1 – Inference for the Mean of a Single Population

Sampling Distribution

Suppose that X̄ is the mean of a simple random sample of size n drawn


from a large population with mean µ and standard deviation σ. Then the
mean of the sampling distribution of X̄ is µ and its standard deviation is
√σ .
n

If X ∼ N (µ, σ), then


σ
 
X̄ ∼ N µ, √
n

This is known as the sampling distribution of the sample mean X̄ .

Carrie Madden STAT 2000 – Unit 1 16 / 253


Unit 1 – Inference for the Mean of a Single Population

Sampling Distribution

Note
The mean of the sampling distribution of X̄ is equal to the mean of the
population distribution of X , but the standard deviation is lower. This is
due to the fact that averages are less variable than individual observations.

Carrie Madden STAT 2000 – Unit 1 17 / 253


Unit 1 – Inference for the Mean of a Single Population

Sampling Distrbutions – Pepsi Example Revisited

Recall: The label on a can of Pepsi says the can contains 355 ml.
Suppose that in fact, the fill volumes of cans of Pepsi follow a normal
distribution with mean 355 ml and standard deviation 2 ml.
Question
If you buy a six-pack of Pepsi, what is the probability that the mean
volume of Pepsi in the cans is greater than 356 ml?

Solution
   
356−355
P X̄ > 356 = P Z > √2
= P(Z > 1.22) = 1 − P(Z < 1.22) =
6
1 − 0.8888 = 0.1112

Carrie Madden STAT 2000 – Unit 1 18 / 253


Unit 1 – Inference for the Mean of a Single Population

Sampling Distrbutions – Pepsi Example Revisited

Instead of using our Tables, we can use R to find the probability as well.
Since we are finding P(x̄ > 356) (area to the right). We use 1-pnorm
function R. pnorm is the cummulative density function. This is for you
information, but this function just gives us a more accurate value than the
values we see in the tables.

1-pnorm(356,355,2/sqrt(6))

## [1] 0.1103357

Carrie Madden STAT 2000 – Unit 1 19 / 253


Unit 1 – Inference for the Mean of a Single Population

Example Pulse Rates

If the pulse rates of healthy adult women follow a normal distribution with
mean 74 beats per minute and standard deviation 12 beats per minutes,
What is the probability that a simple random sample of 25 women has an
average pulse rate between 68 and 80 beats per minute?
So what we have here is X ∼ N(74, 12). In words, our random variable X
(pulse rates) follow a normal distribution with a mean, µ = 74 and
standard deviation σ = 12.
We are looking for P(68 ≤ x̄ ≤ 80)
12
X̄ ∼ N(74, √ )
25
   
68−74 80−74
P 68 < X̄ < 80 = P √12
<Z < √12
= P(−2.50 < Z < 2.50) =
25 25
P(Z < 2.50) − P(Z < −2.50) = 0.9938 − 0.0062 = 0.9876

Carrie Madden STAT 2000 – Unit 1 20 / 253


Unit 1 – Inference for the Mean of a Single Population

Example Pulse Rates (Cont’d)

The R code to calcuate that probability is below.

pnorm(80, 74, 12/sqrt(25)) - pnorm(68, 74, 12/sqrt(25))

## [1] 0.9875807

Carrie Madden STAT 2000 – Unit 1 21 / 253


Unit 1 – Inference for the Mean of a Single Population

Distribution of the Sample Mean

Let us consider the general situation of a random variable following any


distribution.
What happens to the distribution of the sample mean as we increase the
sample size?
Example
The lifetime of a light bulb is known to follow a right-skewed distribution
with mean 500 hours and standard deviation 500 hours.

Carrie Madden STAT 2000 – Unit 1 22 / 253


Unit 1 – Inference for the Mean of a Single Population

Lightbulb Example
Lifetime of Lightbulbs

Carrie Madden STAT 2000 – Unit 1 23 / 253


Unit 1 – Inference for the Mean of a Single Population

Distribution of Sample Mean

Suppose we take a sample of n = 2 lightbulbs and calculate their mean


lifetime x̄ . Take another sample of size 2 and do the same thing. We
repeat this many times and plot our values of x̄ on a histogram:
Recall:
Lifetimes (X )follow an exponential (right-skewed) distribution with a mean
of 500 hours and a standard deviation of 500 hours.

Carrie Madden STAT 2000 – Unit 1 24 / 253


Unit 1 – Inference for the Mean of a Single Population

Distribution of Sample Means


Histogram of xbar
300
250
200
Frequency

150
100
50
0

0 500 1000 1500 2000

xbar

Carrie Madden STAT 2000 – Unit 1 25 / 253


Unit 1 – Inference for the Mean of a Single Population

Distribution of Sample Means

The R code used to produce that histogram is:

xbar<-mean(rexp(2,rate=(1/500)))
for(i in 1:1000)
{
xbar<-c(xbar,mean(rexp(2,rate=(1/500))))
}

Carrie Madden STAT 2000 – Unit 1 26 / 253


Unit 1 – Inference for the Mean of a Single Population

Distribution of Sample Means


We can now see the mean and standard deviation of the sampling
distribution of x̄ ;
Histogram of xbar
250
200
Frequency

150
100
50
0

0 500 1000 1500 2000 2500

Carrie Madden STAT


xbar2000 – Unit 1 27 / 253
Unit 1 – Inference for the Mean of a Single Population

Distribution of Sample Means

We would expect the mean to be: µ = 500


500
The standard deviation of √ = 353.55
2
You can see the results from the R output below (they are very close):

mean(xbar)

## [1] 500.8593

sd(xbar)

## [1] 366.4374

Carrie Madden STAT 2000 – Unit 1 28 / 253


Unit 1 – Inference for the Mean of a Single Population

Distribution of the Sample Mean


Now we take an SRS of n = 5 light bulbs and calculate the mean lifetime
x̄ . Take another sample of size 5 and do the same thing. We repeat this
many times and plot our values of x̄ on a histogram:
Histogram of xbar
200
150
Frequency

100
50
0

Carrie Madden STAT 2000 – Unit 1 29 / 253


Unit 1 – Inference for the Mean of a Single Population

Distribution of the Sample Mean

xbar<-mean(rexp(5,rate=(1/500)))
for(i in 1:1000)
{
xbar<-c(xbar,mean(rexp(5,rate=(1/500))))
}

Carrie Madden STAT 2000 – Unit 1 30 / 253


Unit 1 – Inference for the Mean of a Single Population

Distribution of Sample Means

We would expect the mean to be: µ = 500


500
The standard deviation of √ = 223.607
5
You can see the results from the R output below (they are very close):

mean(xbar)

## [1] 496.9203

sd(xbar)

## [1] 232.9599

Carrie Madden STAT 2000 – Unit 1 31 / 253


Unit 1 – Inference for the Mean of a Single Population

Distribution of Sample Mean


Now we take an SRS of n = 50 light bulbs and calculate the mean lifetime
x̄ . Take another sample of size 50 and do the same thing. We repeat this
many times and plot our values of x̄ on a histogram:
Histogram of xbar
250
200
150
Frequency

100
50
0

Carrie Madden STAT 2000 – Unit 1 32 / 253


Unit 1 – Inference for the Mean of a Single Population

Distribution of the Sample Mean

xbar<-mean(rexp(50,rate=(1/500)))
for(i in 1:1000)
{
xbar<-c(xbar,mean(rexp(50,rate=(1/500))))
}

Carrie Madden STAT 2000 – Unit 1 33 / 253


Unit 1 – Inference for the Mean of a Single Population

Distribution of the Sample Mean

You can see what is happening to the shape of the distribution as the
sample size increases.
500
We expect the mean = 500 and the standard deviation = √ = 70.71
50

Carrie Madden STAT 2000 – Unit 1 34 / 253


Unit 1 – Inference for the Mean of a Single Population

Distribution of the Sample Mean

mean(xbar)

## [1] 500.1796

sd(xbar)

## [1] 72.23384

See how close they are now.

Carrie Madden STAT 2000 – Unit 1 35 / 253


Unit 1 – Inference for the Mean of a Single Population

Central Limit Theorem

This results leads us to one of the fundamental theorems in statistics:


Central Limit Theorem
Take an SRS of size n from any population with mean µ and standard
deviation σ. When n is large, the sampling distribution of the sample is
approximately normal with a man of µ and a standard deviation √σn .

σ
 
X̄ ∼ N µ, √
n

Carrie Madden STAT 2000 – Unit 1 36 / 253


Unit 1 – Inference for the Mean of a Single Population

Central Limit Theorem

The sample size required for a sampling distribution to be approximately


normal depends on the original distribution.
Sampling distribution of the sample mean for symmetric distributions
approach the normal distribution much more quickly than those for
severely skewed distributions.

Carrie Madden STAT 2000 – Unit 1 37 / 253


Unit 1 – Inference for the Mean of a Single Population

Lightbulb Example

Recall the example for the lifetimes of lightbulbs. Recall lifetimes followed
a right-skewed distribution with µ = 500 and σ = 500
Example
What is the probability that a random sample of 40 light bulbs has a
mean lifetime greater than 600 hours?

Even though the distribution of lifetimes is not normal, the sample size
(here n = 40) is large enough that we can use the Central Limit Theorem
to calculate this probability, since the distribution of X̄ is approximately
normal.

Carrie Madden STAT 2000 – Unit 1 38 / 253


Unit 1 – Inference for the Mean of a Single Population

Lightbulb Example

The probability that the mean lifetime of the 40 bulbs exceeds 600 hours is
approximately :
Solution
   
600−500
P X̄ > 600 ≈ P Z > 500

= P(Z > 1.26) = 1 − P(Z < 1.26) =
40
1 − 0.8962 = 0.1038

Carrie Madden STAT 2000 – Unit 1 39 / 253


Unit 1 – Inference for the Mean of a Single Population

Lightbulb Example Using R

1-pnorm(600,500,500/sqrt(40))

## [1] 0.1029516

Carrie Madden STAT 2000 – Unit 1 40 / 253


Unit 1 – Inference for the Mean of a Single Population

Distribution of the Sample Mean

In summary:

If the mean and the standard deviation of a random variable X are µ


and σ, respectively, then regardless of the distribution of X , the mean
of X̄ is µ and the standard deviation of X̄ is √σn .
If X follows a normal distribution with mean µ and standard deviation
σ, then the sampling distribution of the sample mean X̄ is normal with
mean µ and standard deviation √σn , regardless of the sample size n.
If X follows any distribution with mean µ and standard deviation σ,
then the sampling distribution of the sample mean X̄ is approximately
normal with mean µ and standard deviation √σn , provided that the
sample size is large.

Carrie Madden STAT 2000 – Unit 1 41 / 253


Unit 1 – Inference for the Mean of a Single Population

Statistical Inference

We get data from a sample, but we are often not satisfied with
information just about the sample itself. We would like to use this sample
data to infer something about the population of interest.
Statistical inference provide methods for drawing conclusions about a
population from sample data.

Carrie Madden STAT 2000 – Unit 1 42 / 253


Unit 1 – Inference for the Mean of a Single Population

Statistical Inference

We can never be sure that our sample data fairly represent the population.
In order to quantify this uncertainty, in statistical inference we use the
language of probability.
Like probability, the foundation of inference lies on predictable long-run
behaviour.
By taking “good” sample (i.e.: SRS), we can draw conclusions with a high
probability of being correct.

Carrie Madden STAT 2000 – Unit 1 43 / 253


Unit 1 – Inference for the Mean of a Single Population

Statistical Inference
Suppose a random variable X follows a normal distribution with mean µ
and standard deviation σ. We take a simple random sample of n
individuals from the population. Recall that a level C confidence interval
for the population mean µ is calculated as
σ
x̄ ± z ∗ √
n

where:

x̄ is the estimate
z ∗ is the critical value such that

P (−z ∗ ≤ Z ≤ z ∗ ) = C

z ∗ √σn is the margin of error

Carrie Madden STAT 2000 – Unit 1 44 / 253


Unit 1 – Inference for the Mean of a Single Population

Statistical Inference
The confidence interval is the middle area. For example, a 95% confidence
interval woud have the shaded area as 0.95, with 0.025 area in either tail.
This falls between z = −1.96 and z = 1.96
0.4
0.3
0.2
y

0.1
0.0

Carrie
−4 Madden −2 STAT 2000
0 – Unit 1 2 4 45 / 253
Unit 1 – Inference for the Mean of a Single Population

Statistical Inference

For interest only, this is the code used to produce the picture on the
previous slide:

x=seq(-4,4,length=200)
y=dnorm(x,mean=0,sd=1)
plot(x,y,type="l")
x=seq(-1.96,1.96,length=100)
y=dnorm(x,mean=0,sd=1)
polygon(c(-1.96,x,1.96),c(0,y,0),col="blue")

Carrie Madden STAT 2000 – Unit 1 46 / 253


Unit 1 – Inference for the Mean of a Single Population

Confidence Intervals – Example

Example
The sentence times for criminals convicted of a particular crime are known
to follow a normal distribution with standard deviation σ = 25.8 months.
The sentences (in months) of a random sample of ten criminals convicted
of this crime are shown below:
136 102 84 150 115
98 125 176 120 74

Calculate a 95% confidence interval for the true mean sentence time for all
criminals convicted of this crime.

Carrie Madden STAT 2000 – Unit 1 47 / 253


Unit 1 – Inference for the Mean of a Single Population

Confidence Intervals – Example (Cont’d)

Solution
A 95% confidence interval for the true mean sentence time for all criminals
convicted of this crime is
σ 25.8
 
x̄ ± z ∗ √ = 118.0 ± 1.96 √
n 10
= 118.0 ± 16.0 = (102.0, 134.0)

where z ∗ = 1.96 is the upper 0.025 critical value from the standard normal
distribution, i.e.,
P (−1.96 ≤ Z ≤ 1.96) = 0.95

Carrie Madden STAT 2000 – Unit 1 48 / 253


Unit 1 – Inference for the Mean of a Single Population

Critical Values

Critical values, z ∗ for some common confidence levels (90%, 95%, 99%,
etc.) can be found in the last row of Table 3. We interpret the confidence
interval as follows:
Interpretation of Confidence Interval
If we took repeated sample of ten criminals and calculated the interval in a
similar manner, then 95% of such intervals would contain the true mean
sentence time for all criminals convicted of this crime.

Carrie Madden STAT 2000 – Unit 1 49 / 253


Unit 1 – Inference for the Mean of a Single Population

Critical Values with R


qnorm(0.05/2, lower.tail=FALSE)

## [1] 1.959964

#or

qnorm(0.975, lower.tail = FALSE)

## [1] -1.959964

#0.975 = 0.95 + 0.025

We use the qnorm function. The probability (since we are looking to have
a middle = 0.95) is going to leave 0.025 in either tail. That is the reason
we divide by 2, and set the lower tail probability to false (because, once
again, it’s a two-sided critical value.)
Carrie Madden STAT 2000 – Unit 1 50 / 253
Unit 1 – Inference for the Mean of a Single Population

Confidence Intervals in R

Going back to our previous example, here is the R code:

#First I will create a vector of the data.

x<-c(136, 102, 84, 150, 115, 98, 125, 176, 120, 74)
xbar <- mean(x)
sigma <- 25.8
#from the question this is the population standard deviation

Carrie Madden STAT 2000 – Unit 1 51 / 253


Unit 1 – Inference for the Mean of a Single Population

Confidence Interval Example R Code Cont’d

error <- (qnorm(0.05/2, lower.tail = FALSE)*(sigma/sqrt(10)))

left <- xbar - error

right<- xbar + error

left

## [1] 102.0093

right

## [1] 133.9907

Carrie Madden STAT 2000 – Unit 1 52 / 253


Unit 1 – Inference for the Mean of a Single Population

Practice Question

An airport manager would like to estimate the true mean number of


minutes passengers arrive before their scheduled flight departure. Suppose
it is known that arrival times follow a normal distribution with standard
deviation 15 minutes. A random sample of 9 passengers arrived an average
of 70 minutes before their flight. A 98% confidence interval for µ is:
A (58.37, 81.63)
B (59.73, 80.27)
C (65.10, 74.90)
D (57.62, 82.38)
E (61.45, 78.55)

Carrie Madden STAT 2000 – Unit 1 53 / 253


Unit 1 – Inference for the Mean of a Single Population

Confidence Intervals (Cont’d)

Below is a picture of what we are doing:

Note that all points falling within


two standard deviations of µ (we
know this to be 95%) catch the
value of the population mean when
stretched on either side by the
margin of error.

Carrie Madden STAT 2000 – Unit 1 54 / 253


Unit 1 – Inference for the Mean of a Single Population

Practice Question
The manager at a grocery store would like to estimate the true mean
amount of money spent by customers in the express lane. She selects a
simple random sample of 50 receipts and calculates a 97% confidence
interval for µ to be ($15.50, $20.25). The confidence interval can be
interpreted as, in the long run,
A 97% of similarly constructed intervals would contain the population
mean.
B 97% of similarly constructed interval would contain the sample mean.
C 97% of all customers in the express lane spend between $15.50 and
$20.25.
D 97% of samples of 50 customers will have means between $15.50 and
$20.25.
E 97% of customers who are spending between $15.50 and $20.25 use
the express lane.
Carrie Madden STAT 2000 – Unit 1 55 / 253
Unit 1 – Inference for the Mean of a Single Population

Confidence Interval Example

Example
Suppose we wish to find a 92% confidence interval for µ:
We find the value z ∗ such that

P (−z ∗ ≤ Z ≤ z ∗ ) = 0.92

Therefore,
P (Z ≤ z ∗ ) = 0.92 + 0.04 = 0.96
From Table 2, this corresponds to the critical value z ∗ = 1.75. Therefore,
our 92% confidence interval is thus:
σ 25.8
 

X̄ ± z √ = 118.0 ± 1.75 √
n 10
= 118.0 ± 14.3 = (103.7, 132.3)

Carrie Madden STAT 2000 – Unit 1 56 / 253


Unit 1 – Inference for the Mean of a Single Population

Confidence Interval Example (Cont’d) Using R

We can also use R to find the critical value;


0.92 in the centre leaves 0.08 in tails.

qnorm(0.08/2, lower.tail = FALSE)

## [1] 1.750686

#or

qnorm(0.96, lower.tail = FALSE) # 0.96 = 0.92 + 0.04

## [1] -1.750686

Carrie Madden STAT 2000 – Unit 1 57 / 253


Unit 1 – Inference for the Mean of a Single Population

Confidence Intervals in R

Going back to our previous example, here is the R code:

#First I will create a vector of the data.

x<-c(136, 102, 84, 150, 115, 98, 125, 176, 120, 74)
xbar <- mean(x)
sigma <- 25.8
#from the question this is the population standard deviation

Carrie Madden STAT 2000 – Unit 1 58 / 253


Unit 1 – Inference for the Mean of a Single Population

Confidence Interval Example R Code Cont’d

error <- (qnorm(0.08/2, lower.tail = FALSE)*(sigma/sqrt(10)))

left <- xbar - error

right<- xbar + error

left

## [1] 103.7167

right

## [1] 132.2833

Carrie Madden STAT 2000 – Unit 1 59 / 253


Unit 1 – Inference for the Mean of a Single Population

Practice Question

We measure the contents of a random sample of 35 bottles of cough syrup


and we calculate a mean of 252 ml. It is known that the contents of a
bottle of cough syrup follow a normal distribution with a standard
deviation of 1.5 ml. An 82% confidence interval for µ is:
 
1.5
A 252 ± 1.48 √
35
 
1.5
B 252 ± 1.34 √
35
 
1.5
C 252 ± 0.82 √
35
 
1.5
D 252 ± 0.92 √
35
 
1.5
E 252 ± 1.28 √
35

Carrie Madden STAT 2000 – Unit 1 60 / 253


Unit 1 – Inference for the Mean of a Single Population

Recall previous Example

Recall our two previous confidence intervals:

92% confidence interval: (103.7, 132.3)


95% confidence interval: (102.0, 134.0)

Notice that as the confidence level increase, so too does the margin of
error (and hence the length of the confidence interval).
If we increase the confidence level, we must sacrifice our precision of
estimation. If we want to be more sure that our interval contains µ, we
have to expand the interval!

Carrie Madden STAT 2000 – Unit 1 61 / 253


Unit 1 – Inference for the Mean of a Single Population

Confidence Intervals - Question

We would ideally like to use a high confidence level and obtain a narrow
confidence interval, but we have seen
that there is a trade-off between the confidence level and the margin of error.

How can we reduce the length of the interval without sacrificing our
precision of estimation?

Carrie Madden STAT 2000 – Unit 1 62 / 253


Unit 1 – Inference for the Mean of a Single Population

Confidence Interval – Increasing sample size

In our previous example, suppose we had instead selected a sample of 40


criminals and that we had calculated a sample mean sentence time of
118.0 months. A 95% confidence interval for µ is then:

σ 25.8
 

x̄ ± z √ = 118.0 ± 1.96 √
n 40
= 118.0 ± 8.0 = (110.0, 126.0)

Carrie Madden STAT 2000 – Unit 1 63 / 253


Unit 1 – Inference for the Mean of a Single Population

R practice

To practice on your own, go back through and find the R code to produce
this confidence interval.
Note
You will not have to start by entering the vector, since we have increased
the observations to 40, and x̄ = 118 (still the same)

Carrie Madden STAT 2000 – Unit 1 64 / 253


Unit 1 – Inference for the Mean of a Single Population

Confidence Intervals – Sample Size

Hence, we have seen the following:

95% confidence interval when n = 10:

(102.0, 134.0)

95% confidence interval when n = 40:

(110.0, 126.0)

Notice that a higher sample size results in a lower margin of error (and
hence a narrower confidence interval). In fact, we see that taking a sample
size that is four times greater results in a margin of error only half as large.

Carrie Madden STAT 2000 – Unit 1 65 / 253


Unit 1 – Inference for the Mean of a Single Population

Confidence Interval – Increasing n

Increasing√the sample size by a factor of k reduces the margin of error by a


factor of k.
We can always reduce the margin of error by increasing our sample size.
As is always the case in statistics, a higher sample size leads to more
accurate results.

Carrie Madden STAT 2000 – Unit 1 66 / 253


Unit 1 – Inference for the Mean of a Single Population

Practice Question

We would like to construct a confidence interval to estimate the mean µ of


some variable X . Which of the following combinations of confidence level
and sample size will produce the widest interval?
A 90% confidence, n = 10
B 95% confidence, n = 10
C 95% confidence, n = 20
D 99% confidence, n = 10
E 99% confidence, n = 20

Carrie Madden STAT 2000 – Unit 1 67 / 253


Unit 1 – Inference for the Mean of a Single Population

Sample Size Determination

When collecting a sample, it is always wise to consider the purpose of our


data collection. We would often like to achieve a certain precision of
estimation. To accomplish this, we require a sufficient sample size.
Ideally, we would like to have a small margin of error, together with a high
confidence level (i.e.: we want the interval to contain the true value of µ
with a high probability.)
This can all be achieved by choosing the appropriate sample size.

Carrie Madden STAT 2000 – Unit 1 68 / 253


Unit 1 – Inference for the Mean of a Single Population

Sample Size Determination

Let m denote the margin of error:


σ
m = z∗ √
n

Therefore, it can be shown that, by solving for n,


 ∗ 2
z σ
n=
m

Carrie Madden STAT 2000 – Unit 1 69 / 253


Unit 1 – Inference for the Mean of a Single Population

Sample Size Determination

Example
Suppose it is known that the nicotine content of a certain brand of
cigarettes follows a normal distribution with standard deviation 0.1 mg.
We would like to take a sample of cigarettes large enough to estimate the
true mean nicotine content to within 0.04 mg with 98% confidence. How
many cigarettes do we need to sample in order to achieve this?

Carrie Madden STAT 2000 – Unit 1 70 / 253


Unit 1 – Inference for the Mean of a Single Population

Sample Size Determination – Example

Solution
We know that

z ∗ = 2.326 σ = 0.1 m = 0.04

Therefore,
 ∗ 2 2
z σ 2.326(0.1)

n= =
m 0.04
= 33.81 ≈ 34

We need a minimum sample of 34 cigarettes. Note that we always round


up, as we calculated that we need a sample of at least 33.81 cigarettes.
(We would even round the value 33.01 up to 34).

Carrie Madden STAT 2000 – Unit 1 71 / 253


Unit 1 – Inference for the Mean of a Single Population

Example – R Code

sigma <- 0.1


moe<-0.04
zstar<- qnorm(0.02/2, lower.tail = FALSE)

n<-(((zstar*sigma)/moe)^2)
n

## [1] 33.82434

Carrie Madden STAT 2000 – Unit 1 72 / 253


Unit 1 – Inference for the Mean of a Single Population

Sample Size Determination – Example

Example
Now suppose that we decide that a margin of error of 0.04 mg is too large
and we would like to estimate the true mean nicotine content to within
0.02 mg with 98% confidence (i.e., cut the margin of error in half).

Solution
We require a sample size of
 ∗ 2 2
z σ 2.326(0.1)

n= =
m 0.02
= 135.26 ≈ 136

Carrie Madden STAT 2000 – Unit 1 73 / 253


Unit 1 – Inference for the Mean of a Single Population

Sample Size Determination – Example

For practice, try to reproduce the R code for the above example and see if
you get the same answer.

Carrie Madden STAT 2000 – Unit 1 74 / 253


Unit 1 – Inference for the Mean of a Single Population

Confidence Intervals – Margin of Error

Notice that when we cut the margin of error in half, we require four times
the sample size.
Note
In general, if we want to reduce the margin of error by a factor of k, we
need a sample that is k 2 times as large.

If we want to reduce the margin of error to one third its original value, we
need nine times more individuals in our sample, etc.

Carrie Madden STAT 2000 – Unit 1 75 / 253


Unit 1 – Inference for the Mean of a Single Population

Practice Question

We would like to estimate the true mean number of hours adults sleep at
night. Suppose that sleep time is knowns to follow a normal distribution
with standard deviation 1.5 hours. What sample size is required in order to
estimate the true mean to within 0.5 hours with 96% confidence?
A 19
B 24
C 38
D 47
E 53

Carrie Madden STAT 2000 – Unit 1 76 / 253


Unit 1 – Inference for the Mean of a Single Population

Practice Question

A real estate agent would like to estimate the true mean value of all
houses in Winnipeg. She calculates that, in order to estimate the true
mean to within $10,000 with 95% confidence, she need to select a sample
of 90 houses in Winnipeg. What sample size would be required to estimate
the true mean value of all houses in Winnipeg to within $5,000 with 95%
confidence?
A 45
B 127
C 180
D 360
E 8100

Carrie Madden STAT 2000 – Unit 1 77 / 253


Unit 1 – Inference for the Mean of a Single Population

Some Cautions
Our formula for the confidence interval holds only if the data were
collected using an SRS. There is no correct way to do proper
inference using data collected haphazardly. Good formulas cannot
rescue us from pro sampling methods.
Since the sample mean is strongly influenced by outliers, so too is the
confidence interval.
We are using the true population standard deviation σ in our
calculations. In practice, this is not a realistic assumption. We will
see a proper method for constructing confidence intervals when we
only have the sample standard deviation s. We make this
unreasonable assumption now to establish the framework for building
confidence intervals.
The margin of error covers only random sampling error. It does not
reflect any degree of undercoverage, nonresponse, or other forms of
bias.
Carrie Madden STAT 2000 – Unit 1 78 / 253
Unit 1 – Inference for the Mean of a Single Population

Hypothesis Testing

Confidence intervals represent the first of two kinds of inference we will


study. The second common type of inference is called hypothesis testing.
A hypothesis test has a different goal than confidence intervals. It helps us
to assess the evidence provided for some claim concerning a population.

Carrie Madden STAT 2000 – Unit 1 79 / 253


Unit 1 – Inference for the Mean of a Single Population

Hypothesis Testing

In other words, we have some claim about the value of some population
parameter and we would like to determine whether there is evidence to
support this claim. We accomplish this by looking at sample data and
seeing if they are representative of the claim. We can prove that a
parameter has any particular value, so we try to reach our conclusions with
a high probability of being correct. We have some new vocabulary in
hypothesis testing, but the idea is a simple one:

“An outcome that would rarely occur if an assumption were true is good
evidence that the assumption is not true.”

Carrie Madden STAT 2000 – Unit 1 80 / 253


Unit 1 – Inference for the Mean of a Single Population

Speeding Example

Example
The parent council at an elementary school appeals to the municipal
government to install a red light camera at a nearby intersection. The
council claims that the average speed of motorists at the intersection is
greater than the posted speed limit of 60 km/h. Suppose it is known that
speeds of vehicles at the intersection follow a normal distribution with
standard deviation of 15 km/h. A city worker is sent to measure the
speeds of a random sample of 50 motorists at the intersection. The
sample mean speed of the vehicles is 66 km/h. Is this enough evidence to
conclude that the true mean speed of all drivers at the intersection is
greater than 60 km/h? That is, should a red light camera be installed?

Carrie Madden STAT 2000 – Unit 1 81 / 253


Unit 1 – Inference for the Mean of a Single Population

Speeding Example (Cont’d)

We can not just say that 66 > 60, so “yes, the mean speed at the
intersection is above the speed limit”. We must ask:

If the true mean speed of motorist at the intersection really was 60 km/h,
how likely would it be to observe a sample mean as extreme as 66 km/h?

Note that extreme in this case, means high

Carrie Madden STAT 2000 – Unit 1 82 / 253


Unit 1 – Inference for the Mean of a Single Population

Speeding Example (Cont’d)

If the probability is low, then we can conclude that the mean speed really
is higher than the limit. IF the probability is not sufficiently low, we have
no conclusive evidence to support the claim.

Carrie Madden STAT 2000 – Unit 1 83 / 253


Unit 1 – Inference for the Mean of a Single Population

Speeding Example (Cont’d)

The first step is to assume that the true mean speed really is equal to 60
km/h; that is, we assume
µ = µ0 = 60
Now if this is true, what is the probability of observing a sample
mean at least as high as 66 km/h? We have the tools to find this
probability!

Carrie Madden STAT 2000 – Unit 1 84 / 253


Unit 1 – Inference for the Mean of a Single Population

Speeding Example (Cont’d)

The probability of observing a value of X̄ at least as high as 66 when the


true mean is 60 is found to be:

 
  66 − 60 
P X̄ ≥ 66 = P Z ≥
√15
50
= P (Z ≥ 2.83) = 1 − P(Z < 2.83)
= 1 − 0.9977 = 0.0023

If the true mean speed of vehicles at this intersection were 60


km/h, then the probability of observing a sample mean speed at
least as high as 66 would only be 0.0023.

Carrie Madden STAT 2000 – Unit 1 85 / 253


Unit 1 – Inference for the Mean of a Single Population

Speeding Example (Cont’d) – R Code


xbar<-66
mu<-60
n<-50
sigma<-15

z<-((xbar-mu)/(sigma/sqrt(n)))

## [1] 2.828427
#P-value

1 - pnorm(z)

## [1] 0.002338867
Carrie Madden STAT 2000 – Unit 1 86 / 253
Unit 1 – Inference for the Mean of a Single Population

Speeding Example (Cont’d) – R Code Explained

All I have done in the previous code is set the variables with the fixed
values from the problem. I have calculated our test statistic z, then
“called” it so you can see the test statistic printed out. Then found our
P-value using our pnorm function, and since we are looking for the area to
the right, I have the 1−.

Carrie Madden STAT 2000 – Unit 1 87 / 253


Unit 1 – Inference for the Mean of a Single Population

Speeding Example (Cont’d)

We conclude that, since this probability is so low, the true mean speed of
vehicles at the intersection really is above the posted limit. It is
possible, but very unlikely, that the true mean is as low as 60.
The probability of observing such a high mean sample speed given the
assumption that µ = 60 is small enough that we are willing to believe the
council’s claim. Based on these findings, the municipal government
decides to install a camera at the intersection.

Carrie Madden STAT 2000 – Unit 1 88 / 253


Unit 1 – Inference for the Mean of a Single Population

Speeding Example (Cont’d)

Note that there is always a certain probability that we will be wrong.


Maybe this was an exceptional sample of unusually fast vehicles. However,
we are able to conclude in favour of the council’s claim with a reasonably
high likelihood of being correct.
Note also that we are not testing the fact that these data follow a normal
distribution. This is an assumption and the probability is only accurate if
this assumption is valid (or if the sample size is reasonably high to use the
CLT).

Carrie Madden STAT 2000 – Unit 1 89 / 253


Unit 1 – Inference for the Mean of a Single Population

Hypothesis Testing

For this reason, we should look at the distribution of the data prior to
conducting a test (especially if the sample size is low) to see if the
assumption of normality appears to be reasonable. As mentioned,
hypothesis tests have their own distinct vocabulary.
Because we are interested in the value of a parameter for the whole
population, we always express our statements of interest in terms of
population parameters.

Carrie Madden STAT 2000 – Unit 1 90 / 253


Unit 1 – Inference for the Mean of a Single Population

Null Hypothesis

The statements of claim we are testing are expressed as two hypotheses:


The statement being tested in a statistical test is called the null
hypothesis, denoted H0 . The test is designed to asses the strength of
evidence agains the null hypothesis.

H0 is always a statement of “no difference” or “no effect”. It will


always be expressed is the form of an equality.

Carrie Madden STAT 2000 – Unit 1 91 / 253


Unit 1 – Inference for the Mean of a Single Population

Alternative Hypothesis

The statement making the claim which we are trying to support is called
the alternative hypothesis, denoted Ha , which will always be expressed as
an inequality.
The null and alternative hypotheses are precise statements of what claims
we are testing. They are both always given in terms of the population
parameter µ. The hypotheses can be stated in either words or in symbols.

Carrie Madden STAT 2000 – Unit 1 92 / 253


Unit 1 – Inference for the Mean of a Single Population

P-value

Note that we assume the null hypothesis is true and calculate the
probability of observing a value of the sample mean at least as extreme as
the one observed.
This probability is called the P-value of the test. The lower the P-value,
the less likely it would have been to observe a value of x̄ at least as
extreme as the one observed if H0 were true. In other words, the lower the
P-value, the stronger our evidence against the null hypothesis.

Carrie Madden STAT 2000 – Unit 1 93 / 253


Unit 1 – Inference for the Mean of a Single Population

Level of Significance

How low must the P-value be before we are willing to reject the null
hypothesis in favour of the alternative claim? For example, if the P-value
is 0.08, do we consider this to be convincing enough evidence to say the
null hypothesis is false?
Prior to the test, we must choose a level of significance α, to which we
will compare the P-value.

If the P-value is less than or equal to α, we will reject H0 .


If the P-value is greater than α, we fail to reject H0 .

Carrie Madden STAT 2000 – Unit 1 94 / 253


Unit 1 – Inference for the Mean of a Single Population

Level of Significance (Cont’d)

As such, we can think of α as the maximum P-value for which the null
hypothesis will be rejected.
The most common values of α are 0.1, 0.05 and 0.01.

Carrie Madden STAT 2000 – Unit 1 95 / 253


Unit 1 – Inference for the Mean of a Single Population

Speeding Example – Revisited

We will now conduct the formal hypothesis test for our speeding example.
1 Level of significance
Let α = 0.05
(We will be willing to conclude in favour of the council only if the
P-value is less than or equal to 0.05)
2 Hypotheses
H0 : µ = 60
Ha : µ > 60

Carrie Madden STAT 2000 – Unit 1 96 / 253


Unit 1 – Inference for the Mean of a Single Population

Speeding Example – Revisited

3 Decision Rule
Reject H0 if the P-value≤ α = 0.05.
(The decision rule is a precise statement of that must happen in order
for us to reject the null hypothesis.)
4 Test Statistic
X̄ − µ0 66 − 60
z= σ = = 2.83
√ 15

n 50
(The test statistic is a measure of the compatibility between the null
hypothesis and our data.)
Note that this is calculated assuming the null hypothesis is true.

Carrie Madden STAT 2000 – Unit 1 97 / 253


Unit 1 – Inference for the Mean of a Single Population

Speeding Example – Revisited

5 Calculate the P-value

 
P-value = P X̄ ≥ 66|µ = 60 = P (Z ≥ 2.83) = 1 − P (Z < 2.83) =
1 − 0.9977 = 0.0023

Interpretation of the P-value


If the true mean speed of vehicles at this intersection were 60, the
probability of taking a sample of 50 vehicles with a mean speed of at least
66 km/h would only be 0.0023.

Carrie Madden STAT 2000 – Unit 1 98 / 253


Unit 1 – Inference for the Mean of a Single Population

Speeding Example – Revisited

Since the P-value = 0.0023 < α = 0.05, we reject the null hypothesis in
favour of the alternative at the 5% level of significance.
6 Conclusion
There is sufficient statistical evidence to conclude that the true mean
speed of motorists at the intersection is greater than the posted limit
of 60 km/h.

Carrie Madden STAT 2000 – Unit 1 99 / 253


Unit 1 – Inference for the Mean of a Single Population

Statistical Significance

Results that lead to the reject of a null hypothesis are said to be


statistically significant.
For this reason, statistical hypothesis tests are also referred to as tests
of significance.
Statistical significance is an effect so large that it would rarely occur
by chance alone.

Carrie Madden STAT 2000 – Unit 1 100 / 253


Unit 1 – Inference for the Mean of a Single Population

Practice Question

The response times of technicians of a large heating company follow a


normal distribution with a standard deviation of 10 minutes. A supervisor
suspects that the mean response time has increased from the target time
of 30 minutes. He takes a random sample of 25 response times and
calculates the sample mean response time to be 33.8 minutes
What are the null and alternative hypotheses for the appropriate
hypothesis test?
A H0 : µ = 30vs.Ha : µ ̸= 30
B H0 : X̄ = 30vs.Ha : X̄ > 30
C H0 : µ = 33.8vs.Ha : µ > 33.8
D H0 : X̄ = 33.8vs.Ha : X̄ > 33.8
E H0 : µ = 30vs.Ha : µ > 30

Carrie Madden STAT 2000 – Unit 1 101 / 253


Unit 1 – Inference for the Mean of a Single Population

Practice Question

The response times of technicians of a large heating company follow a


normal distribution with a standard deviation of 10 minutes. A supervisor
suspects that the mean response time has increased from the target time
of 30 minutes. He takes a random sample of 25 response times and
calculates the sample mean response time to be 33.8 minutes.
What is the value of the test statistic for the appropriate hypothesis test?
A z = 1.65
B z = 2.09
C z = 0.77
D z = 1.90
E z = 1.83

Carrie Madden STAT 2000 – Unit 1 102 / 253


Unit 1 – Inference for the Mean of a Single Population

Hypothesis Testing

Note that in the above case, we were interested in testing the claim that
the mean speed of vehicles at the intersection was greater than 60.
Let us consider the cases where we are interested if the population mean
for some variable is less than some specified value.

Carrie Madden STAT 2000 – Unit 1 103 / 253


Unit 1 – Inference for the Mean of a Single Population

Example – Paint Drying

Example
The true mean drying time for a certain type of paint under specified test
conditions is known to be 75 minutes. Chemists have proposed a new
additive designed to decrease the mean drying time. Suppose it is known
that drying times follow a normal distribution with a standard deviation of
9 minutes. They test the new paint on a random sample of 36 specimens,
and find an average drying time of 73 minutes. Is this strong evidence to
suggest that the true mean drying time with the additive is less than 75
minutes?

Carrie Madden STAT 2000 – Unit 1 104 / 253


Unit 1 – Inference for the Mean of a Single Population

Example – Paint Drying (Cont’d)


1 Level of significance
Let α = 0.01.
2 Hypotheses

H0 : µ = 75
Ha : µ < 75
3 Decision rule
Reject H0 if the P − value ≤ α = 0.01.
4 Test statistic

x̄ − µo 73 − 75
z= =
√σ √9
n 36
= −1.33
Carrie Madden STAT 2000 – Unit 1 105 / 253
Unit 1 – Inference for the Mean of a Single Population

Example – Paint Drying (Cont’d)

5 Calculate the P-value


The P-value of the test is
 
P-value = P X̄ ≤ 73|µ = 75
= P (Z ≤ −1.33) = 0.0918

(Notice that the P-value is now an expression of the form P (Z ≤ z)


rather than the form P (Z ≥ z) that we used in the previous example.
This is because the P-value is the probability of observing a value of
the test statistic at least as extreme as the one observed, given the
null hypothesis is true. In this case, since our alternative hypothesis
was left-sided, an “extreme” value of the test statistic indicates a low
value.)

Carrie Madden STAT 2000 – Unit 1 106 / 253


Unit 1 – Inference for the Mean of a Single Population

Example – Paint Drying (Cont’d)

Since the P-value = 0.0918 > α = 0.01, we fail to reject the null
hypothesis.
6 Conclusion
We have insufficient statistical evidence that the true mean drying
time is lower with the additive.

Notice that we do not conclude that H0 is true. A sample mean of 73 is


certainly not proof that the population mean is equal to 75. All we can say
is that we do not have enough evidence to reject the null hypothesis.
Note
We never say “accept H0 ”

Carrie Madden STAT 2000 – Unit 1 107 / 253


Unit 1 – Inference for the Mean of a Single Population

Example – Paint Drying (Con’d) – R Code

pnorm(-1.33)

## [1] 0.09175914

Carrie Madden STAT 2000 – Unit 1 108 / 253


Unit 1 – Inference for the Mean of a Single Population

Hypothesis Testing

A simple rule for left or right sided tests


The direction of arrow in the p-value is the same as the direction of the
arrow in the alternative hypothesis.

Carrie Madden STAT 2000 – Unit 1 109 / 253


Unit 1 – Inference for the Mean of a Single Population

Practice Question

The average body temperature of healthy adults is commonly thought to


be 37.0◦ C , but a physician believes the mean is actually lower. She
measures the body temperatures of a random sample of 16 healthy adult
patients and calculates a sample mean body temperature of 36.9◦ C .
Suppose it is known that body temperatures follow a normal distribution
with standard deviation 0.2◦ C . The doctor conducts a hypothesis test to
test her suspicion. What is the P-value for the appropriate hypothesis test?
A 0.3085
B 0.0228
C 0.0075
D 0.1587
E 0.0630

Carrie Madden STAT 2000 – Unit 1 110 / 253


Unit 1 – Inference for the Mean of a Single Population

Practice Question
It is known that the tar contents of cigarettes of a particular brand follow
a normal distribution with standard deviation 0.3 mg. The mean tar
content is supposed to be 14.1 mg per cigarette. However, changes in the
composition of the tobacco and changes in the processing methods
sometimes cause the mean tar content to shift. We take a random sample
of five cigarettes every hour and calculate x̄ = 14.4. We would like to
conduct a hypothesis test of H0 : µ = 14.1 vs. Ha : µ > 14.1. We find a
P-value of 0.0127. At a 5% level of significance, we should:
A fail to reject Ho because the P-value is 0.0253, which is less than 0.05.
B reject Ho because the P-value is 0.0127, which is less than 0.05.
C fail to reject Ho because the P-value is 0.0127, which is less than 0.05.
D reject Ho because the P-value is 0.0253, which is less than 0.05.
E fail to reject Ho because the P-value is 0.9873, which is greater than
0.05.
Carrie Madden STAT 2000 – Unit 1 111 / 253
Unit 1 – Inference for the Mean of a Single Population

Two Sided Tests

The other possible scenario is that we may simply be interested in the


possibility that the population mean is not equal to the value hypothesized
in the null hypothesis. In this case, the P-value is the probability of
observing a value of the test statistic at least as extreme (in either
direction) given the null hypothesis is true. In this case, we find the
P-value by doubling the probability to the left or right of z (whichever is
lower).
This is because we were originally interested in the value of the sample
mean being far from µ0 in either direction.
Because we are assuming that the null hypothesis is true, getting a value
equally as far from the hypothesized mean in the other direction would be
equally likely.

Carrie Madden STAT 2000 – Unit 1 112 / 253


Unit 1 – Inference for the Mean of a Single Population

P-Values

In summary, the P-value for testing H0 : µ = µ0 vs.:

Ha : µ > µ0 is
P(Z > z)
Ha : µ < µ0 is
P(Z < z)
Ha : µ ̸= µ0 is
2P (Z > |z|)

These P-values are exact if the population is normal and approximate for
large sample size n in other cases.

Carrie Madden STAT 2000 – Unit 1 113 / 253


Unit 1 – Inference for the Mean of a Single Population

Example – Root Beer

Example
The Mackenzie Valley Bottling Company distributes root beer in bottles
labeled 500 ml. They routinely inspect samples of 10 bottles prior to
making a large shipment, hoping to detect if the true mean volume in the
shipment differs from 500 ml. If the bottles are under-filled, the company
could be sued for false advertising. If the bottles are overfilled, the
company is spending more money than they need to. Suppose it is known
that fill volumes for the bottles of root beer follow a normal distribution
with standard deviation 3.5 ml. One random sample of 10 bottles results
in a sample average volume of 502 ml. Does this provide convincing
evidence that the true mean fill volume for the shipment differs from the
advertised amount of 500 ml?

Carrie Madden STAT 2000 – Unit 1 114 / 253


Unit 1 – Inference for the Mean of a Single Population

Example – Root Beer (Cont’d)


Solution
1 Level of significance

Let α = 0.05.
2 Hypotheses

H0 : µ = 500
Ha : µ ̸= 500

3 Decision rule
Reject H0 if P-value ≤ α = 0.05.
4 Test statistic
502 − 500
z= 3.5 = 1.81

10

Carrie Madden STAT 2000 – Unit 1 115 / 253


Unit 1 – Inference for the Mean of a Single Population

Example – Root Beer (Cont’d)

Solution
5 P-value

The P-value is

2P (Z ≥ 1.81) = 2 (1 − P (Z < 1.81))


= 2 (1 − 0.9649) = 2(0.0351) = 0.0702

Interpretation: If the true mean fill volume of all bottles was 500 ml,
the probability of observing a sample mean at least as extreme as 502
ml would be 0.0702.
Since the P-value = 0.0702 > α = 0.05, we fail to reject Ho .
6 Conclusion
We have insufficient evidence that the true mean volume of all bottles
in the shipment differs from 500 ml.

Carrie Madden STAT 2000 – Unit 1 116 / 253


Unit 1 – Inference for the Mean of a Single Population

Example – Root Beer (Cont’d) – R Code

2*pnorm(-1.81)

## [1] 0.07029579

##or

2*(1-pnorm(1.81))

## [1] 0.07029579

Carrie Madden STAT 2000 – Unit 1 117 / 253


Unit 1 – Inference for the Mean of a Single Population

Practice Question

We conduct a hypothesis test of H0 : µ = 15 vs. Ha : µ ̸= 15 at the 10%


level of significance. We take a random sample of 100 individuals and
calculate a test statistic of z = −1.19. What is the P-value of the test?
A 0.8830
B 0.1000
C 0.1170
D 0.2340
E 0.0585

Carrie Madden STAT 2000 – Unit 1 118 / 253


Unit 1 – Inference for the Mean of a Single Population

Practice Question

A jury in an armed robbery trial is essentially testing the hypotheses:

H0 : Defendant is innocent vs. Ha : Defendant is guilty

After all the evidence has been presented, the jury deliberates and
determines a P-value of 0.35. They therefore conclude that:
A there is sufficient evidence that the defendant is innocent.
B there is insufficient evidence that the defendant is innocent.
C there is sufficient evidence that the defendant is guilty.
D there is insufficient evidence that the defendant is guilty.
E the probability that the defendant is innocent is only 35%.

Carrie Madden STAT 2000 – Unit 1 119 / 253


Unit 1 – Inference for the Mean of a Single Population

Confidence Interval Method for Hypothesis Tests

For a two-sided test, we have one additional method to conduct the


hypothesis test – the confidence interval method. A two-sided test with
significance level α rejects the null hypothesis if µ0 falls outside the
100 (1 − α)% confidence interval. If µ0 falls inside the interval, we fail to
reject H0 .

Carrie Madden STAT 2000 – Unit 1 120 / 253


Unit 1 – Inference for the Mean of a Single Population

Root Beer Example Revisted

Consider again the root beer example. We will conduct the hypothesis test
again, this time using the confidence interval method. \begin{solution}
1 Level of significance
Let α = 0.05.
2 Hypotheses

H0 : µ = 500
Ha : µ ̸= 500

3 Decision rule
Reject H0 if µ0 = 500 is not in the 95% confidence interval for µ.

Carrie Madden STAT 2000 – Unit 1 121 / 253


Unit 1 – Inference for the Mean of a Single Population

Root Beer Example – Revisted

Solution
4 Confidence interval

The 95% confidence interval for µ is:


σ 3.5
 
x̄ ± z ∗ √ = 502 ± 1.960 √
n 10
= 502 ± 2.17 = (499.83, 504.17)

Since µ0 = 500 is contained in the 95% confidence interval, we fail to


reject H0 .
5 Conclusion
We have insufficient evidence that the true mean volume of all bottles
in the shipment differs from 500 ml.

Carrie Madden STAT 2000 – Unit 1 122 / 253


Unit 1 – Inference for the Mean of a Single Population

Root Beer Example – R Code

Here is the R code to make the confidence interval for the above example:

xbar<-502
n<-10
sigma<-3.5
#This is for a 95%CI, leaving 0.025 in either tail.
#Hence the are to the left of 1.96 is 0.95+0.025=0.975
zstar<- qnorm(0.975)
moe<-zstar*(sigma/sqrt(n))
left<- xbar-moe
right<- xbar+moe

Carrie Madden STAT 2000 – Unit 1 123 / 253


Unit 1 – Inference for the Mean of a Single Population

Root Beer Example – R Code

## [1] 499.8307

## [1] 504.1693

Which agree with the hand calculations.

Carrie Madden STAT 2000 – Unit 1 124 / 253


Unit 1 – Inference for the Mean of a Single Population

Practice Question
The manager at a grocery store would like to estimate the true mean
amount of money spent by customers in the express lane. She selects a
simple random sample of 50 receipts and calculates a 98% confidence
interval for µ to be ($15.50, $20.25). Suppose we wish to conduct a
hypothesis test to determine whether there is evidence that the true mean
amount spent by customers in the express lane differs from $20. Which of
the following statements is true?
A At a significance level of α = 0.01, we have sufficient evidence that
µ ̸= 20.
B At a significance level of α = 0.01, we conclude that µ = 20.
C At a significance level of α = 0.02, we have sufficient evidence that
µ ̸= 20.
D At a significance level of α = 0.02, we have insufficient evidence that
µ ̸= 20.
E At a significance level of α = 0.04, we have insufficient evidence that
µ ̸= 20.
Carrie Madden STAT 2000 – Unit 1 125 / 253
Unit 1 – Inference for the Mean of a Single Population

Hypothesis Testing – Critical Value Method

We now examine an alternate method for conducting a hypothesis test.


Consider again the speeding vehicle example. Suppose that, instead of
asking “What is the probability that the value of Z is at least as high as
the value we observed?”, we ask:

“How high does z have to be in order for us to reject the null hypothesis?”

Carrie Madden STAT 2000 – Unit 1 126 / 253


Unit 1 – Inference for the Mean of a Single Population

Hypothesis Testing – Critical Value Method


The level of significance for this test was given as α = 0.05, and so we
reject H0 if the P-value ≤ 0.05.
In other words, we will reject the null hypothesis for any z ≥ z ∗ , where

0.3
P (Z ≥ z ∗ ) = 0.05

0.2
0.1 0.05

0 z*

Carrie Madden STAT 2000 – Unit 1 127 / 253


Unit 1 – Inference for the Mean of a Single Population

Critical Value Method


From Table 3, we find this value to be z ∗ = 1.645. In other words, we will
reject the null hypothesis if z ≥ 1.645, and we will fail to reject if
z < 1.645.
The value z ∗ is called the critical value of the test, and so the new test
method is called the critical value method. The area beyond the value z ∗
under the normal curve is called the critical region or the rejection region.

qnorm(0.05)

## [1] -1.644854

qnorm(0.95)

## [1] 1.644854
Carrie Madden STAT 2000 – Unit 1 128 / 253
Unit 1 – Inference for the Mean of a Single Population

Speeding Example Revisted – Critical Value Method

We now revisit the speeding vehicle example and conduct the test using
the critical value approach.
Solution
1 Level of significance

Let α = 0.05.
2 Hypotheses

H0 : µ = 60
Ha : µ > 60

3 Decision Rule
Reject H0 if z ≥ z ∗ = 1.645.

Carrie Madden STAT 2000 – Unit 1 129 / 253


Unit 1 – Inference for the Mean of a Single Population

Speeding Example Revisted – Critical Value Method

Solution
4 Test statistic

66 − 60
z= = 2.83
√15
50

Since z = 2.83 > z ∗ = 1.645, we reject the null hypothesis in favour


of the alternative.
5 Conclusion
We have sufficient statistical evidence to conclude that the true mean
speed of motorists at the intersection is greater than the posted limit
of 60 km/h.

Carrie Madden STAT 2000 – Unit 1 130 / 253


Unit 1 – Inference for the Mean of a Single Population

Speeding Example Revisted – Critical Value Method

Note that there are only five steps in conducting a hypothesis test using
the critical value approach, since the calculation of a P-value is no longer
necessary. In the case of a left-sided test, we reject the null hypothesis if
z ≤ −z ∗ , where −z ∗ is the value of Z such that

P (Z ≤ −z ∗ ) = α

Carrie Madden STAT 2000 – Unit 1 131 / 253


Unit 1 – Inference for the Mean of a Single Population

Paint Drying Example Revisted – Critical Value


Method
Consider again the paint drying example using the critical value approach.
Solution
1 Level of significance

Let α = 0.01.
2 Hypotheses

H0 : µ = 75
Ha : µ < 75

3 Decision rule
Reject H0 if z ≤ z ∗ = −2.326.

.
Carrie Madden STAT 2000 – Unit 1 132 / 253
Unit 1 – Inference for the Mean of a Single Population

Paint Drying Example Revisted – Critical Value


Method – R Code

qnorm(0.01)

## [1] -2.326348

Carrie Madden STAT 2000 – Unit 1 133 / 253


Unit 1 – Inference for the Mean of a Single Population

Paint Drying Example Revisted – Critical Value


Method

Solution
4 Test statistic

73 − 75
z= = −1.33
√9
36

Since z = −1.33 > z ∗ = −2.323, we fail to reject the null hypothesis.


5 Conclusion
We have insufficient statistical evidence that the true mean drying
time is lower with the additive.

Carrie Madden STAT 2000 – Unit 1 134 / 253


Unit 1 – Inference for the Mean of a Single Population

Critical Value Method – Two Sided Tests

If we use the critical value approach for a two-sided test, we reject the null
hypothesis if |Z | > z ∗ , where z ∗ is the value of z such that
α
P (Z ≥ z ∗ ) =
2
In other words, we reject Ho if Z ≤ −z ∗ or Z ≥ z ∗ .

Carrie Madden STAT 2000 – Unit 1 135 / 253


Unit 1 – Inference for the Mean of a Single Population

Root Beer Example Revisited – Critical Value


Method
Consider again the root beer example, this time using the critical value
approach.
Solution
1 Level of significance

Let α = 0.05.
2 Hypotheses

H0 : µ = 500
Ha : µ ̸= 500

3 Decision rule
Reject H0 if |z| ≥ z ∗ = 1.96. In other words, if z ≤ −1.96 or
z ≥ 1.96.
Carrie Madden STAT 2000 – Unit 1 136 / 253
Unit 1 – Inference for the Mean of a Single Population

Root Beer Example Revisited – Critical Value


Method – R Code

qnorm(.05/2)

## [1] -1.959964

Carrie Madden STAT 2000 – Unit 1 137 / 253


Unit 1 – Inference for the Mean of a Single Population

Root Beer Example Revisited – Critical Value


Method

Solution
–>
4 Test statistic
502 − 500
z= 3.5 = 1.81

10

Since −1.96 < z = 1.81 < 1.96, we fail to reject Ho .


5 Conclusion
We have insufficient evidence that the true mean volume of all bottles
in the shipment differs from 500 ml.

Carrie Madden STAT 2000 – Unit 1 138 / 253


Unit 1 – Inference for the Mean of a Single Population

Practice Question

A random variable X follows a normal distribution with known standard


deviation σ. We will use the critical value approach to conduct a
hypothesis test of H0 : µ = 20 vs. Ha : µ ̸= 20 at the 2% level of
significance. The decision rule is to reject H0 if:
A |z| > 2.054
B z > 2.054
C |z| > 2.326
D z > 2.326
E |z| > 2.576

Carrie Madden STAT 2000 – Unit 1 139 / 253


Unit 1 – Inference for the Mean of a Single Population

Decisions in Inference

In conducting a hypothesis test, we can never be sure that our conclusion


is correct. Since we examine only a part of the population, we will never
be able to state our conclusion with 100% certainty. The best we can do is
state our conclusions with a high probability of being correct.
As shown in the following diagram, there are four situations we may
encounter upon making conclusion for a statistical hypothesis test:

Carrie Madden STAT 2000 – Unit 1 140 / 253


Unit 1 – Inference for the Mean of a Single Population

Decisions in Inference

Truth about pop-


ulation mean µo

Ho true Ha true
Decision based on sample

Correct
Reject Ho Type I Error
Decision

1 2
3 4

Fail to re- Correct


Type II Error
ject Ho Decision

Carrie Madden STAT 2000 – Unit 1 141 / 253


Unit 1 – Inference for the Mean of a Single Population

Decisions in Inference

Obviously, we want to reject H0 when it is false and we want to fail to


reject H0 when it is true.

Carrie Madden STAT 2000 – Unit 1 142 / 253


Unit 1 – Inference for the Mean of a Single Population

Decisions in Inference

On the other hand, if we find ourselves in Case 1 or Case 3, we have made


an error in our conclusion. As shown in the diagram, there are two types
of error we could make:

We say we have made a Type I Error if we reject H0 when it is true


(Case 1).
We say we have made a Type II Error if we fail to reject H0 when Ha
is true (Case 3).

Carrie Madden STAT 2000 – Unit 1 143 / 253


Unit 1 – Inference for the Mean of a Single Population

Type I Error
Note however that this is just
our regular level of significance
we have been using all along.
We say we have made a Type I
error if we reject H0 when it is
true.
We will denote the probability

0.3
of making a Type I Error as α:

0.2
P (reject Ho |Ho true) = P (Type I Error)

0.1

µo

Carrie Madden STAT 2000 – Unit 1 144 / 253


Unit 1 – Inference for the Mean of a Single Population

Type I Error

We control the probability of Type I Error directly through our specification


of the significance level α. For example, when α = 0.05, we have only a
5% chance of incorrectly rejecting the null hypothesis when it is true.

Carrie Madden STAT 2000 – Unit 1 145 / 253


Unit 1 – Inference for the Mean of a Single Population

Type II Error

We say we have made a Type II error if we fail to reject H0 when Ha is


true. We will denote the probability of making a Type II Error as β:

P (fail to reject H0 |Ha true) = P (Type II Error)


The probability of Type II Error has not been considered previously when
we have set up our tests of significance. We would, however, like for β to
be low when conducting a hypothesis test.

Carrie Madden STAT 2000 – Unit 1 146 / 253


Unit 1 – Inference for the Mean of a Single Population

Type II Error

Rather than examining the probability of Type II error directly, we will


examine the compliment:

P (reject H0 |Ha true) = 1 − β

Note that this corresponds to Case 2 in our diagram. We give this


probability a special name.

Carrie Madden STAT 2000 – Unit 1 147 / 253


Unit 1 – Inference for the Mean of a Single Population

Power

Power
The power of a hypothesis test is the probability of correctly rejecting H0
when Ha is true.

As we can see from the expression above, if we can calculate the power,
then we can easily find β:

Power = P (reject H0 |Ha true) = 1 − β

Therefore,
β = 1 − Power

Carrie Madden STAT 2000 – Unit 1 148 / 253


Unit 1 – Inference for the Mean of a Single Population

Example – Pharmaceutical Company

Example
A pharmaceutical company is producing prescription pills for the alleviation
of migraine headaches. The pills are supposed to contain 25 mg of the
active ingredient. It is very important that the amount of this ingredient
does not exceed 25 mg, as it is very powerful and could be dangerous if
taken in excessive amounts. Thousand of pills are produced for sale each
day, and samples of 5 pills are taken frequently to measure the amount of
the ingredient. A hypothesis test is conducted at α = 0.01 to test whether
the amount of exceeds 25 mg. Suppose it is known that the amount of the
active ingredient per pill follows a normal distribution with standard
deviation 1.2 mg. The analysts would like to detect a true mean of 27 mg
with high probability, as high amount of the ingredient are dangerous.

Carrie Madden STAT 2000 – Unit 1 149 / 253


Unit 1 – Inference for the Mean of a Single Population

Example – Pharmaceutical Company (Cont’d)

Example
What is the power of the test of

H0 : µ = 25
Ha : µ = 27

when α = 0.01?

Carrie Madden STAT 2000 – Unit 1 150 / 253


Unit 1 – Inference for the Mean of a Single Population

Example – Pharmaceutical Company (Cont’d)

1 Find the reject rule in terms of X̄ :


We reject H0 if

Z ≥ z∗
X̄ − µo
≥ z∗
√σ
n
σ
 
X̄ ≥ µo + z ∗ √
n
1.2
 
X̄ ≥ 25 + 2.326 √
5
X̄ ≥ 26.248

Carrie Madden STAT 2000 – Unit 1 151 / 253


Unit 1 – Inference for the Mean of a Single Population

Example – Pharmaceutical Company – R Code

Finding the rejection rule in terms of x̄

n <- 5
sigma <- 1.2
sm<-(sigma/sqrt(5))
alpha <- 0.01
mu0<-25
q = qnorm((1-alpha), mean=mu0, sd=sm) #1-alpha; area to the ri

## [1] 26.24845

Carrie Madden STAT 2000 – Unit 1 152 / 253


Unit 1 – Inference for the Mean of a Single Population

Example – Pharmaceutical Company (Cont’d)

2 Now assume that Ha is correct. Find the probability of rejection


under this assumption.

Power = P (reject H0 |Ha true) = P (reject H0 |µ = 27)


 
  26.248 − 27 
= P X̄ ≥ 26.248|µ = 27 = P Z ≥ 1.2

5
= P (Z ≥ −1.40) = 1 − P(Z < −1.40) = 0.9192

Therefore, the probability of Type II error is

β = 1 − Power = 1 − 0.9192 = 0.0808

Carrie Madden STAT 2000 – Unit 1 153 / 253


Unit 1 – Inference for the Mean of a Single Population

Example – Pharmaceutical Company – R Code

mua<-27
power<-pnorm(q, mean = mua, sd=sm, lower.tail = FALSE)

power

## [1] 0.919308

Carrie Madden STAT 2000 – Unit 1 154 / 253


Unit 1 – Inference for the Mean of a Single Population

Example (Cont’d)

Question:

“Why do we need to specify a specific value of the alternative hypothesis


when calculating power?”

Suppose the analysts were interested in detecting a true mean of 28 mg


with high probability. We will calculate the power of the test

H0 : µ = 25
Ha : µ = 28

when α = 0.01.

Carrie Madden STAT 2000 – Unit 1 155 / 253


Unit 1 – Inference for the Mean of a Single Population

Example (Cont’d)

1 Step 1 is the same as before, as the rejection rule depends only on the
value µ0 stated in the null hypothesis
2

Power = P (reject H0 |Ha true) = P (reject H0 |µ = 28)


 
  26.248 − 28 
= P X̄ ≥ 26.248|µ = 28 = P Z ≥ 1.2

5
= P (Z ≥ −3.26) = 1 − P(Z < −3.26) = 0.9994

Therefore, the probability of Type II error is

β = 1 − Power = 1 − 0.9994 = 0.0006

Carrie Madden STAT 2000 – Unit 1 156 / 253


Unit 1 – Inference for the Mean of a Single Population

Example – Pharmaceutical Company – R Code

mua<-28
power<-pnorm(q, mean = mua, sd=sm, lower.tail = FALSE)

power

## [1] 0.9994504

Carrie Madden STAT 2000 – Unit 1 157 / 253


Unit 1 – Inference for the Mean of a Single Population

Power

As we should have expected, the probability of detecting that H0 is false is


greater when the alternative mean µa is further away from µ0 .
Consider, for example, if the true mean amount of ingredient was 35 mg.
It would obviously be more likely to detect that the mean was above 25
mg that if the true mean was 28 mg.
Thus, the power of a test of significance depends on the specific value of
the mean under the alternative hypothesis. The further µa is from µ0 , the
higher the power.

Carrie Madden STAT 2000 – Unit 1 158 / 253


Unit 1 – Inference for the Mean of a Single Population

Practice Question

Suppose we are testing the null hypothesis that the value of some
population mean is 32 versus the alternative that the population mean is
greater than 32. We use a significance level of 0.05 and the standard
deviation of the population is known to be 8. Based on a sample size of
16, the critical (rejection) region of the test is:
A x̄ > 28.71
B x̄ > 33.97
C x̄ > 1.645
D x̄ > 35.29
E x̄ > 36.44

Carrie Madden STAT 2000 – Unit 1 159 / 253


Unit 1 – Inference for the Mean of a Single Population

Example – Mining Operations

In some mining operations, a byproduct of the processing is mildly


radioactive. Of prime concern is the possibility that release of these
byproducts into the environment may contaminate the freshwater supply.
There are strict regulations for the maximum allowable radioactivity in
supplies of drinking water. In order for the water to be considered safe, the
population mean radioactivity must be less than 5 pico curies per litre
(pc/l0. Radiation levels are known to follow a normal distribution with
standard deviation 0.4 pc/l. We take a random sample of 12 specimens of
water from a city’s water supply and we wish to conduct a test to
determine whether there is sufficient evidence that the water is safe. We
conduct a hypothesis test, at the 5% level of significance, to determine
whether the water is safe. We will find the power of the test if the true
mean radioactivity is 4.5 pc/l.

Carrie Madden STAT 2000 – Unit 1 160 / 253


Unit 1 – Inference for the Mean of a Single Population

Example – Mining Operations (Cont’d)

Solution
1 We reject H if
0

Z ≤ z∗
X̄ − µ0
≤ −z ∗
√σ
n
σ
 

X̄ ≤ µ0 − z √
n
0.4
 
X̄ ≤ 5 − 1.645 √ = 4.81
12

Carrie Madden STAT 2000 – Unit 1 161 / 253


Unit 1 – Inference for the Mean of a Single Population

Example – Mining Operations (Cont’d)

Solution
2 Find the power of the test.

Power = P (reject H0 |Ha true) = P (reject H0 |µ = 4.5)


 
  4.81 − 4.5 
= P X̄ ≤ 4.81|µ = 4.5 = P Z ≤ 0.4

12
= P (Z ≤ 2.68) = 0.9963

Therefore, the probability of Type II error is

β = 1 − Power = 1 − 0.9963 = 0.0037

Carrie Madden STAT 2000 – Unit 1 162 / 253


Unit 1 – Inference for the Mean of a Single Population

Example – Mining Operations R code

n <- 12
sigma <- 0.4
sm<-(sigma/sqrt(n))
alpha <- 0.05
mu0<-5
q = qnorm((alpha), mean=mu0, sd=sm)

## [1] 4.810069

Carrie Madden STAT 2000 – Unit 1 163 / 253


Unit 1 – Inference for the Mean of a Single Population

Example – Mining Operatinos R code

mua<-4.5
power<-pnorm(q, mean = mua, sd=sm, lower.tail = TRUE)

power

## [1] 0.9963765

Carrie Madden STAT 2000 – Unit 1 164 / 253


Unit 1 – Inference for the Mean of a Single Population

Relationships

Question:

“What is the relationship between α and β?”

Assume that, instead of conduction the above test with α = 0.05, we were
to conduct it using α = 0.01.

Carrie Madden STAT 2000 – Unit 1 165 / 253


Unit 1 – Inference for the Mean of a Single Population

Example – Mining Operations Cont’d

1 We reject HO if

Z ≤ z∗
X̄ − µ0
≤ −z ∗
√σ
n
σ
 

X̄ ≤ µ0 − z √
n
0.4
 
X̄ ≤ 5 − 2.326 √ = 4.73
12

Carrie Madden STAT 2000 – Unit 1 166 / 253


Unit 1 – Inference for the Mean of a Single Population

Example – Mining Operations R code

n <- 12
sigma <- 0.4
sm<-(sigma/sqrt(n))
alpha <- 0.01 #Changed alpha
mu0<-5
q = qnorm((alpha), mean=mu0, sd=sm)

## [1] 4.731376

Carrie Madden STAT 2000 – Unit 1 167 / 253


Unit 1 – Inference for the Mean of a Single Population

Example – Mining Operations Cont’d

2 Find the power of the test.

Power = P (reject Ho |Ha true) = P (reject Ho |µ = 4.5)


 
  4.73 − 4.5 
= P X̄ ≤ 4.73|µ = 4.5 = P Z ≤ 0.4

12
= P (Z ≤ 1.99) = 0.9767

Therefore, the probability of Type II error is

β = 1 − Power = 1 − 0.9767 = 0.0233

Carrie Madden STAT 2000 – Unit 1 168 / 253


Unit 1 – Inference for the Mean of a Single Population

Example – Mining Operations Cont’d

mua<-4.5
power<-pnorm(q, mean = mua, sd=sm, lower.tail = TRUE)

power

## [1] 0.9774531

You will see small discrepencies due to rounding error with hand
calculations.

Carrie Madden STAT 2000 – Unit 1 169 / 253


Unit 1 – Inference for the Mean of a Single Population

Relationships (Cont’d)

Ideally, we would like to reject H0 with high probability when it is false.


We would also like to fail to reject H0 with high probability when it is true.
That is, we would like both α and β to be low. However, as shown in the
above problem, decreasing α results in an increase in β (and vice-versa).
Therefore, for a given sample size, we must choose the level of significance
α wisely, in a manner that yields a reasonably low value of β as well.

Carrie Madden STAT 2000 – Unit 1 170 / 253


Unit 1 – Inference for the Mean of a Single Population

Practice Question
A box of cookies is supposed to weigh 250 grams. There is some variation
in weight from box to box. The weights of cookies are normally distributed
with an unknown mean and a known standard deviation of 3 grams. A
consumer agency takes a random sample of 8 boxes of cookies, and wishes
to conduct a 5% significance test to test the hypothesis:

H0 : µ = 250
Ha : µ < 250

What is the power of the test if the true mean is actually 245?
A 0.8493
B 0.8749
C 0.9374
D 0.9500
E 0.9989
Carrie Madden STAT 2000 – Unit 1 171 / 253
Unit 1 – Inference for the Mean of a Single Population

Practice Question
Suppose we test

H0 : µ = 10
Ha : µ ̸= 10

at the 5% significance level, based on a random sample of size n from a


normally distributed population with known standard deviation σ. If we
increase the level of significance to 10%, then the power of the test if the
true mean is actually 20 will:
A increase.
B decrease.
C double.
D decrease by half.
E not change.
Carrie Madden STAT 2000 – Unit 1 172 / 253
Unit 1 – Inference for the Mean of a Single Population

Example – Power – Two Sided Test

Example
A hypothesis test of

H0 : µ = 1.5
Ha : µ ̸= 1.5

is conducted for a particular sample of size 10 with population standard


deviation σ = 0.04 at α = 0.05. We will find the power of the test of

H0 : µ = 1.5
Ha : µ = 1.51

Carrie Madden STAT 2000 – Unit 1 173 / 253


Unit 1 – Inference for the Mean of a Single Population

Example – Power (Cont’d)

Solution
1 We reject H if
0

Z ≤ −z ∗ or Z ≥ z∗
X̄ − µo X̄ − µo
≤ −z ∗ or ≥ z∗
√σ √σ
n n
σ σ
   
∗ ∗
X̄ ≤ µ0 − z √ or X̄ ≥ µ0 + z √
n n
0.04 0.04
   
X̄ ≤ 1.5 − 1.96 √ or X̄ ≥ 1.5 + 1.96 √
10 10
X̄ ≤ 1.4752 or X̄ ≥ 1.5248

Carrie Madden STAT 2000 – Unit 1 174 / 253


Unit 1 – Inference for the Mean of a Single Population

Example – Power – Two Sided – R Code


Rejection Regions in terms of x̄

n <- 10
sigma <- 0.04
sm<-(sigma/sqrt(n))
alpha <- 0.05
mu0<-1.5
ql = qnorm((alpha/2), mean=mu0, sd=sm) #alpha/2; area in the l
qr = qnorm((1-(alpha/2)), mean=mu0, sd=sm) #alpha/2; area in t
ql

## [1] 1.475208
qr

## [1] 1.524792
Carrie Madden STAT 2000 – Unit 1 175 / 253
Unit 1 – Inference for the Mean of a Single Population

Example – Power (Cont’d)

Solution
2 The power is

Power = P (reject H0 |Ha true) = P (reject H0 |µ = 1.51)


 
= P X̄ ≤ 1.4752 or X̄ ≥ 1.5248|µ = 1.51
   
1.4752 − 1.51  1.5248 − 1.51 
= P Z ≤ 0.04 + P Z ≥ 0.04
√ √
10 10
= P (Z ≤ −2.75) + P (Z ≥ 1.17) = 0.1240

Therefore, the probability of Type II error is

β = 1 − Power = 1 − 0.1240 = 0.8760

Carrie Madden STAT 2000 – Unit 1 176 / 253


Unit 1 – Inference for the Mean of a Single Population

Example – Power – Two Sided – R Code


mua<-1.51
powerl<-pnorm(ql, mean = mua, sd=sm, lower.tail = TRUE)
powerr<-pnorm(qr, mean = mua, sd=sm, lower.tail = FALSE)
powerl

## [1] 0.002974916
powerr

## [1] 0.1211223

power = powerl+powerr
power

## [1] 0.1240973
Carrie Madden STAT 2000 – Unit 1 177 / 253
Unit 1 – Inference for the Mean of a Single Population

Relationship between Power and Sample Size

We see that, when α = 0.05, the probability of Type II Error is


β = 0.8760. That is, if the true mean is 1.51, there is more than an 87%
chance that we will incorrectly fail to reject H0 .
This is clearly unacceptable.
Question:

“Why is the power so low and what can we do to raise it?”

The power is so low because out test is based on a small sample size.
Let’s see what happens when we conduct the same test with a higher
sample size, say n = 100.

Carrie Madden STAT 2000 – Unit 1 178 / 253


Unit 1 – Inference for the Mean of a Single Population

Example – Power – Two Sided Revisted

1 We reject H0 if

Z ≤ −z ∗ or Z ≥ z∗
X̄ − µ0 X̄ − µ0
≤ −z ∗ or ≥ z∗
√σ √σ
n n
σ σ
   
X̄ ≤ µ0 − z ∗ √ or X̄ ≥ µ0 + z ∗ √
n n
0.04 0.04
   
X̄ ≤ 1.5 − 1.96 √ or X̄ ≥ 1.5 + 1.96 √
100 100
X̄ ≤ 1.49216 or X̄ ≥ 1.50784

Carrie Madden STAT 2000 – Unit 1 179 / 253


Unit 1 – Inference for the Mean of a Single Population

Example – Power – Two Sided Revisted

2 The power is

Power = P (reject H0 |Ha true) = P (reject H0 |µ = 1.51)


 
= P X̄ ≤ 1.49216 or X̄ ≥ 1.50784|µ = 1.51
   
1.49216 − 1.51  1.50784 − 1.51 
= P Z ≤ 0.04 + P Z ≥ 0.04
√ √
100 100
= P (Z ≤ −4.46) + P (Z ≥ −0.54) = 0.7054

Therefore, the probability of Type II error is

β = 1 − Power = 1 − 0.7054 = 0.2946

Carrie Madden STAT 2000 – Unit 1 180 / 253


Unit 1 – Inference for the Mean of a Single Population

Example – Power – Two Sided – R Code

Go back through the previous R code for this example. Change n and see
if you can get the correct answers.

Carrie Madden STAT 2000 – Unit 1 181 / 253


Unit 1 – Inference for the Mean of a Single Population

Summary of Power Relationships

Summary:
The further away the value of the alternative mean is from µ0 , the
higher the power.
For a fixed sample size n, reducing the probability of a Type I Error α
will result in an increase of the probability of a Type II Error β (and
thus a decrease in power), and vice-versa.
For a fixed level of significance α, an increase in the sample size n will
result in a decrease in β (and thus an increase in power).

Carrie Madden STAT 2000 – Unit 1 182 / 253


Unit 1 – Inference for the Mean of a Single Population

Practice Question
In which of the following situations is a Type II Error more serious than a
Type I Error? Suppose you have to decide whether or not to:
(I) slow down to the speed limit

H0 : The car behind you is not a police car.


Ha : The car behind you is a police car.
(II) study a topic for the exam

H0 : The topic will be on the exam.


Ha : The topic will not be on the exam.

A I only
B II only
C both I and II
D neither
Carrie Madden STAT 2000 – Unit 1 183 / 253
Unit 1 – Inference for the Mean of a Single Population

Power

Note that, prior to conducting a hypothesis test, we should specify the


level of significance α, the value of the mean µa we would like to detect
with high probability, and the power, the probability with which we would
like to detect it.
When these three values have been specified, tables can be used to
determine the appropriate sample size that should be selected to attain
these values.

Carrie Madden STAT 2000 – Unit 1 184 / 253


Unit 1 – Inference for the Mean of a Single Population

Quality Control – Statistical control charts

In order to see an application of hypothesis testing in industry we can


consider a topic in statistics known as quality control. This is an
application of statistics used in industry. We use these statistics in order to
maintain the integrity of products we are producing. In order to use
control charts, we need to take samples from our process and measure our
variable to note whether the process is running “in control.”

Carrie Madden STAT 2000 – Unit 1 185 / 253


Unit 1 – Inference for the Mean of a Single Population

Quality Control – Causes of Variation

There is always going to be variability associated with any process because


most processes are quite complex. If our process is operating with only
chance causes of variation present is said to be in in statistical control
or simply (in control.)
Chance or Common causes are all those unavoidable causes that result in
natural inherent variability. Also known as “noise.”
A process that is operating in the presence of Assignable Causes is said
to be out-of-control.

Carrie Madden STAT 2000 – Unit 1 186 / 253


Unit 1 – Inference for the Mean of a Single Population

Quality Control – Causes of Variation

This variability arises from many sources:

Improperly controlled or adjusted machines.


Operator errors
Defective raw materials

Variability that results is usually large compared to background noise.


Special causes result in process changes that may cause process output to
be nonconforming.

Carrie Madden STAT 2000 – Unit 1 187 / 253


Unit 1 – Inference for the Mean of a Single Population

Quality Control – Typical Control Chart


Here is a control chart:

Carrie Madden STAT 2000 – Unit 1 188 / 253


Unit 1 – Inference for the Mean of a Single Population

Quality Control – Typical Control Chart

Is a graph of data in "run order" or in time sequence. Data may be


individual measurements or summary statistics.
Has a centre line around which the data vary. This can be considered
the true mean of the characterstic we are interested in.
Has lines called Control Limits within which the data are expected
to fall when the process is in control. These control limits are set at
three standard deviations away from the mean.
A plotted point outside the control limits is taken as a signal that a
special cause of variation may have affected the process. Action must
be taken to see what may have occurred.

Carrie Madden STAT 2000 – Unit 1 189 / 253


Unit 1 – Inference for the Mean of a Single Population

Quality Control – Basic Principles

A typical control chart has:

a centre line.
two other horizontal lines called the control limits, they are set at
values such that if the process is in control, nearly all points will lie
between them.
the top lines is known as the upper control limit(UCL) and the
other is the lower control limit(LCL).

Carrie Madden STAT 2000 – Unit 1 190 / 253


Unit 1 – Inference for the Mean of a Single Population

Quality Cntrol – Out of Control Situations

If at least one point plots beyond the control limits, the process is
said to be “out-of-control.”
If the points behave in a systematic or nonrandom manner, then the
process could be out-of-control. (i.e. a run of 9).

Carrie Madden STAT 2000 – Unit 1 191 / 253


Unit 1 – Inference for the Mean of a Single Population

Relationships between hypothesis testing and


control charts (application)
We have a process for which we assume the true process mean is µ = 1.5
and the process standard deviation is σ = 0.15. Samples of size 5 are
taken giving a standard deviation of the sample average, x̄ , as
σ 0.15
σx̄ = √ = √ = 0.0671
n 5
Control limits can be set at 3 standard deviations from the mean. This
results in “3-sigma control limits” or “3σ control limits”

UCL = 1.5 + 3(0.0671) = 1.7013


CL = 1.5
LCL = 1.5 − 3(0.0671) = 1.2987

Choosing the control limits is equivalent to setting up the critical region


for testing hypothesis:
Carrie Madden STAT 2000 – Unit 1 192 / 253
Unit 1 – Inference for the Mean of a Single Population

Example – Control Chart

A company manufactures a 1cm carbon steel bolt. The bolts are assigned
a hardness rating which follows a normal distribution with a mean of 85
and standard deviation of 2.8. Five bolts were selected every hour for 15
hours and the average hardness for each sample was calculated. The
averages are shown below:

Hour x̄ Hour x̄ Hour x̄


1 87.4 6 84.5 11 85.1
2 84.6 7 82.8 12 84.9
3 86.0 8 83.8 13 83.1
4 86.7 9 82.3 14 81.0
5 85.1 10 84.3 15 83.3

Carrie Madden STAT 2000 – Unit 1 193 / 253


Unit 1 – Inference for the Mean of a Single Population

Example – Control Chart (Cont’d)


First we will plot the x̄ ’s in time (or run) order.
90
88
86
hardnessseries

84
82
80

2 4 6 8 10 12 14

Time

Carrie Madden STAT 2000 – Unit 1 194 / 253


Unit 1 – Inference for the Mean of a Single Population

Example – Control Chart (Cont’d)

Now we will calculate the control limits:


The CL (centre line) will be at µ = 85
σ
The UCL (upper control limit) = µ + 3 √
n
σ
The LCL (lower control limit) = µ − 3 √
n
2.8
The UCL = 85 + 3 √ = 88.757
5
2.8
The LCL = 85 − 3 √ = 81.243
5

Carrie Madden STAT 2000 – Unit 1 195 / 253


Unit 1 – Inference for the Mean of a Single Population

Example – Control Chart (Cont’d)


We will now plot the CL, UCL and LCL on the contol chart:
90
88
86
hardnessseries

84
82
80

2 4 6 8 10 12 14

Time
##
Carrie Madden STAT 2000 – Unit 1 196 / 253
Unit 1 – Inference for the Mean of a Single Population

Example – Control Chart (Cont’d)- R Code

We are using “ts” which stands for time series because this is data
gathered over time (in a run order).

hardness<-c(87.4, 84.6, 86.0, 86.7, 85.1, 84.5, 82.8, 83.8,


82.3, 84.3, 85.1, 84.9, 83.1, 81.0, 83.3)

hardnessseries<- ts(hardness)

hardnessseries

plot.ts(hardnessseries, ylim=c(80,90))

Carrie Madden STAT 2000 – Unit 1 197 / 253


Unit 1 – Inference for the Mean of a Single Population

Example – Control Chart (Cont’d)- R Code

We will now plot the control limits:

plot.ts(hardnessseries, ylim=c(80,90))
abline(h=85)
abline(h=88.757, lty=2)
abline(h=81.243, lty=2)

Carrie Madden STAT 2000 – Unit 1 198 / 253


Unit 1 – Inference for the Mean of a Single Population

Quality Control Example – Gearbox Assemblies

A process produces nuts for use in automobile gearbox assemblies. The


process follows a normal distribution with a mean nut diameter of 19.5mm
and a standard deviation of 1.3mm. Process inspectors randomly select
samples of four nuts every hour and calculate the average diameter of
those four nuts. Below are the diameters for a 10-hour shift.

Hour x̄ Hour x̄
1 19.2 6 18.4
2 18.6 7 20.6
3 19.6 8 19.5
4 19.9 9 21.4
5 20.7 10 19.8

Is this process in control? Construct a control chart and plot the control
limits.
Carrie Madden STAT 2000 – Unit 1 199 / 253
Unit 1 – Inference for the Mean of a Single Population

Quality Control Example – Gearbox Assemblies

First let’s fine the LCL, CL and UCL;


The CL (centre line) will be at µ = 19.5
σ
The UCL (upper control limit) = µ + 3 √
n
σ
The LCL (lower control limit) = µ − 3 √
n
1.3
The UCL = 19.5 + 3 √ = 21.45
4
1.3
The LCL = 19.5 − 3 √ = 17.55
4

Carrie Madden STAT 2000 – Unit 1 200 / 253


Unit 1 – Inference for the Mean of a Single Population

Quality Control Example – Gearbox Assemblies


diameter<-c(19.2, 18.6, 19.6, 19.9, 20.7, 19.4, 20.6,
19.5, 21.4, 19.8)
plot.ts(diameter, ylim=c(18,22))
22
21
diameter

20
19
18

Carrie Madden STAT 2000 – Unit 1 201 / 253


Unit 1 – Inference for the Mean of a Single Population

Quality Control Example – Gearbox Assemblies

plot.ts(diameter, ylim=c(18,22))
abline(h=19.5)
abline(h=21.45, lty=2)
abline(h=17.55, lty=2)

From the control chart above, we can see there are no points that extend
above the UCL and none below LCL so this process is in control.

Carrie Madden STAT 2000 – Unit 1 202 / 253


Unit 1 – Inference for the Mean of a Single Population

Inference when the standard deviation is Unknown

Until now, we have used the unrealistic assumption that we know the
population standard deviation σ of our variable of interest, in order to
more easily explain the reasoning behind or methods.
Now that the framework is in place, we are ready to make the transition to
the more realistic situation of unknown population standard deviation.

Carrie Madden STAT 2000 – Unit 1 203 / 253


Unit 1 – Inference for the Mean of a Single Population

Inference when the standard deviation is unknown

Recall that Z is a standard normal random variable. If X ∼ N (µ, σ), then

X̄ − µ
Z= ∼ N (0, 1)
√σ
n

Carrie Madden STAT 2000 – Unit 1 204 / 253


Unit 1 – Inference for the Mean of a Single Population

Inference when the standard deviation is unknown

What do we mean when we say “the distribution of Z ”?


If we take every possible sample of size n from the population of X , where
X ∼ N (µ, σ) and plot
x̄ − µ
z= σ

n

for each sample (this is theoretical, as there are infinitely many possible
samples), then we will get the standard normal curve.

Carrie Madden STAT 2000 – Unit 1 205 / 253


Unit 1 – Inference for the Mean of a Single Population

t-distribution

If σ is unknown, then we estimate it by the sample standard deviation s.


This standardized variable is very important, and we give it its own name.
IF X ∼ N (µ, σ), then the variable

X̄ − µ
T =
√s
n

follows a t distribution.

Carrie Madden STAT 2000 – Unit 1 206 / 253


Unit 1 – Inference for the Mean of a Single Population

t-distribution

That is, if we take every possible sample of size n, and plot


x̄ − µ
t=
√s
n

for each sample, then we will get a probability density curve that we call
the t distribution.
The quantity in the denominator of t is called the standard error of the
sample mean. The standard error of a random variable is its estimated
standard deviation.

Carrie Madden STAT 2000 – Unit 1 207 / 253


Unit 1 – Inference for the Mean of a Single Population

t-distribution

The t statistic
x̄ − µ
t=
√s
n

has the t distribution with n − 1 degrees of freedom.


Because the t distributions depend on the degrees of freedom, there is a
different t distribution associated with each value of the sample size. We
will write the t distribution with n − 1 degrees of freedom as t(n−1) for
short.

Carrie Madden STAT 2000 – Unit 1 208 / 253


Unit 1 – Inference for the Mean of a Single Population

T vs. Z

Since the form of t and z are quite similar, we expect the shape of the t
distribution to be similar to that of the standard normal curve.
In fact, this is the case. The t distribution is symmetric about its mean,
which is zero, but the spread for this distribution is slightly greater than
for the standard normal curve. This is the case because estimating σ by s
introduces more variation.

Carrie Madden STAT 2000 – Unit 1 209 / 253


Unit 1 – Inference for the Mean of a Single Population

T vs. Z
Comparing the T and Z Distribution
Comparison of t−distributions
0.4

t−distributions
df = 1
df = 5
df = 10
df = 25
normal
0.3
dnorm(x)

0.2
0.1
0.0

−4 −2 0 2 4

t−value

Carrie Madden STAT 2000 – Unit 1 210 / 253


Unit 1 – Inference for the Mean of a Single Population

R Code from above plot for your interest only

# This part of the code produces a dashed black normal curve.

x<-seq(-4, 4, length = 200) # Generating some numbers

df = c(1, 5, 10, 25) # these are the df’s I want


#for the t curves along with their colours.
colour = c("red","blue","green", "orange", "black")

Carrie Madden STAT 2000 – Unit 1 211 / 253


Unit 1 – Inference for the Mean of a Single Population

Cont’d
# Plots the normal curve, type is (line - not points)
#and lty (2 is a dashed line)
plot(x, dnorm(x), type = "l", lty = 2,
xlab = "t-value",
main = "Comparison of t-distributions", col = "black")
# This will add the t-distribution for the four df’s
#dt is density for t with $n-1$ df.
#So it looks at the vectors as a table of values.
for(i in 1:4){
lines(x, dt(x, df[i]), col=colour[i])
}
#This code adds the legend
legend("topright", c("df = 1", "df = 5", "df = 10",
"df = 25", "normal"),
col = colour, title = "t-distributions", lty = c(1,1,1,1,2))
Carrie Madden STAT 2000 – Unit 1 212 / 253
Unit 1 – Inference for the Mean of a Single Population

T vs. Z (Cont’d)

The t distributions have less area near the centre and more in the
tails than does the standard normal distribution.
As the degrees of freedom increase, the t distribution approaches the
standard normal distribution.
The critical values for selected t distributions are given in Table 3, for
various upper tail probabilities (located at the top).
R fuctions for the t-distribution:
dt() – calculates the density (won’t often use here)
pt() – calculates the area under the density curve
qt() – gives us our critical value from a given probability
rt() – generate random values from the t-distribution for certain
parameters.

Carrie Madden STAT 2000 – Unit 1 213 / 253


Unit 1 – Inference for the Mean of a Single Population

Confidence Intervals using T

We draw an SRS of size n from a population having unknown mean µ and


unknown standard deviation σ. A level C confidence interval for µ is:
s
x̄ ± t ∗ √
n

where t ∗ is the upper α


2 critical value for the t(n−1) distribution.
This interval is exact when the population is normal and approximate in
other cases when the sample size is large.

Carrie Madden STAT 2000 – Unit 1 214 / 253


Unit 1 – Inference for the Mean of a Single Population

Example – Reponse Times

Example
The chief of a local police department would like to estimate the true
mean response time for all emergency calls in the city. A random sample
of seven emergency calls is selected, and the police response times (in
minutes) are shown below:

7 4 11 8 7 12 9

We would like to construct a 95% confidence interval for the true mean
response time µ of all emergency response calls in the city. We will assume
that response times follow a normal distribution.

Carrie Madden STAT 2000 – Unit 1 215 / 253


Unit 1 – Inference for the Mean of a Single Population

Example – Reponse Times (Cont’d)

Some preliminary calculations:

n=7 x̄ = 8.29 s = 2.69

Solution
We find the upper 0.025 critical value from the t distribution with
n − 1 = 6 degrees of freedom to be t ∗ = 2.447. Our 95% confidence
interval is
s 2.69
 

x̄ ± t √ = 8.29 ± 2.447 √
n 7
= 8.29 ± 2.49 = (5.80, 10.78)

Carrie Madden STAT 2000 – Unit 1 216 / 253


Unit 1 – Inference for the Mean of a Single Population

Example – Reponse Times (Cont’d)

Interpretation
If we repeatedly measured samples of seven response times in this city and
constructed an interval in a similar manner, then 95% of such intervals
would contain the true mean response time µ.

The convergence of the t distribution to the standard normal distribution


as the sample size gets high can be seen by comparing critical values for
z ∗ and t ∗ for 1000 degrees of freedom.

Carrie Madden STAT 2000 – Unit 1 217 / 253


Unit 1 – Inference for the Mean of a Single Population

Example – Response Times in R

times<-c(7,4,11,8,7,12,9)
xbar<-mean(times)
sd<- sd(times)
n<-7
stderror<- sd/sqrt(n)
cvl<- qt(0.025,(n-1)) #negative critical value
cvu<-qt(0.975,(n-1)) #positive critical value

lower<- xbar - (cvu*stderror)


upper<- xbar + (cvu*stderror)

Carrie Madden STAT 2000 – Unit 1 218 / 253


Unit 1 – Inference for the Mean of a Single Population

Example – Response Times in R

lower

## [1] 5.797536

upper

## [1] 10.77389

Carrie Madden STAT 2000 – Unit 1 219 / 253


Unit 1 – Inference for the Mean of a Single Population

Calculating the Standard Deviation by hand - review

The number of goals scored by each of the five NHL Pacific Division
teams for the 2009/10 regular season are shown below:

Team Goals
Anaheim Ducks 238
Dallas Stars 237
L.A. Kings 241
Phoenix Coyotes 225
S.J. Sharks 264

We calculate x̄ = 241.

Carrie Madden STAT 2000 – Unit 1 220 / 253


Unit 1 – Inference for the Mean of a Single Population

Calculating the Standard Deviation

The sample variance is

(238 − 241)2 + . . . + (264 − 241)2


s2 =
4
9 + 16 + 256 + 529
= = 202.5
4

To get the sample standard deviation, we take the positive square root of
the variance: √ √
s = s 2 = 202.5 = 14.23

Carrie Madden STAT 2000 – Unit 1 221 / 253


Unit 1 – Inference for the Mean of a Single Population

Practice Question

A medical researcher measured the pulse rates (in beats per minute) of a
random sample of 10 adult females. The mean pulse rates of the females
in the sample was 72.2 and the standard deviation was 5.9. Assuming
pulse rates follow a normal distribution, a 96% confidence interval for the
true mean pulse rate of all adult females is given by:
 
5.9
1 72.2 ± 2.359 √
10
 
5.9
2 72.2 ± 2.398 √
9
 
5.9
3 72.2 ± 2.398 √
10
 
5.9
4 72.2 ± 2.054 √
10
 
5.9
5 72.2 ± 2.359 √
9

Carrie Madden STAT 2000 – Unit 1 222 / 253


Unit 1 – Inference for the Mean of a Single Population

Hypothesis Tests with T

We can also use the t distributions to conduct tests of significance:


Draw an SRS of size n from a normal distribution with unknown mean µ
and unknown standard deviation σ. Then null hypothesis Ho : µ = µo is
rejected in favour of the alternative hypothesis Ha when the P-value is less
than or equal to the level of significance α.

Carrie Madden STAT 2000 – Unit 1 223 / 253


Unit 1 – Inference for the Mean of a Single Population

Example – Response Times Revisted

Example
Consider the response times example. The police chief would like to know
if new measures need to be adopted in order to improve response times.
Specifically, he would like to know if the true mean response times has
increased since the previous year, when the mean time was known to be
6.5 minutes.We will conduct a hypothesis test to determine if the mean
response time has increased since last year. Test at the 10% level of
significance.

Carrie Madden STAT 2000 – Unit 1 224 / 253


Unit 1 – Inference for the Mean of a Single Population

Example – Response Times Revisted

Solution
1 Let α = 0.10

H0 : µ = 6.5
Ha : µ > 6.5

3 Reject H0 if P-value ≤ α = 0.10.


4 The test statistic is
x̄ − µ0 8.29 − 6.50
t= = = 1.76
√s 2.69

n 7

Carrie Madden STAT 2000 – Unit 1 225 / 253


Unit 1 – Inference for the Mean of a Single Population

Example – Response Times Revisted

Solution
 
5 The P-value is P T(6) ≥ 1.76 . From Table 3, we see that
   
P T(6) ≥ 1.440 = 0.10 and P T(6) ≥ 1.943 = 0.05

Since 1.440 < t = 1.76 < 1.943, it follows that our P-value is
between 0.05 and 0.10. For any P-value between 0.05 and 0.10, we
would reject the null hypothesis.
6 We have sufficient evidence to conclude that the department’s true
mean response time has increased since last year. As such, action will
be taken to improve response times.

Carrie Madden STAT 2000 – Unit 1 226 / 253


Unit 1 – Inference for the Mean of a Single Population

Example – Response Times Revisted

The interpretation of the P-value is the same for t tests as it is for z tests.
Interpretation
If the true mean response time was 6.5 minutes, the probability of getting
a sample mean at least as high as 8.29 minutes would be between 0.05
and 0.10.

Carrie Madden STAT 2000 – Unit 1 227 / 253


Unit 1 – Inference for the Mean of a Single Population

Example – Response Times Revisted – Critical


Value Approach
We repeat the test using the critical value approach:
Solution
1 Let α = 0.10

H0 : µ = 6.5
Ha : µ > 6.5

3 Reject H0 if t ≥ t ∗ = 1.440 where t ∗ = 1.440 is the upper 0.10


critical value from the t distribution with n − 1 = 6df .
4 The test statistic is
x̄ − µo 8.29 − 6.50
t= = = 1.76
√s 2.69

n 7
Carrie Madden STAT 2000 – Unit 1 228 / 253
Unit 1 – Inference for the Mean of a Single Population

Example – Response Times Revisted – Critical


Value Approach
Solution
Since t = 1.76 > t ∗ = 1.440, we reject the null hypothesis.
5 We have sufficient evidence to conclude that the department’s true
mean response time has increased since last year. As such, action will
be taken to improve response times.

alpha=0.10
cv<-qt(0.90, 6)
#we use 0.90 since this is a upper-tailed test.
#df = 6 = 7-1
cv

## [1] 1.439756
Carrie Madden STAT 2000 – Unit 1 229 / 253
Unit 1 – Inference for the Mean of a Single Population

T-test in R

Consider the response time example, here is the code;

times<-c(7,4,11,8,7,12,9)
t.test(times, mu=6.5, alternative = ’greater’)

Carrie Madden STAT 2000 – Unit 1 230 / 253


Unit 1 – Inference for the Mean of a Single Population

T-test in R Code Explained

##
## One Sample t-test
##
## data: times
## t = 1.7561, df = 6, p-value = 0.0648
## alternative hypothesis: true mean is greater than 6.5
## 95 percent confidence interval:
## 6.309763 Inf
## sample estimates:
## mean of x
## 8.285714

You can see from the output, our test statistic, the degrees of freedom and
the p-value associated with the test.
Carrie Madden STAT 2000 – Unit 1 231 / 253
Unit 1 – Inference for the Mean of a Single Population

Example – Fast Food

Example
A fast food restaurant claims that the average waiting time in their drive
through is less than a minute. We record the drive through waiting times
for a random sample of 30 customers. The sample average time is 55
seconds and the sample standard deviation is 15 seconds. Waiting times
are known to follow a normal distribution. We will conduct a hypothesis
test to examine the significance of the restaurant’s claim.

Carrie Madden STAT 2000 – Unit 1 232 / 253


Unit 1 – Inference for the Mean of a Single Population

Example – Fast Food (Cont’d)

Solution
1 Let α = 0.01.

H0 : µ = 60
Ha : µ < 60

3 Reject H0 if the P-value ≤ α = 0.01.


4 The test statistic is
x̄ − µ0 55 − 60
t= = = −1.83
√s √15
n 30

Carrie Madden STAT 2000 – Unit 1 233 / 253


Unit 1 – Inference for the Mean of a Single Population

Example – Fast Food (Cont’d)

Solution
   
5 The P-value is P T(29) ≤ −1.83 = P T(29) ≥ 1.83 by the
symmetry of the t distributions. We see from Table 3 that
   
P T(29) ≥ 1.699 = 0.05 and P T(29) ≥ 2.045 = 0.025

Since 1.699 < 1.83 < 2.045, if follows that the P-value is between
0.025 and 0.05. For any P-value between 0.025 and 0.05, we fail to
reject the null hypothesis.
6 We have insufficient evidence to conclude that the true mean waiting
time in the drive thru is less than one minute.

Carrie Madden STAT 2000 – Unit 1 234 / 253


Unit 1 – Inference for the Mean of a Single Population

Example Fast Food – (Cont’d)


We conduct the test again using the critical value approach:
Solution
1 Let α = 0.01.

H0 : µ = 60
Ha : µ < 60

3 Reject H0 if t ≤ t ∗ = −2.462 where −t ∗ = −2.462 is the lower 0.01


critical value from the t distribution with 29df .
4 The test statistic is
x̄ − µ0 55 − 60
t= = = −1.83
√s √15
n 30

Carrie Madden STAT 2000 – Unit 1 235 / 253


Unit 1 – Inference for the Mean of a Single Population

Example Fast Food – (Cont’d)

Solution
Since t = −1.83 > −t ∗ = −2.462, we fail to reject H0 .
5 We have insufficient evidence to conclude that the true mean waiting
time in the drive thru is less than one minute.

Carrie Madden STAT 2000 – Unit 1 236 / 253


Unit 1 – Inference for the Mean of a Single Population

Example Fast Food – R Code – P-value Method


n<-30
xbar<-55
mu<-60
s<-15
t<-((xbar-mu)/(s/sqrt(n)))
t

## [1] -1.825742

#pvalue method:
pt(t, 29)

## [1] 0.03910166

Note when we did it by hand we knew the p-value was between 0.025 and
0.05, we see the exact p-value with R is 0.0391
Carrie Madden STAT 2000 – Unit 1 237 / 253
Unit 1 – Inference for the Mean of a Single Population

Example Fast Food – R Code – Critical Value


Method

alpha=0.01
cv<-qt(0.01,29)
cv

## [1] -2.462021

Carrie Madden STAT 2000 – Unit 1 238 / 253


Unit 1 – Inference for the Mean of a Single Population

Practice Question
A major car manufacturer wants to test a new engine to determine if it
meets new air pollution standards. Safety regulations require that the
mean emission of all engines of this type must be less than 20 parts per
million (ppm) of carbon. If it is not less than 20, they will have to redesign
parts of the engine. A random sample of 25 engines is tested and the
emission level of each is determined. The sample mean is calculated to be
19.6 ppm and the sample standard deviation is 2.0 ppm. It is known that
emission levels are normally distributed with standard deviation 1.6 ppm.
We would like to test whether there is evidence that the engine meets the
new pollution standards. The hypotheses for the appropriate test of
significance are:
A H0 : µ = 20 vs. Ha : µ > 20
B H0 : µ = 19.6 vs. Ha : µ < 19.6
C H0 : µ = 20 vs. Ha : µ < 20
D H0 : µ = 19.6 vs. Ha : µ > 19.6
E H0 : X̄ = 20 vs. Ha : X̄ < 20
Carrie Madden STAT 2000 – Unit 1 239 / 253
Unit 1 – Inference for the Mean of a Single Population

Practice Question
A major car manufacturer wants to test a new engine to determine if it
meets new air pollution standards. Safety regulations require that the
mean emission of all engines of this type must be less than 20 parts per
million (ppm) of carbon. If it is not less than 20, they will have to redesign
parts of the engine. A random sample of 25 engines is tested and the
emission level of each is determined. The sample mean is calculated to be
19.6 ppm and the sample standard deviation is 2.0 ppm. It is known that
emission levels are normally distributed with standard deviation 1.6 ppm.
We would like to test whether there is evidence that the engine meets the
new pollution standards. The test statistic for the appropriate test of
significance is:
A t = −1.25
B z = −1.00
C t = −0.40
D z = −1.25
E t = −1.00
Carrie Madden STAT 2000 – Unit 1 240 / 253
Unit 1 – Inference for the Mean of a Single Population

Example – Air Pressure

A machine is designed to fill automobile tires to a mean air pressure of 30


pounds per square inch (psi). The manufacturer tests the machine on a
random sample of 25 tires. The sample has a mean air pressure of 30.9 psi
and a standard deviation of 1.8 psi. It is known that air pressure follows a
normal distribution.

Carrie Madden STAT 2000 – Unit 1 241 / 253


Unit 1 – Inference for the Mean of a Single Population

Example – Air Pressure


A 95% confidence interval for the true mean fill pressure for this machine
is:

s 1.8
 

x̄ ± t √ = 30.9 ± 2.064 √
n 25
= 30.9 ± 0.74 = (30.16, 31.64)

Note that we used the upper critical value from the t distribution with
24df .
Interpretation
If we repeatedly took samples of 25 fill pressures and calculated an interval
in a similar manner, then 95% of such intervals would contain the true
mean fill pressure for this machine.

Carrie Madden STAT 2000 – Unit 1 242 / 253


Unit 1 – Inference for the Mean of a Single Population

Example – Air Pressure R Code

xbar<-30.9
s<-1.8
n<-25
se<-(s/sqrt(n))
#95% CI
cv<-qt(0.975, 24)
cv

## [1] 2.063899

Carrie Madden STAT 2000 – Unit 1 243 / 253


Unit 1 – Inference for the Mean of a Single Population

Example – Air Pressure R Code

lower<-(xbar-(cv*se))
upper<-(xbar+(cv*se))
lower

## [1] 30.157

upper

## [1] 31.643

Carrie Madden STAT 2000 – Unit 1 244 / 253


Unit 1 – Inference for the Mean of a Single Population

Example – Air Pressure Hypothesis Test

We will now conduct a hypothesis test to determine whether the true


mean fill pressure for this machine differs from 30 psi.
1 Let α = 0.05.
2

H0 : µ = 30
Ha : µ ̸= 30

3 Reject H0 if the P-value ≤ α = 0.05.


4 The test statistic is
x̄ − µ 30.9 − 30
t= = = 2.50
√s 1.8

n 25

Carrie Madden STAT 2000 – Unit 1 245 / 253


Unit 1 – Inference for the Mean of a Single Population

Example – Air Pressure Hypothesis Test

 
5 The P-value is 2P T(24) ≥ 2.50 . We see from Table 3 that
   
P T(24) ≥ 2.492 = 0.01 and P T(24) ≥ 2.797 = 0.005

Since 2.492 < t = 2.50 < 2.797, it follows that


0.005 < P T(24) ≥ 2.50 < 0.01, and so the P-value is between
2 (0.005) = 0.01 and 2 (0.01) = 0.02. For any P-value between 0.01
and 0.02, we reject Ho .

Carrie Madden STAT 2000 – Unit 1 246 / 253


Unit 1 – Inference for the Mean of a Single Population

Example – Air Pressure Hypothesis Test

6 We have sufficient evidence to conclude that the true mean fill


pressure for this machine differs from 30 psi.

Note that, since this is a two-sided test using a 5% level of significance,


and since we constructed a 95% confidence interval for µ, we could have
used that interval to conduct the test. Since µ0 = 30 is not in the
confidence interval, we reject H0 . \end{frame}

Carrie Madden STAT 2000 – Unit 1 247 / 253


Unit 1 – Inference for the Mean of a Single Population

Practice Question

A random variable X follows a normal distribution with unknown mean µ


and unknown standard deviation σ. We take a random sample of 15
individuals and calculate the sample mean and sample standard deviation
s. We conduct a test of H0 : µ = 100 vs. Ha : µ ̸= 100 at α = 0.02. We
calculate a test statistic of t = 2.25. We conclude that we should:
1 reject H0 since the P-value is between 0.01 and 0.02.
2 reject H0 since the P-value is between 0.02 and 0.04.
3 fail to reject H0 since the P-value is between 0.02 and 0.04.
4 reject H0 since the P-value is between 0.04 and 0.05.
5 fail to reject H0 since the P-value is between 0.04 and 0.05.

Carrie Madden STAT 2000 – Unit 1 248 / 253


Unit 1 – Inference for the Mean of a Single Population

Example – Air Pressure - Critical Value


We conduct the test again using the critical value approach.
1 Let α = 0.05.
2

H0 : µ = 30
Ha : µ ̸= 30

3 Reject H0 if |t| ≥ t ∗ = 2.064 (i.e., if t ≤ −2.064 or if t ≥ 2.064)


where t ∗ = 2.064 is the upper 0.025 critical value from the t
distribution with 24df .
4 The test statistic is
x̄ − µ 30.9 − 30
t= = = 2.50
√s 1.8

n 25

Carrie Madden STAT 2000 – Unit 1 249 / 253


Unit 1 – Inference for the Mean of a Single Population

Example – Air Pressure - Critical Value

Since t = 2.50 > t ∗ = 2.064, we reject the null hypothesis.


6 We have sufficient evidence to conclude that the true mean fill
pressure for this machine differs from 30 psi.

Carrie Madden STAT 2000 – Unit 1 250 / 253


Unit 1 – Inference for the Mean of a Single Population

P-Values

Suppose we are conducting a test of

H0 : µ = µ 0
Ha : µ > µ0

We select a sample size of


 25 and we get  a test statistic of t = 4.58. We
see from Table 3 that P T(24) ≥ 3.745 = 0.0005, and that 3.745 is the
highest value in this row. As such, since our value is even higher, the
P-value must be less than 0.0005. This is another good reason to use
software as we will get a precise value.

Carrie Madden STAT 2000 – Unit 1 251 / 253


Unit 1 – Inference for the Mean of a Single Population

P-Values

Suppose we are conducting a test of

H0 : µ = µ 0
H0 : µ < µ0

 of size 16 and we get a test statistic of t = −0.43.


We select a sample 
The P-value is P T(15) ≤ −0.43 , which is equal to P T(15) ≥ 0.43 by
 
symmetry. We see from Table 3 that P T(15) ≥ 0.691 = 0.25, and that
0.691 us the lowest value in this row. As such, since our value is even
lower, the P-value must be greater than 0.25.

Carrie Madden STAT 2000 – Unit 1 252 / 253


Unit 1 – Inference for the Mean of a Single Population

Cautions about t- procedures

Because t is a function of the sample mean and of the sample


standard deviation, which are both strongly influenced by out lies, t
itself is strongly influenced by outliers.
Although we have an assumption that the population is normal, the t
procedures are quite robust against non normality.
The most important assumption (except for small samples) is that the
data are from an SRS from the population.

Carrie Madden STAT 2000 – Unit 1 253 / 253

You might also like