You are on page 1of 39

ETF1100 Business Statistics

Week 5
Hypothesis Testing Coding on Laptop by Matthew Henry

Charanjit Kaur https://burst.shopify.com/photos/coding-on-laptop?c=software-development


Week 5: Housekeeping

Reminders:
• Mid-semester Test – 1st of September (8am - 11.55 pm)
✓ 15 MCQs to be completed in one hour

• Group formation for Project – finalise by end of week 5 (25th of


August, 11.55 pm)
Week 5: Support provided by the team

1. Mid-Semester Practice Test - available in Week 6 & Mid-semester Test section


on Moodle
2. Seminar for Week 6 - will include a revision session
3. Textbook Questions – we have prepared a set of detailed solutions available
in the respective weekly sections on Moodle.
4. Seminar Quiz Feedback - feedback is provided for each seminar quiz after it is
closed. This allows you to review your performance.
5. Help for Mid-semester Test preparation- Additional consultations made
available for Weeks 5 and 6. Look out for announcement
Week 5: Hypothesis Testing
Learning Outcomes:
• Understanding the conceptual basis of hypothesis testing.
• Outlining steps of a hypothesis test.
• Differentiating between a two-sided and one-sided hypothesis test.
• Understanding Type I and Type II errors in hypothesis testing.
• Application of hypothesis test to proportions.
Hypothesis Test for Evidence-based Decisions
A statistical framework for using data to derive evidence-based
decisions.
• Define business problem and variables relevant to that problem
• Formulate a hypothesis around these variables that are relevant to
business decisions
• Collect representative data and calculate summary statistics
• Conduct hypothesis testing to establish degree of evidence for the
hypotheses
• Based on evidence, make business decisions
Hypothesis Test for Evidence-based Decisions
6

Sample

Sampling
STATISTICS Distribution

DESCRIPTIVE INFERENTIAL

ESTIMATION
HYPOTHESIS TESTS
Point & Interval

Estimating the value of a Testing a claim about the value


population parameter of a population parameter
7
Hypothesis Testing ……..Is a familiar process
An hypothesis test is conducted to decide between two hypotheses: the null H0 and the alternative, H1.

H0: Defendant is not guilty (‘status quo’; default)


H1: Defendant is guilty (experimental/research hypothesis)

Reject H0: GUILTY!


There IS enough evidence against H0 - the defendant is guilty.

Do not reject H0: NOT GUILTY (INNOCENT!)


There IS NOT enough evidence against H0 - the defendant is not guilty.
Defining the hypothesis
General rule:
• There will typically be a benchmark value, let’s call this 𝜇0
• The null hypothesis always involve equality sign
𝐻0 : 𝑀𝑒𝑎𝑛 = 𝜇0
• The alternative hypothesis is what we are really searching evidence for
• It can contain unequal sign 𝐻1 : 𝑀𝑒𝑎𝑛 ≠ 𝜇0
• It can contain a greater than sign 𝐻1 : 𝑀𝑒𝑎𝑛 > 𝜇0
• It can contain a smaller than sign 𝐻1 : 𝑀𝑒𝑎𝑛 < 𝜇0
Defining the hypothesis
Consider the Real Estate data set:
• We wish to establish whether the average house prices in this suburb is
greater than the average price across the metropolitan Melbourne area of
$993k
• Hypothesis (in word): average price in this suburb is greater than $993k
• Statistical hypothesis:
𝑁𝑢𝑙𝑙 𝐻𝑦𝑝𝑜𝑡ℎ𝑒𝑠𝑖𝑠 𝑯𝟎 : 𝑴𝒆𝒂𝒏 𝑷𝒓𝒊𝒄𝒆 = $𝟗𝟗𝟑𝒌
𝐴𝑙𝑡𝑒𝑟𝑛𝑎𝑡𝑖𝑣𝑒 𝐻𝑦𝑝𝑜𝑡ℎ𝑒𝑠𝑖𝑠 𝑯𝟏 : 𝑴𝒆𝒂𝒏 𝑷𝒓𝒊𝒄𝒆 > $𝟗𝟗𝟑𝒌
Sampling Distribution of the Sample Mean
𝑠
Central Limit Theorem: If the sample size 𝑛 is large, then 𝑥ҧ ∼ 𝑁 𝜇,
𝑛

• We use this result in hypothesis testing.


ҧ
𝑥−𝜇
• If we know the population mean 𝜇, a simple rearrangement gives ∼ 𝑁(0,1)
𝑠/ 𝑛

Consider 𝑯𝟎 : 𝝁 = 𝝁𝟎
• 𝝁 is the unknown population mean,
• 𝝁𝟎 is the hypothesised value (a value set at the null hypothesis)

ഥ−𝝁𝟎
𝒙
If the null is true, then ∼ 𝑵(𝟎, 𝟏)
𝒔/ 𝒏
Mechanics of Hypothesis Testing
• If the null is true, then

ഥ − 𝝁𝟎
𝒙
∼ 𝑵(𝟎, 𝟏)
𝒔/ 𝒏

This is the “test statistic” (Calculated Value)


A value derived from the sample data & null hypothesis
Mechanics of Hypothesis Testing
• What we do in hypothesis testing:
1. Formulate the hypotheses: 𝐻0 and 𝐻1

𝑥ҧ − 𝜇0
𝑇𝑒𝑠𝑡 𝑆𝑡𝑎𝑡𝑖𝑠𝑡𝑖𝑐 =
𝑠/ 𝑛
2. Judge whether the 𝑇𝑒𝑠𝑡 𝑆𝑡𝑎𝑡𝑖𝑠𝑡𝑖𝑐 is likely to be from the standard
normal distribution 𝑁(0,1)
3. How do we judge whether the 𝑇𝑒𝑠𝑡 𝑆𝑡𝑎𝑡𝑖𝑠𝑡𝑖𝑐 is likely to be from the
standard normal distribution 𝑁(0,1)?
Mechanics of Hypothesis Testing
How do we judge whether the 𝑇𝑠𝑡𝑎𝑡 is likely to be from the standard normal
distribution 𝑁(0,1)?

Less likely to be N(0,1) Likely to be N(0,1) Less likely to be N(0,1)


Mechanics of Hypothesis Testing
How do we judge whether the 𝑇𝑒𝑠𝑡 𝑆𝑡𝑎𝑡𝑖𝑠𝑡𝑖𝑐 is likely to be from the standard normal
distribution 𝑁(0,1)?

Two-sided tests:
𝐻0 : 𝜇 = 𝜇0
𝐻1 : 𝜇 ≠ 𝜇0

Sign of test statistic does not matter.


If test statistic value is in the tails –
positive or negative – there is
evidence for the alternative
Evidence in favour of 𝑯𝟏 Do not reject 𝑯𝟎 Evidence in favour of 𝑯𝟏
(rejection region – reject (rejection region – reject
the null hypothesis) the null hypothesis)
Mechanics of Hypothesis Testing
• How do we judge whether the 𝑇𝑒𝑠𝑡 𝑆𝑡𝑎𝑡𝑖𝑠𝑡𝑖𝑐 is likely to be from the standard
normal distribution 𝑁(0,1)?

One-sided upper tail tests:


𝐻0 : 𝜇 = 𝜇0
𝐻1 : 𝜇 > 𝜇0

Sign matters.
If the test statistic value falls in the
positive tail – there is evidence for
the alternative
Do not reject 𝑯𝟎 Evidence in favour of 𝑯𝟏
(rejection region – reject
the null hypothesis)
Mechanics of Hypothesis Testing
• How do we judge whether the 𝑇𝑒𝑠𝑡 𝑆𝑡𝑎𝑡𝑖𝑠𝑡𝑖𝑐 is likely to be from the standard
normal distribution 𝑁(0,1)?

One-sided upper tail tests:


𝐻0 : 𝜇 = 𝜇0
𝐻1 : 𝜇 < 𝜇0

Sign matters.
If the test statistic is in the negative
tail – there is evidence for the
alternative
Evidence in favour of 𝑯𝟏
(rejection region – reject Do not reject 𝑯𝟎
the null hypothesis)
Mechanics of Hypothesis Testing: p-value
Judging whether or not the test statistic is outstandingly “far from zero”, in the
direction of the alternative.

It is the probability of getting the test statistic assuming that 𝐻0 is true.

p-value = P(Test statistic |𝑯𝟎 is true)

• If the p-value is small, then the test statistic is far from zero.
(In the direction of the alternative hypothesis.)
• A smaller p-value means that there is stronger evidence in favor of the
alternative hypothesis.
Interpreting The p-value
P-value should be interpreted as the level of “evidence” in favour of the null
hypothesis, when compared against the ALTERNATIVE hypothesis.

A small p-value indicates little evidence in support of the 𝐻0 ; we have reason


to reject 𝐻0 in favour of 𝐻1

A large p-value indicates considerable evidence in support of the 𝐻0 ; we do


not have reason to reject 𝐻0 in favour of 𝐻1 .
Calculating the p-value using Excel
Computing the p-value depends on the definition of the alternative hypothesis.
In the case of the alternative being 𝝁 < 𝝁𝟎 (left-sided test):
p-value = 𝑃(𝑍 < 𝑡𝑠𝑡𝑎𝑡)

In the case of the alternative being 𝝁 > 𝝁𝟎 (right-sided test):


p-value = 𝑃(𝑍 > 𝑡𝑠𝑡𝑎𝑡) =1- 𝑃(𝑍 < 𝑡𝑠𝑡𝑎𝑡)
In the case of the alternative being 𝝁 ≠ 𝝁𝟎 (two-sided test):
p-value = 2 x 𝑃 𝑍 > 𝑡𝑠𝑡𝑎𝑡 |)

In Excel, 𝑃(𝑍 < 𝑡𝑠𝑡𝑎𝑡) =NORM.S.DIST(tstat, TRUE)


Significance Level
How small is a small p-value?
It depends on a tolerance level set up as an analyst. It is called the
significance level, .

Typical significance levels are 10%, 5% or 1%.

This will prescribe the chance of making potential error of rejecting the 𝐻0 when
it is true in our conclusion.

Low tolerance means there is a lower chance that the correct 𝐻0 will be
rejected.
Significance level for Two- and One Sided Test
The tolerance level is determined such that the significance level of  is spread
over both tails in a two-sided test, whereas it is in one tail in the one-sided
case.

The  for two-sided test The  for right-sided test


Reject the 𝐻0 when p-value < 
If p-value < 

→ we still can tolerate the potential error and conclude that the p-value is small so, we reject
the 𝐻0 .

∴ There is evidence to support the alternative hypothesis.

If p-value > 

→ we no longer can tolerate the potential error as it is bigger than the tolerance level
allowed, . We conclude that the p-value is large so, we fail to reject the 𝐻0 .

∴ There is not enough evidence to support the alternative hypothesis.

Notice: our final conclusion is about the alternative hypothesis!


Steps in Hypothesis Test

1 2 3 4
Formulate Decide Calculate Apply
𝐻0 & 𝐻1 on  the p-value decision rule:
reject 𝐻0
if p-value < 
OR retain it if
p-value > 
Hypothesis Test for the Mean – Real Estate Data
Consider the Real Estate data set:
• We wish to establish whether the average house prices in this suburb is
greater than the average price across the metropolitan Melbourne area of
$993k
• Statistical hypothesis:
𝑁𝑢𝑙𝑙 𝐻𝑦𝑝𝑜𝑡ℎ𝑒𝑠𝑖𝑠 𝑯𝟎 : μ = $𝟗𝟗𝟑𝒌
𝐴𝑙𝑡𝑒𝑟𝑛𝑎𝑡𝑖𝑣𝑒 𝐻𝑦𝑝𝑜𝑡ℎ𝑒𝑠𝑖𝑠 𝑯𝟏 : μ > $𝟗𝟗𝟑𝒌
Hypothesis Test for the Mean – Real Estate Data
• Statistical hypothesis:
𝑁𝑢𝑙𝑙 𝐻𝑦𝑝𝑜𝑡ℎ𝑒𝑠𝑖𝑠 𝑯𝟎 : μ = $𝟗𝟗𝟑𝒌
𝐴𝑙𝑡𝑒𝑟𝑛𝑎𝑡𝑖𝑣𝑒 𝐻𝑦𝑝𝑜𝑡ℎ𝑒𝑠𝑖𝑠 𝑯𝟏 : μ > $𝟗𝟗𝟑𝒌

mu_0 993
From descriptive statistics xbar 1215.462006
SE(xbar) 23.09593056
ഥ−𝝁𝟎
𝒙 ഥ−𝝁𝟎
𝒙
𝒕 − 𝒔𝒕𝒂𝒕 = = ഥ
t-stat 9.632086722
𝒔/ 𝒏 𝑺𝑬 𝒙
p-value (upper-tail) 0.0000
=1-NORM.S.DIST(9.632087,TRUE)

Remembering that for upper tail test: p-value = Pr(𝑍 > 𝑡𝑠𝑡𝑎𝑡 )
Hypothesis Test for the Mean – Real Estate Data
• Statistical hypothesis:
𝑁𝑢𝑙𝑙 𝐻𝑦𝑝𝑜𝑡ℎ𝑒𝑠𝑖𝑠 𝑯𝟎 : μ = $𝟗𝟗𝟑𝒌
𝐴𝑙𝑡𝑒𝑟𝑛𝑎𝑡𝑖𝑣𝑒 𝐻𝑦𝑝𝑜𝑡ℎ𝑒𝑠𝑖𝑠 𝑯𝟏 : μ > $𝟗𝟗𝟑𝒌
Conclusion:
Let us use the significance level of 𝛼 = 5%. mu_0 993
xbar 1215.462006
Since p-value is < 𝛼, we reject the null SE(xbar) 23.09593056
hypothesis in favour of the alternative. t-stat 9.632086722
p-value (upper-tail) 0.0000
There is statistical evidence to support the
hypothesis that the mean price of this suburb is
greater than $993k.
Hypothesis Test for the Mean – Real Estate Data
Still looking at the average price of houses in this Melbourne suburb. Conduct
a hypothesis test to verify that the average price is not equal to the
Melbourne metropolitan median price of $993k.

How would you define the alternative hypothesis, and


what is the p-value for this test?
Errors in Hypothesis Testing: Type I and II errors
Since we rely on data samples to conduct hypothesis tests, there is a potential
of errors.
Possible scenarios:
The true ‘state of the world’

𝑯𝟎 is TRUE 𝑯𝟎 is FALSE
Do not reject 𝑯𝟎 CORRECT TYPE II ERROR
DECISION! (β)
Reject 𝑯𝟎 TYPE I ERROR CORRECT
(α) DECISION!
Errors in Hypothesis Testing

• Type I Error is directly related to the significance level:


Pr 𝑇𝑦𝑝𝑒 𝐼 𝐸𝑟𝑟𝑜𝑟 = 𝛼

• So, we can control the chance of this error by setting small 𝛼

• Small 𝛼 → we need more convincing evidence against 𝐻0 to reject it

The smaller we make α, the bigger β becomes.


Trade-Off between Errors
However, there is a trade-off
Reducing P(Type I error) will increase P(Type II error)
This inverse relationship must be considered when choosing the significance level α.

Reducing the P(type I error) by reducing 𝛼


→ harder to reject 𝐻0 as a much lower p-value is required
→ increasing the chance of not rejecting 𝐻0
→ increasing the P(type II error) when 𝐻0 is actually false.
Recommendations: 𝛼 = 5%; or 𝛼 = 1% for conservative cases.
Note: for all tests and exams, we will specify what 𝛼 you should use to answer the questions.
Errors in Hypothesis Testing
Concept check:

For the testing of average property price, if we reduce the significance


level from 5% to 1%, what would happen to the potential errors that we
can make from our conclusions?
Application of Hypothesis Test to Proportions

Recall from last week


# 𝑜𝑓 𝑠𝑢𝑐𝑐𝑒𝑠𝑠𝑒𝑠
• Proportions estimated by 𝑝 =
𝑛

• If the sample size 𝑛 is large,


𝑝 ∼ 𝑁 𝜋, 𝑆𝐸 𝑝

𝑝 1−𝑝
• Here, 𝜋 =unknown population proportion and 𝑆𝐸 𝑝 =
𝑛

• Hypothesis testing concepts can be applied to proportions too


Application of Hypothesis Test to Proportions

Test statistic
• If the sample size 𝑛 is large,
𝑝 ∼ 𝑁 𝜋, 𝑆𝐸 𝑝
𝑝 1−𝑝
• Here, 𝜋 =unknown population proportion and 𝑆𝐸 𝑝 =
𝑛
𝑝 − 𝜋0
𝑇𝑒𝑠𝑡 𝑠𝑡𝑎𝑡𝑖𝑠𝑡𝑖𝑐 =
SE(𝑝)

• If the null hypothesis is true, this 𝒕𝒆𝒔𝒕 𝒔𝒕𝒂𝒕𝒊𝒔𝒕𝒊𝒄 ∼ 𝑵(𝟎, 𝟏)


Marketing Survey
More than half of our potential market have tried our frozen food product

Let’s use hypothesis testing to validate/invalidate this claim

Contingency table from Week 3 Tutorial


Count of Person ID Gender
Have tried Female Male Grand Total
No 0.21262 0.20911 0.42173 𝑝
Yes 0.25234 0.32593 0.57827
Grand Total 0.46495 0.53505 1.00000
N= 856
Hypothesis testing – Marketing Survey
What are our statistical hypotheses?
𝐻0 : 𝜋 = 50%
𝐻1 : 𝜋 > 50%

Hypothesis testing
At 𝛼 = 5%, reject 𝐻0 in favour of 𝐻1 .
pi_0 0.5 There is statistical evidence to suggest that
t-stat 4.637 more than half of potential market have
p-value (upper tail) 0.000 tried the frozen food product.

Note: Result is consistent with confidence interval. However, hypothesis testing gives
you more concrete statistical evidence, rather than range.
Hypothesis Testing – SPECIAL CASE
• In small sample size and normal population,
ഥ−𝝁𝟎
𝒙
T𝑒𝑠𝑡 𝑠𝑡𝑎𝑡𝑖𝑠𝑡𝑖𝑐 = ∼ 𝑺𝒕𝒖𝒅𝒆𝒏𝒕 − 𝒕(𝒅𝒇 = 𝒏 − 𝟏)
𝒔/ 𝒏

• → Use the “=T.DIST(test statistic,df)” function to calculate the p-values


• All decision rules remain the same as before
Hypothesis Testing Poll Questions
For the testing of average property price, if we reduce the significance level from 5% to 1%, what
would happen to the potential errors that we can make from our conclusions?
A) Both the probabilities of a Type I and II errors will increase
B) Probability of a Type 1 error increases and the probability of a Type II error decreases
C) Probability of a Type I error decreases and the probability of a Type II error increases
D) Both the probabilities of a Type I and II errors will decrease

ANSWER: C

Conduct a hypothesis test to verify that the average house price is not equal to the Melbourne
metropolitan median price of $993k. What is the p-value for this test?
A) 2*P(Z>9.632086) = 0.0000
B) P(Z>9.632086) = 0.0000
C) P(Z<9.632086) = 0.0000

ANSWER: A
Hypothesis Testing Poll Questions
For the testing of average property price, if we reduce the significance level from 5% to 1%,
what would happen to the potential errors that we can make from our conclusions?

A) Both the probabilities of a Type I and II errors will increase


B) Probability of a Type 1 error increases and the probability of a Type II error decreases
C) Probability of a Type I error decreases and the probability of a Type II error increases
D) Both the probabilities of a Type I and II errors will decrease

ANSWER: C
Hypothesis Testing
❖ Hypothesis testing summary
▪ Hypotheses (null and alternative statements)
▪ Significance level (α): Tolerance level of making the potential error of rejecting
the correct 𝐻0 .
▪ p-value: a measure of evidence of the 𝐻0
▪ Small p-value means little evidence in support of 𝐻0 , reject 𝐻0 in favour of 𝐻1
❖ Error in hypothesis testing
▪ Type I error
▪ Type II error
▪ Increasing P(Type I error) will reduce P(Type II error) and vice versa.

You might also like