BE186
BE186
BE18
Chapter 9: Hypothesis Testing
Håkan Lane
Why are confidence intervals not enough
2
What is a hypothesis?
3
Null and alternative
4
Example
• A medical trial is conducted to test whether or not a new medicine reduces
cholesterol by 25%. State the null and alternative hypotheses.
5
Example 1
6
Three situations
We want to test if it takes fewer than 45 minutes to teach a lesson plan. State
the null and alternative hypotheses.
Fill in the correct symbol ( =, ≠, ≥, <, ≤, >) for the null and alternative
hypotheses.
a. H0: μ >= 45
b. Ha: μ < 45
7
Four possibilities
• Remember: We make decision on population based on sample
Sample Population
25 Dalmatians
Mu=40, All Dalmatians > 35?
sigma=6
8
Four possibilities
• We support H0, and H0 is true: Correct
• We support HA, but H0 is true: Type I Error
• We support HA, and HA is true: Correct
• We support H0, and HA is true: Type II Error
H0 OK Type II
HA Type I OK
9
Implications for dalmatians
10
Example
• Question: Is rock climbing equipment from X company unsafe?
• H0? Ha?
• H0: safe
• HA: unsafe
11
Example
• H0: innocent
• HA: guilty
12
Example
13
Distributions
• Mean:
• Normal distribution
• Proportion:
• Independent trials
• Each has same probability p
14
Proof beyond reasonable doubt
• You have reason to believe that a coin flip is rigged in favour of heads,
but how to prove?
• Start flipping, how many times, after how many heads would you be
convinced?
• Write in chat
15
How to check
16
Significance alpha
• Standard = 0.05 = 5%
• If chance of results less than 5%, it was caused by effect and not by
chance
• Can never be 100 % certain
• How many heads would the statistician require?
• 5
17
Poll
18
Principle of proof
• Question: “If H0 was true, what is the chance that all this happened
just by chance”?
• Example:
• H0 : x <= 15 cm, HA : x > 15 cm
• Sample of 10 gives x* = 17 cm, known σ = 2 cm
• What is the probability to get this is real mean was 15 cm?
19
Consider the CLT
20
The p value
21
Different types of tails I: Left tailed
22
Tails 2: Double tailed
23
Tail type 3: Right tailed
24
Example II
25
One sample for mean summary
26
Example
27
One sample test for proportions
• Remember that some questions are only yes/no.
• Example:
• Proportion of voters for party
• Percentage of people with cancer
• Proportion of crops of a certain type
28
One sample test for proportion in R
29
Example
30
Comparing two groups
• Population I Population II
Mean Mean
μ1 μ2
32
T test two groups
Sample 1 Sample 2
Population 1 Population 2
33
Compare the samples
• Standard error:
• Degrees of freedom: n1 + n2 - 2
34
P value from t distribution
• Calculate se =
35
In R
install.packages(„BSDA“)
library(BSDA)
tsum.test
tsum.test( mean.x, s.x = NULL, n.x = NULL, mean.y = NULL, s.y = NULL, n.y = NULL, alternative = "two.sided", mu = 0,
var.equal = FALSE, conf.level = 0.95 )
36
Example
• Two samples are shown in Table 10.2. Both have normal distributions.
The means for the two populations are thought to be the same. Is
there a difference in the means? Test at the 5% level of significance.
• Sample Size Sample Mean Sample Standard Deviation
• Population A 25 5 1
• Population B 16 4.7 1.2
37
Example 2
38
With actual data
• Alternative:
• ”less” when HA is <
• ”two-sided” when HA !=
• ”greater” when HA is >
39
Example
40
Conclusion
Population 1 Population 2
41
T test for proportions
• Remember that some questions are only yes/no.
• Examples:
• Smoking in different countries
42
Hypothesis test for proportions
43
Procedure
• SE=
44
In R
45
Example 1
46
Repeated Measures Basics
47
Repeated Measures test procedure
48
In R
• Exam1
• Exam2
• t.test(Exam1,Exam2,paired=TRUE)
49
Example:
TRY IT 10.11
A study was conducted to investigate how effective a new diet was in
lowering cholesterol.
Results for the randomly selected subjects are shown in the table.
The differences have a normal distribution.
Are the subjects’ cholesterol levels lower on average after the diet?
Test at the 5% level.
Subject A B C D E F G H I
Before 209 210 205 198 216 217 238 240 222
After 199 207 189 209 217 202 211 223 201
50
Poll
51