0% found this document useful (0 votes)
13 views62 pages

Lecture 07 (Part I) Hypothesis Testing

This document discusses hypothesis testing terminology and one sample tests, including z-tests and t-tests. It provides examples of right-tailed, left-tailed, and two-tailed z-tests for means. The examples calculate test values and compare them to critical values to determine whether to reject the null hypothesis or not.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views62 pages

Lecture 07 (Part I) Hypothesis Testing

This document discusses hypothesis testing terminology and one sample tests, including z-tests and t-tests. It provides examples of right-tailed, left-tailed, and two-tailed z-tests for means. The examples calculate test values and compare them to critical values to determine whether to reject the null hypothesis or not.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 62

CCN2311

FOUNDATIONS OF DATA SCIENCE


LECTURE 7 (PART I)
Terminologies of Hypothesis Testing
One Sample Tests
Topics
1. Terminologies of hypothesis testing
2. One sample tests
• One sample tests for means (Z-Test and t-Test) (in Part I)
• One sample tests for proportions (Z-Test) (in Part II)
• One sample tests for variances (Chi-Square Test) (in Part II)

CCN2311 Foundations of Data Science Page 2


Making Decisions by Using Data
• Hypothesis Tests are statistical tools for making
decisions using data
• These decisions are binary decisions about unknown
population parameter (such as 𝜇𝜇, 𝑝𝑝 or 𝜎𝜎 2 ), e.g.
1. Let 𝜇𝜇 be average household income in Hong Kong. Is 𝜇𝜇 ≤
$20,000 or 𝜇𝜇 > $20,000?
2. Let 𝑝𝑝 be the proportion of Hong Kong people who paid
taxes. Is 𝑝𝑝 ≥ 0.6 or 𝑝𝑝 < 0.6?
3. Let 𝜎𝜎 2 be variance of the GPA of students in HKCC. Is 𝜎𝜎 2 =
1.5 or 𝜎𝜎 2 ≠ 1.5?

CCN2311 Foundations of Data Science Page 3


Decisions Cannot be Made by Using
Point Estimates Alone
In the 1st example 𝜇𝜇 is the average household income in Hong Kong
and we want to decide if 𝜇𝜇 ≤ $20,000 or 𝜇𝜇 > $20,000.
• Suppose a survey is carried out and we found that the sample
mean is 𝑥𝑥̅ = $50,000, we will likely conclude that 𝜇𝜇 > $20,000
• If the sample mean is 𝑥𝑥̅ = $20,001, can you still conclude that
𝜇𝜇 > $20,000? Probably not as 𝑥𝑥̅ may be greater than $20,000
because of random chance!!

Therefore, we need some objective ways to make these kind of


decisions.

CCN2311 Foundations of Data Science Page 4


Types of Hypotheses - 𝑯𝑯𝟎𝟎 and 𝑯𝑯𝟏𝟏
• The two possible decisions in a hypothesis test are
called the null hypothesis and the alternative
hypothesis
• Null hypotheses (𝑯𝑯𝟎𝟎 ) involves equality of a parameter
and a known value. E.g.
𝐻𝐻0 : 𝜇𝜇 = 123 or 𝐻𝐻0 : 𝜇𝜇 ≥ 123 or 𝐻𝐻0 : 𝜇𝜇 ≤ 123
• Alternative hypotheses (𝑯𝑯𝟏𝟏 ) involves inequality of a
parameter and a known value. E.g.
𝐻𝐻1 : 𝜇𝜇 ≠ 123 or 𝐻𝐻1 : 𝜇𝜇 > 123 or 𝐻𝐻1 : 𝜇𝜇 < 123

CCN2311 Foundations of Data Science Page 5


Pairs of Hypotheses
Since we need to make a decision out of two choices, they
can be represented as a pair of hypotheses containing one
𝐻𝐻0 and one 𝐻𝐻1 . For example,
𝐻𝐻0 : 𝜇𝜇 = 123 vs 𝐻𝐻1 : 𝜇𝜇 ≠ 123
𝐻𝐻0 : 𝜇𝜇 = 123 vs 𝐻𝐻1 : 𝜇𝜇 < 123
𝐻𝐻0 : 𝜇𝜇 = 123 vs 𝐻𝐻1 : 𝜇𝜇 > 123

It is important to note that the two hypotheses must be


mutually exclusive (no overlap), e.g. 𝐻𝐻0 : 𝜇𝜇 ≤ 123 vs
𝐻𝐻1 : 𝜇𝜇 > 100 is a pair of overlapping hypotheses.
CCN2311 Foundations of Data Science Page 6
Conceptual Idea of Hypothesis Testing
Consider the example of testing the effectiveness of a diet program
in reducing body weight.
• We can let 𝜇𝜇 be the average weight change in body weight after
participating in the diet program
• If a person does not participate in the diet program, we expect
the weight change is 0, i.e. 𝐻𝐻0 : 𝜇𝜇 = 0.
• If a person participate in the diet program, we conjecture that
the weight change will be negative (decrease in weight), i.e.
𝐻𝐻1 : 𝜇𝜇 < 0
Note: in this example, we don't expect the body weight will go up
after participating in the diet program.

CCN2311 Foundations of Data Science Page 7


Conceptual Idea of Hypothesis Testing
• We first assumes 𝐻𝐻0 to be correct, the we try to collect evidence
(data) to conclude that 𝐻𝐻0 is wrong and 𝐻𝐻1 is correct.
• This is very similar to how trials are being done in a court. Before
we have any evidence, we assume a person is not guilty (𝐻𝐻0 ).
Once sufficient evidence (i.e. data) are presented, we can
conclude that a person is guilty (𝐻𝐻1 ).
• Once we have the data evidence we will make a decision out of
the following two decisions
– REJECT 𝑯𝑯𝟎𝟎
– DO NOT REJECT 𝑯𝑯𝟎𝟎

CCN2311 Foundations of Data Science Page 8


Errors in Hypothesis Testing
Since the decision is made on the basis of a random sample, it is
possible to make wrong decision (error) in hypothesis testing. The
matrix below illustrates the types of errors that can be made.
Decision Actual Truth (unknown)
(based on data) 𝑯𝑯𝟎𝟎 is TRUE 𝑯𝑯𝟎𝟎 is FALSE
Wrong decision
Reject 𝑯𝑯𝟎𝟎 Correct decision
(Type I Error)
Wrong decision
Do not reject 𝑯𝑯𝟎𝟎 Correct decision
(Type II Error)

Type I error: Reject 𝐻𝐻0 when 𝐻𝐻0 is TRUE


Type II error: Do not reject 𝐻𝐻0 when 𝐻𝐻0 is FALSE

CCN2311 Foundations of Data Science Page 9


Errors in Hypothesis Testing
• Due to the possibilities of making wrong decisions. The goal of
hypothesis testing is to control the error when making a decision
• The probability 𝛼𝛼 = 𝑃𝑃(𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇 𝐼𝐼 𝐸𝐸𝐸𝐸𝐸𝐸𝐸𝐸𝐸𝐸) is called the level of
significance
• The probability 𝛽𝛽 = 𝑃𝑃(𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇 𝐼𝐼𝐼𝐼 𝐸𝐸𝐸𝐸𝐸𝐸𝐸𝐸𝐸𝐸). The probability 1 − 𝛽𝛽 is
called the power of the test
• When conducting a hypothesis test, the probability 𝛼𝛼 is specified
by the researcher (similar to the confidence level of confidence
interval). Usually we will select a very small probability for 𝛼𝛼, e.g.
0.05.

CCN2311 Foundations of Data Science Page 10


Z-Test for Means
Assumptions:
• 𝑋𝑋1 , 𝑋𝑋2 , … , 𝑋𝑋𝑛𝑛 are iid normal random variable with unknown mean 𝜇𝜇 and
known variance 𝜎𝜎 2
Observed Data and Useful Quantities:
• 𝑥𝑥1 , 𝑥𝑥2 , … , 𝑥𝑥𝑛𝑛 are the observed values of the random sample
• 𝑥𝑥̅ is the sample mean
Types of Tests:
𝐻𝐻0 : 𝜇𝜇 = 𝑐𝑐 vs 𝐻𝐻1 : 𝜇𝜇 > 𝑐𝑐 [Right tailed test]
𝐻𝐻0 : 𝜇𝜇 ≤ 𝑐𝑐 vs 𝐻𝐻1 : 𝜇𝜇 > 𝑐𝑐 [Right tailed test]
𝐻𝐻0 : 𝜇𝜇 = 𝑐𝑐 vs 𝐻𝐻1 : 𝜇𝜇 < 𝑐𝑐 [Left tailed test]
𝐻𝐻0 : 𝜇𝜇 ≥ 𝑐𝑐 vs 𝐻𝐻1 : 𝜇𝜇 < 𝑐𝑐 [Left tailed test]
𝐻𝐻0 : 𝜇𝜇 = 𝑐𝑐 vs 𝐻𝐻1 : 𝜇𝜇 ≠ 𝑐𝑐 [Two tailed test]

CCN2311 Foundations of Data Science Page 11


Z-Test for Means – Procedure
(Critical Value Method)
This is an outline of the procedures of Z-Test for a given level of significance 𝛼𝛼
Step 1: Form the pair of hypotheses 𝐻𝐻0 and 𝐻𝐻1 based on your business problem
Step 2: Calculate critical value(s)
For left tailed test: critical value = −𝑧𝑧𝛼𝛼
For right tailed test: critical value = +𝑧𝑧𝛼𝛼
For two tailed test: critical values = ±𝑧𝑧𝛼𝛼/2
Step 3: Calculate test value
̅
𝑥𝑥−𝜇𝜇
𝑧𝑧 = 𝜎𝜎 , where 𝜇𝜇 is the hypothesized mean, 𝜎𝜎 is the known standard
𝑛𝑛
deviation, 𝑋𝑋� is the sample mean and 𝑛𝑛 is the sample size
Step 4: Make the decision
For left tailed test: reject 𝐻𝐻0 if 𝑧𝑧 < −z𝛼𝛼
For right tailed test: reject 𝐻𝐻0 if 𝑧𝑧 > +𝑧𝑧𝛼𝛼
For two tailed test: reject 𝐻𝐻0 if 𝑧𝑧 < −𝑧𝑧𝛼𝛼/2 or 𝑧𝑧 > +𝑧𝑧𝛼𝛼/2

CCN2311 Foundations of Data Science Page 12


Z-Test for Means - Examples
We will walk through the three types of Z-Tests in the
following examples
Example 1 – Z-Test for Mean (Right tailed)
Example 2 – Z-Test for Mean (Left tailed)
Example 3 – Z-Test for Mean (Two tailed)

CCN2311 Foundations of Data Science Page 13


Example 1 – Z-Test for Mean (Right
tailed)
The average IQ of students in CCN1234 was about 100. The teacher
of CCN1234 feels that this year’s students are smarter and he claims
that the average IQ of this year’s students is greater than 100.

In a random sample of 20 students in CCN1234, the average IQ is


103. Can we conclude the teacher’s claim at a level of significance
of 𝛼𝛼 = 0.05?

(We can assume that the IQs of the students in CCN1234 are
normally distributed with an unknown mean 𝜇𝜇 and a standard
deviation of 5)

CCN2311 Foundations of Data Science Page 14


Example 1 – Z-Test for Mean (Right
tailed)
Useful information: normal population, 𝑛𝑛 = 20, 𝑥𝑥̅ = 103, 𝜎𝜎 = 5 and 𝛼𝛼 = 0.05
Step 1: 𝐻𝐻0 : 𝜇𝜇 = 100 vs 𝐻𝐻1 : 𝜇𝜇 > 100 Right tailed!

Step 2: 𝛼𝛼 = 0.05 and it is a right tailed test, therefore critical value is 𝑧𝑧0.05 =
1.645 Standard Normal Distribution

area = 𝛼𝛼 =0.05

𝑧𝑧𝛼𝛼

CCN2311 Foundations of Data Science Page 15


Example 1 – Z-Test for Mean (Right
tailed)
̅
𝑥𝑥−𝜇𝜇 103−100
Step 3: test value 𝑧𝑧 = = ≈ 2.683
𝜎𝜎/ 𝑛𝑛 (5/ 20)
Note that 𝜇𝜇 is the value specified in 𝐻𝐻0 .
Step 4: Since test value (2.683) is greater than the critical value (1.645), test
value falls into the critical region (aka rejection region). The decision is to
reject 𝑯𝑯𝟎𝟎 and we have evidence that the average IQ of this year’s students
is greater than 100. Standard Normal Distribution
Non-critical region critical region
(Non-rejection region) (rejection region)

Critical region is on
the RIGHT hand for
RIGHT tailed test

critical test
value value
(1.645) (2.683)

CCN2311 Foundations of Data Science Page 16


Example 1 – Reasoning Behind Right
Tailed Test
1. If 𝐻𝐻0 is TRUE, the test value is distributed as 𝑁𝑁(0,1). (Do you recall why?)

2. If the average IQ is actually much greater than 100 (i.e. 𝐻𝐻1 is TRUE), sample
mean will likely be large, and hence, the test value will also be large (and
positive too).

3. Therefore we need to reject 𝐻𝐻0 when test value is large. But how large is
large??

4. We use the critical value to judge what do we mean by a “large” test value.
The critical value is chosen such that 𝛼𝛼 = 𝑃𝑃 𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇 𝐼𝐼 𝐸𝐸𝐸𝐸𝐸𝐸𝐸𝐸𝐸𝐸 = 0.05. That is
we have a small probability making Type I Error if using the critical value as a
cut-off.

CCN2311 Foundations of Data Science Page 17


Example 2 – Z-Test for Mean (Left
tailed)
The average blood pressure of hypertension patients is about
90mmHg. A doctor claims that a new drug is effective in reducing
the blood pressure of hypertension patients.

For a random sample of 25 hypertension patients taking the new


drug, the average blood pressure is 89 mmHg. Can we conclude the
doctor’s claim at a level of significance of 𝛼𝛼 = 0.01?

(We can assume that the blood pressures of the hypertension


patients are normally distributed with an unknown mean 𝜇𝜇 and a
standard deviation of 4 mmHg)

CCN2311 Foundations of Data Science Page 18


Example 2 – Z-Test for Mean (Left
tailed)
Useful information: normal population, 𝑛𝑛 = 25, 𝑥𝑥̅ = 89, 𝜎𝜎 = 4 and 𝛼𝛼 = 0.01
Step 1: 𝐻𝐻0 : 𝜇𝜇 = 90 vs 𝐻𝐻1 : 𝜇𝜇 < 90 Left tailed!

Step 2: 𝛼𝛼 = 0.01 and it is a left tailed test, therefore critical value is −𝑧𝑧0.01 =
− 2.33 Standard Normal Distribution

area = 𝛼𝛼 =0.01

−𝑧𝑧𝛼𝛼

CCN2311 Foundations of Data Science Page 19


Example 2 – Z-Test for Mean (Left
tailed)
̅
𝑥𝑥−𝜇𝜇 89−90
Step 3: test value 𝑧𝑧 = = = −1.25
𝜎𝜎/ 𝑛𝑛 (4/ 25)
Note that 𝜇𝜇 is the value specified in 𝐻𝐻0 .
Step 4: Since test value (-1.25) is greater than the critical value (-2.33), test value falls into
the non-critical region (aka non-rejection region). The decision is not to reject 𝑯𝑯𝟎𝟎
and we do not have evidence that the new drug can reduce the blood pressure of
hypertension patients.
Standard Normal Distribution

critical region Non-critical region


(rejection region) (Non-rejection region)

Critical region is on
the LEFT hand for
LEFT tailed test
critical test
value value
(-2.33) (-1.25)

CCN2311 Foundations of Data Science Page 20


Example 2 – Reasoning Behind Left
Tailed Test
1. If 𝐻𝐻0 is TRUE, the test value is distributed as 𝑁𝑁(0,1).

2. If the average blood pressure is actually much smaller than 90 after taking
the new drug (i.e. 𝐻𝐻1 is TRUE), sample mean will likely be small, and hence,
the test value will also be small (and negative too).

3. Therefore we need to reject 𝐻𝐻0 when test value is small. But how small is
small??

4. We use the critical value to judge what do we mean by a “small” test value.
The critical value is chosen such that 𝛼𝛼 = 𝑃𝑃 𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇 𝐼𝐼 𝐸𝐸𝐸𝐸𝐸𝐸𝐸𝐸𝐸𝐸 = 0.01. That is
we have a small probability making Type I Error if using the critical value as a
cut-off.

CCN2311 Foundations of Data Science Page 21


Example 3 – Z-Test for Mean (Two
tailed)
The average heart rate of healthy adults is 67 beats per minutes. A
doctor claims that a new drug may have side effects and change the
heart rate of a person.

The doctor tests the new drug on a random sample of 36 healthy


adults. At the end of the study the average heart rate of the adults
in the sample is 63 beats per minutes. Can we conclude the doctor’s
claim at a level of significance of 𝛼𝛼 = 0.05?

(We can assume that the heart rates of healthy adults are normally
distributed with an unknown mean 𝜇𝜇 and a standard deviation of
10)

CCN2311 Foundations of Data Science Page 22


Example 3 – Z-Test for Mean (Two
tailed)
Useful information: normal population, 𝑛𝑛 = 36, 𝑥𝑥̅ = 63, 𝜎𝜎 = 10 and 𝛼𝛼 = 0.05
Step 1: 𝐻𝐻0 : 𝜇𝜇 = 67 vs 𝐻𝐻1 : 𝜇𝜇 ≠ 67 Two tailed!

Step 2: 𝛼𝛼 = 0.05 and it is a two tailed test, therefore critical values


are ±𝑧𝑧𝛼𝛼/2 = ±1.96
Standard Normal Distribution

area = 𝛼𝛼/2 =0.025 area = 𝛼𝛼/2 =0.025

−𝑧𝑧𝛼𝛼/2 𝑧𝑧𝛼𝛼/2

CCN2311 Foundations of Data Science Page 23


Example 3 – Z-Test for Mean (Two
tailed)
̅
𝑥𝑥−𝜇𝜇 63−67
Step 3: test value 𝑧𝑧 = = = −2.4
𝜎𝜎/ 𝑛𝑛 (10/ 36)
Note that 𝜇𝜇 is the value specified in 𝐻𝐻0 .
Step 4: Since test value (-2.4) is NOT between the critical values (±1.96), test value falls
into the critical region (aka rejection region). The decision is to reject 𝑯𝑯𝟎𝟎 and we
do have evidence that the new drug can affect the heart rates of healthy adults.

Standard Normal Distribution

critical region Non-critical region critical region


(rejection region) (Non-rejection region) (rejection region)

Critical region is on
both sides for 2
tailed test
test critical critical
value value value
(-2.4) (-1.96) (1.96)

CCN2311 Foundations of Data Science Page 24


Example 3 – Reasoning Behind Two
Tailed Test
1. If 𝐻𝐻0 is TRUE, the test value is distributed as 𝑁𝑁(0,1).

2. If the average heart rate is actually different from 67 after taking the new
drug (i.e. 𝐻𝐻1 is TRUE), sample mean will likely be either be much smaller than
67 or much larger than 67, and hence, the test value will also be very small
(and negative) or very large (and positive).

3. Therefore we need to reject 𝐻𝐻0 when test value is either very small or very
large. But for how small or how large??

4. We use the critical value to judge what do we mean by a “small” or “large”


test value. The critical values are chosen such that 𝛼𝛼 = 𝑃𝑃 𝑇𝑇𝑇𝑇𝑇𝑇𝑇𝑇 𝐼𝐼 𝐸𝐸𝐸𝐸𝐸𝐸𝐸𝐸𝐸𝐸 =
0.05. That is we have a small probability making Type I Error if using the
critical values as a cut-off.

CCN2311 Foundations of Data Science Page 25


How about 𝑯𝑯𝟎𝟎 : 𝝁𝝁 ≤ 𝒄𝒄 & 𝑯𝑯𝟎𝟎 : 𝝁𝝁 ≥ 𝒄𝒄
In Example 1 to 3, the null hypotheses 𝐻𝐻0 are all 𝐻𝐻0 = 𝑐𝑐 where 𝑐𝑐 is
a constant. In fact, the left and right tailed tests can be modified to

Right tailed test: 𝐻𝐻0 : 𝜇𝜇 ≤ 𝑐𝑐 vs 𝐻𝐻1 : 𝜇𝜇 > 𝑐𝑐


Left tailed test: 𝐻𝐻0 : 𝜇𝜇 ≥ 𝑐𝑐 vs 𝐻𝐻1 : 𝜇𝜇 < 𝑐𝑐

• Despite of the change in 𝐻𝐻0 , the procedure of the tests are the
same as before.
• However the probability of committing Type I error will be less
than or equal to 𝛼𝛼, instead of exactly equal to 𝛼𝛼.

CCN2311 Foundations of Data Science Page 26


Example 4
Suppose 𝑥𝑥̅ = 15, 𝑛𝑛 = 25, 𝜎𝜎 = 2. Test the following
hypotheses using Z-Test, by assuming normality.
(a) 𝐻𝐻0 : 𝜇𝜇 = 14 vs 𝐻𝐻1 : 𝜇𝜇 > 14 (𝛼𝛼 = 0.07)
(b) 𝐻𝐻0 : 𝜇𝜇 = 14 vs 𝐻𝐻1 : 𝜇𝜇 < 14 (𝛼𝛼 = 0.05)
(c) 𝐻𝐻0 : 𝜇𝜇 = 14 vs 𝐻𝐻1 : 𝜇𝜇 ≠ 14 (𝛼𝛼 = 0.12)

CCN2311 Foundations of Data Science Page 27


Example 4 (a) - Solution

CCN2311 Foundations of Data Science Page 28


Example 4 (b) - Solution

CCN2311 Foundations of Data Science Page 29


Example 4 (c) - Solution

CCN2311 Foundations of Data Science Page 30


Example 4 (a) - Solution
Step 1: 𝐻𝐻0 : 𝜇𝜇 = 14 vs 𝐻𝐻1 : 𝜇𝜇 > 14
Step 2: This is a right tailed test and 𝛼𝛼 = 0.07. Therefore
critical value is 𝑧𝑧0.07 = 1.48.
̅
𝑥𝑥−𝜇𝜇 15−14
Step 3: Test value 𝑧𝑧 = = = 2.5
(𝜎𝜎/ 𝑛𝑛) 2/ 25
Step 4: Since the test value is greater than the critical
value, it is in the critical region. The decision is to
reject 𝐻𝐻0 and we have evidence to conclude that 𝜇𝜇
is greater than 14.

CCN2311 Foundations of Data Science Page 31


Example 4 (b) - Solution
Step 1: 𝐻𝐻0 : 𝜇𝜇 = 14 vs 𝐻𝐻1 : 𝜇𝜇 < 14
Step 2: This is a left tailed test and 𝛼𝛼 = 0.05. Therefore
critical value is −𝑧𝑧0.05 = −1.645.
̅
𝑥𝑥−𝜇𝜇 15−14
Step 3: Test value 𝑧𝑧 = = = 2.5
(𝜎𝜎/ 𝑛𝑛) 2/ 25
Step 4: Since the test value is greater than the critical
value, it is in the non-critical region. The decision
is NOT to reject 𝐻𝐻0 and we do not have evidence
to conclude that 𝜇𝜇 is less than 14.

CCN2311 Foundations of Data Science Page 32


Example 4 (c) - Solution
Step 1: 𝐻𝐻0 : 𝜇𝜇 = 14 vs 𝐻𝐻1 : 𝜇𝜇 ≠ 14
Step 2: This is a two tailed test and 𝛼𝛼 = 0.12. Therefore
critical values are ±𝑧𝑧0.06 = ±1.555.
̅
𝑥𝑥−𝜇𝜇 15−14
Step 3: Test value 𝑧𝑧 = = = 2.5
(𝜎𝜎/ 𝑛𝑛) 2/ 25
Step 4: Since the test value is NOT between the critical
values, it is in the critical region. The decision is to
reject 𝐻𝐻0 and we have evidence to conclude that 𝜇𝜇
is not equal to 14.

CCN2311 Foundations of Data Science Page 33


p-value Method for Hypothesis Testing
• There is a disadvantage of using critical values in hypothesis
testing
• If you change the value of 𝛼𝛼, you need to go through the
hypothesis testing procedure again and find a new critical value
• If your audience has a different 𝛼𝛼 in mind, it will be very
inconvenient
• Statisticians therefore invented another method called p-value
method
• The procedure of p-value method is different from critical value
method, but the final conclusion is the same

CCN2311 Foundations of Data Science Page 34


Calculation of p-value (left tailed)
p-value of left tailed tests = 𝑃𝑃 𝑍𝑍 < 𝑡𝑡𝑡𝑡𝑡𝑡𝑡𝑡 𝑣𝑣𝑣𝑣𝑣𝑣𝑣𝑣𝑣𝑣
Example: Example:
Test value = 1.8 Test value = -1.5
p-value = 𝑃𝑃 𝑍𝑍 < 1.8 p-value = 𝑃𝑃 𝑍𝑍 < −1.5
= 0.9641 = 0.0668
p-value=0.9641

p-value=0.0668

Test value = 1.8 Test value = -1.5


CCN2311 Foundations of Data Science Page 35
Calculation of p-value (right tailed)
p-value of right tailed tests = 𝑃𝑃 𝑍𝑍 > 𝑡𝑡𝑡𝑡𝑡𝑡𝑡𝑡 𝑣𝑣𝑣𝑣𝑣𝑣𝑣𝑣𝑣𝑣
Example: Example:
Test value = 1.8 Test value = -1.5
p-value = 𝑃𝑃 𝑍𝑍 > 1.8 p-value = 𝑃𝑃 𝑍𝑍 > −1.5
= 0.0359 = 0.9332

p-value=0.0359 p-value=0.9332

Test value = 1.8 Test value = -1.5


CCN2311 Foundations of Data Science Page 36
Calculation of p-value (2-tailed)
p-value of 2-tailed tests = 2 × 𝑃𝑃 𝑍𝑍 > |𝑡𝑡𝑡𝑡𝑡𝑡𝑡𝑡 𝑣𝑣𝑣𝑣𝑣𝑣𝑣𝑣𝑣𝑣|
Example: Example:
Test value = 1.8 Test value = -1.5
p-value = 2𝑃𝑃 𝑍𝑍 > |1.8| p-value = 2𝑃𝑃 𝑍𝑍 > | − 1.5|
= 2 1 − 0.9641 = 2 1 − 0.9332
= 0.0718 = 0.1336

p-value=0.0718 p-value=0.1336

-1.8 1.8 -1.5 1.5


CCN2311 Foundations of Data Science Page 37
Z-Test for Means – Procedure
(p-Value Method)
This is an outline of the procedures of Z-Test for a given level of significance 𝛼𝛼
Step 1: Form the pair of hypotheses 𝐻𝐻0 and 𝐻𝐻1 based on your business problem
Step 2: Calculate test value
̅
𝑥𝑥−𝜇𝜇
𝑧𝑧 = 𝜎𝜎 , where 𝜇𝜇 is the hypothesized mean, 𝜎𝜎 is the known standard
𝑛𝑛
deviation, 𝑋𝑋� is the sample mean and 𝑛𝑛 is the sample size
Step 3: Find p-value
For left tailed test: p-value = 𝑃𝑃 𝑍𝑍 < 𝑡𝑡𝑡𝑡𝑡𝑡𝑡𝑡 𝑣𝑣𝑣𝑣𝑣𝑣𝑣𝑣𝑣𝑣
For right tailed test: p-value = 𝑃𝑃 𝑍𝑍 > 𝑡𝑡𝑡𝑡𝑡𝑡𝑡𝑡 𝑣𝑣𝑣𝑣𝑣𝑣𝑣𝑣𝑣𝑣
For two tailed test: p-value = 2 × 𝑃𝑃(𝑍𝑍 > 𝑡𝑡𝑡𝑡𝑡𝑡𝑡𝑡 𝑣𝑣𝑣𝑣𝑣𝑣𝑣𝑣𝑣𝑣 )
Step 4: Make the decision
Any type of tests: reject 𝐻𝐻0 if p-value < 𝛼𝛼

CCN2311 Foundations of Data Science Page 38


Example 5
Suppose 𝑥𝑥̅ = 21.5, 𝑛𝑛 = 36, 𝜎𝜎 = 4. Test the following
hypotheses using Z-Test, by assuming normality.
(a) 𝐻𝐻0 : 𝜇𝜇 = 20 vs 𝐻𝐻1 : 𝜇𝜇 > 20 (𝛼𝛼 = 0.10)
(b) 𝐻𝐻0 : 𝜇𝜇 = 20 vs 𝐻𝐻1 : 𝜇𝜇 < 20 (𝛼𝛼 = 0.05)
(c) 𝐻𝐻0 : 𝜇𝜇 = 20 vs 𝐻𝐻1 : 𝜇𝜇 ≠ 20 (𝛼𝛼 = 0.01)

CCN2311 Foundations of Data Science Page 39


Example 5 (a) - Solution

CCN2311 Foundations of Data Science Page 40


Example 5 (b) - Solution

CCN2311 Foundations of Data Science Page 41


Example 5 (c) - Solution

CCN2311 Foundations of Data Science Page 42


Example 5 (a) - Solution
Step 1: 𝐻𝐻0 : 𝜇𝜇 = 20 vs 𝐻𝐻1 : 𝜇𝜇 > 20
̅
𝑥𝑥−𝜇𝜇 21.5−20
Step 2: Test value 𝑧𝑧 = = = 2.25
(𝜎𝜎/ 𝑛𝑛) 4/ 36
Step 3: p-value = 𝑃𝑃 𝑍𝑍 > 2.25 = 0.0122
Step 4: Since p-value (0.0122) is less than 𝛼𝛼 (0.1), the
decision is to reject 𝐻𝐻0 and we have evidence to
conclude that 𝜇𝜇 is greater than 20.

CCN2311 Foundations of Data Science Page 43


Example 5 (b) - Solution
Step 1: 𝐻𝐻0 : 𝜇𝜇 = 20 vs 𝐻𝐻1 : 𝜇𝜇 < 20
̅
𝑥𝑥−𝜇𝜇 21.5−20
Step 2: Test value 𝑧𝑧 = = = 2.25
(𝜎𝜎/ 𝑛𝑛) 4/ 36
Step 3: p-value = 𝑃𝑃 𝑍𝑍 < 2.25 = 0.9878
Step 4: Since the p-value (0.9878) is greater than 𝛼𝛼 (0.05),
the decision is NOT to reject 𝐻𝐻0 and we do not
have evidence to conclude that 𝜇𝜇 is less than 20.

CCN2311 Foundations of Data Science Page 44


Example 5 (c) - Solution
Step 1: 𝐻𝐻0 : 𝜇𝜇 = 20 vs 𝐻𝐻1 : 𝜇𝜇 ≠ 20
̅
𝑥𝑥−𝜇𝜇 21.5−20
Step 2: Test value 𝑧𝑧 = = = 2.25
(𝜎𝜎/ 𝑛𝑛) 4/ 36
Step 3: p-value = 2 × 𝑃𝑃 𝑍𝑍 > |2.25| = 0.0244
Step 4: Since p-value (0.0244) is greater than 𝛼𝛼 (0.01), the
decision is NOT to reject 𝐻𝐻0 and we do not have
evidence to conclude that 𝜇𝜇 is not equal to 20.

CCN2311 Foundations of Data Science Page 45


Questions?

CCN2311 Foundations of Data Science Page 46


t-Test for Means
Assumptions:
• 𝑋𝑋1 , 𝑋𝑋2 , … , 𝑋𝑋𝑛𝑛 are iid normal random variable with unknown mean 𝜇𝜇 and
unknown variance 𝜎𝜎 2
Observed Data and Useful Quantities:
• 𝑥𝑥1 , 𝑥𝑥2 , … , 𝑥𝑥𝑛𝑛 are the observed values of the random sample
• 𝑥𝑥̅ and 𝑠𝑠 2 are the sample mean and sample variance

Types of Tests:
𝐻𝐻0 : 𝜇𝜇 = 𝑐𝑐 vs 𝐻𝐻1 : 𝜇𝜇 > 𝑐𝑐 [Right tailed test]
𝐻𝐻0 : 𝜇𝜇 ≤ 𝑐𝑐 vs 𝐻𝐻1 : 𝜇𝜇 > 𝑐𝑐 [Right tailed test]
𝐻𝐻0 : 𝜇𝜇 = 𝑐𝑐 vs 𝐻𝐻1 : 𝜇𝜇 < 𝑐𝑐 [Left tailed test]
𝐻𝐻0 : 𝜇𝜇 ≥ 𝑐𝑐 vs 𝐻𝐻1 : 𝜇𝜇 < 𝑐𝑐 [Left tailed test]
𝐻𝐻0 : 𝜇𝜇 = 𝑐𝑐 vs 𝐻𝐻1 : 𝜇𝜇 ≠ 𝑐𝑐 [Two tailed test]

CCN2311 Foundations of Data Science Page 47


t-Test for Means - Procedure
This is an outline of the procedures of t-Test for a given level of significance 𝛼𝛼
Step 1: Form the pair of hypotheses 𝐻𝐻0 and 𝐻𝐻1 based on your business problem
Step 2: Calculate critical value(s)
For left tailed test: critical value = −𝑡𝑡𝛼𝛼;(𝑛𝑛−1)
For right tailed test: critical value = 𝑡𝑡𝛼𝛼;(𝑛𝑛−1)
For two tailed test: critical values = ±𝑡𝑡𝛼𝛼/2;(𝑛𝑛−1)
Step 3: Calculate test value
̅
𝑥𝑥−𝜇𝜇
𝑡𝑡 = 𝑠𝑠 , where 𝜇𝜇 is the hypothesized mean, 𝑠𝑠 is the sample standard
𝑛𝑛
deviation, 𝑋𝑋� is the sample mean and 𝑛𝑛 is the sample size
Step 4: Make the decision
For left tailed test: reject 𝐻𝐻0 if 𝑡𝑡 < −𝑡𝑡𝛼𝛼;(𝑛𝑛−1)
For right tailed test: reject 𝐻𝐻0 if 𝑡𝑡 > 𝑡𝑡𝛼𝛼;(𝑛𝑛−1)
For two tailed test: reject 𝐻𝐻0 if 𝑡𝑡 < −𝑡𝑡𝛼𝛼/2; 𝑛𝑛−1 or 𝑡𝑡 > +𝑡𝑡𝛼𝛼/2;(𝑛𝑛−1)

CCN2311 Foundations of Data Science Page 48


t-Test for Means - Examples
We will walk through the three types of t-Tests in the
following examples
Example 6 – Z-Test for Mean (Right tailed)
Example 7 – Z-Test for Mean (Left tailed)
Example 8 – Z-Test for Mean (Two tailed)

CCN2311 Foundations of Data Science Page 49


Example 6 – t-Test for Mean (Right
tailed)
A traffic police suspected that the average speed of cars on a
highway was above 100km/hr. After checking the speeds of 15
randomly selected cars on the highway, he found that the sample
mean and sample standard deviation of the speeds of the 15 cars
were 102km/hr and 5km/hr respectively.

Do we have evidence that the average speed of cars on the highway


was above 100km/hr at a level of significance of 0.05?

(We can assume that the speeds of cars on the highway were
normally distributed with unknown mean and standard deviation)

CCN2311 Foundations of Data Science Page 50


Example 6 – t-Test for Mean (Right
tailed)
Useful information: normal population, 𝑛𝑛 = 15, 𝑥𝑥̅ = 102, 𝑠𝑠 = 5 and 𝛼𝛼 = 0.05
Step 1: 𝐻𝐻0 : 𝜇𝜇 = 100 vs 𝐻𝐻1 : 𝜇𝜇 > 100 Right tailed!

Step 2: 𝛼𝛼 = 0.05 and it is a right tailed test, therefore critical value is 𝑡𝑡0.05;(14) =
1.761 t-Distribution with 14 d.f. (i.e. n-1 d.f.)

area = 𝛼𝛼 =0.05

𝑡𝑡𝛼𝛼;(𝑛𝑛−1)

CCN2311 Foundations of Data Science Page 51


Example 6 – t-Test for Mean (Right
tailed)
̅
𝑥𝑥−𝜇𝜇 102−100
Step 3: test value 𝑡𝑡 = = ≈ 1.549
𝑠𝑠/ 𝑛𝑛 (5/ 15)
Note that 𝜇𝜇 is the value specified in 𝐻𝐻0 .
Step 4: Since test value (1.549) is less than the critical value (1.761), the test
value falls into the non-critical region (aka non-rejection region). The
decision is NOT to reject 𝑯𝑯𝟎𝟎 and we do not have evidence to conclude
that that the average speed of cars on the highway is greater than
100km/hr.
t-Distribution with 14 d.f.
Non-critical region critical region
(Non-rejection region) (rejection region)

Critical region is on
the RIGHT hand for
RIGHT tailed test
test critical
value value
(1.549) (1.761)

CCN2311 Foundations of Data Science Page 52


Example 7 – t-Test for Mean (Left tailed)
Suppose average salary of janitors in Hong Kong was about $8,000.
A social worker claimed that the average salary of janitors in Tuen
Mun is less than $8,000. The social worker interviewed a random
sample of 20 janitors in Tuen Mun. The mean and standard
deviation of salaries of janitors in Tuen Mun were $7,900 and $100
respectively.

Are there evidence to conclude the social worker’s claim at a level


of significance of 0.01?

(We can assume that the salaries of janitors in Tuen Mun were
normally distributed with unknown mean and standard deviation)

CCN2311 Foundations of Data Science Page 53


Example 7 – t-Test for Mean (Left tailed)

CCN2311 Foundations of Data Science Page 54


Example 7 – t-Test for Mean (Left tailed)

CCN2311 Foundations of Data Science Page 55


Example 7 – t-Test for Mean (Left tailed)
Useful information: normal population, 𝑛𝑛 = 20, 𝑥𝑥̅ = 7900, 𝑠𝑠 = 100 and 𝛼𝛼 =
0.01
Step 1: 𝐻𝐻0 : 𝜇𝜇 = 8000 vs 𝐻𝐻1 : 𝜇𝜇 < 8000 Left tailed!
Step 2: 𝛼𝛼 = 0.01 and it is a left tailed test, therefore critical value is −𝑡𝑡0.01;(19) =
− 2.539 t-Distribution with 19 d.f. (i.e. n-1 d.f.)

area = 𝛼𝛼 =0.01

−𝑡𝑡𝛼𝛼;(𝑛𝑛−1)

CCN2311 Foundations of Data Science Page 56


Example 7 – t-Test for Mean (Left tailed)
̅
𝑥𝑥−𝜇𝜇 7900−8000
Step 3: test value 𝑡𝑡 = = = −4.472
𝑠𝑠/ 𝑛𝑛 (100/ 20)
Note that 𝜇𝜇 is the value specified in 𝐻𝐻0 .
Step 4: Since test value (-4.472) is less than the critical value (-2.539), test value falls into
the critical region (aka rejection region). The decision is to reject 𝑯𝑯𝟎𝟎 and we do
have evidence that average salary of janitors in Tuen Mun is less than $8,000.
t-Distribution with 19 d.f.
critical region Non-critical region
(rejection region) (Non-rejection region)

Critical region is on
the LEFT hand for
LEFT tailed test

test critical
value value
(-4.472) (-2.539)

CCN2311 Foundations of Data Science Page 57


Example 8 – t-Test for Mean (Two
tailed)
A researcher claimed that the average daily commuting time to
work for workers in Town B was not equal to 1 hour.

The researcher recorded the daily commuting times of 13 randomly


selected workers from Town B. The average daily commuting time
of these 13 workers was 1.05 hours and the sample standard
deviation was 0.2 hour. Can we confirm the researcher’s claim at a
level of significance of 𝛼𝛼 = 0.05?

(We can assume that the daily commuting times of workers in Town
B are normally distributed with an unknown mean and standard
deviation)

CCN2311 Foundations of Data Science Page 58


Example 8 – t-Test for Mean (Two
tailed)
Useful information: normal population, 𝑛𝑛 = 13, 𝑥𝑥̅ = 1.05, 𝑠𝑠 = 0.2 and 𝛼𝛼 = 0.05
Step 1: 𝐻𝐻0 : 𝜇𝜇 = 1 vs 𝐻𝐻1 : 𝜇𝜇 ≠ 1 Two tailed!

Step 2: 𝛼𝛼 = 0.05 and it is a two tailed test, therefore critical values


are ±𝑡𝑡𝛼𝛼/2;(𝑛𝑛−1) = ±𝑡𝑡0.025;(12) = ±2.179
t-Distribution with 12 d.f.

area = 𝛼𝛼/2 =0.025 area = 𝛼𝛼/2 =0.025

−𝑡𝑡𝛼𝛼/2;(𝑛𝑛−1) 𝑡𝑡𝛼𝛼/2;(𝑛𝑛−1)

CCN2311 Foundations of Data Science Page 59


Example 8 – t-Test for Mean (Two
tailed)
̅
𝑥𝑥−𝜇𝜇 1.05−1
Step 3: test value 𝑡𝑡 = = = 0.901
𝑠𝑠/ 𝑛𝑛 (0.2/ 13)
Note that 𝜇𝜇 is the value specified in 𝐻𝐻0 .
Step 4: Since test value (0.901) is between the critical values (±2.179), test value falls into
the non-critical region (aka non-rejection region). The decision is NOT to reject 𝑯𝑯𝟎𝟎
and we do not have evidence that daily commuting time for workers in Town B is
not equal to 1 hour.
t-Distribution with 12 d.f.

critical region Non-critical region critical region


(rejection region) (Non-rejection region) (rejection region)

Critical region is on
both sides for 2
tailed test
critical test critical
value value value
(-2.179) (0.901) (2.179)

CCN2311 Foundations of Data Science Page 60


Hypothesis for Means (Non-Normal)
• It is very common to encounter population with
unknown distribution or non-normal distribution
• If sample size is large 𝑛𝑛 ≥ 30, we can apply CLT and use
Z-Test
• If population variance is unknown, we can replace it
with sample variance when sample size is large 𝑛𝑛 ≥ 30

CCN2311 Foundations of Data Science Page 61


Next Lecture
• We will continue with one sample tests for proportion
and variance

CCN2311 Foundations of Data Science Page 62

You might also like