Statistical Inference Week 3: Hypothesis Testing and t-tests
Central Limit Theorem What is the mean height (π) of all primary school children in Singapore?
Sample = Anderson Primary
Population = All primary school children in SG
Sample = DamaiPrimary
Sample = Red Swastika Primary
Sample = Zhenghua Primary
ππ¨ππ πππππ π·ππππππ = Mean height of
100 children from Anderson Primary
ππ«ππππ π·ππππππ = Mean height of 100
children from Damai Primary
ππΉππ πΊπππππππ = Mean height of 100 children from Red Swastika Primary
πππππππππ π·ππππππ= Mean height of 100
children from Zhenghua Primary
π·ππ π‘ππππ’π‘πππ ππ ππππ βπππβπ‘ ~ π(ππππ = π, π π‘ππππππ πππππ =π
100)
β¦
β¦
β¦
From the sampling distribution: Mean( π₯) β π SD( π₯) < π
β As sample size increases, SD decreases
Central Limit Theorem (CLT)
The distribution of sample statistics (e.g., mean) is approximately normal, regardless of the underlying distribution, with mean =
π and variance = π2
π
π ~ π΅(ππππ = π, πππππ πππ πππππ =π
π)
Further experimentation: http://bitly.com/clt_mean
Distribution is normal
Sample mean = population mean
Sample sd = population sd divided by square root
of sample size
Applet source: Mine Γetinkaya-Rundel, Duke University
Conditions for CLT
Independence: Sampled observations must be independent:βRandom sample/assignment
β If sampling without replacement, n < 10% of population
Sample Size/Skew:βPopulation should be normal
β If not, sample size should be large (rule of thumb: n > 30)
Confidence Interval
An interval estimate of a population parameterβComputed as sample mean +/- a
margin of error
π₯ Β± π§ Γ ππΈ,where SE =π
π
β95% confidence interval would contain 95% of all values and would be π₯ Β± 2ππΈ or π₯ Β± 1.96 Γ
π
π
πͺπ³π»: π ~ π΅(ππππ = π, πππππ πππ πππππ =π
π)
Confidence Interval
You have taken a random sample of 100 primary school children in Singapore. Their heights had mean = 150cm and sd = 10cm. Estimate the true average height of primary school children based on this sample using a 95% confidence interval.
We are 95% confident that primary school children mean height is between 148.04cm and 151.96cm
Confidence Interval: π₯ Β± π§ Γ ππΈπ = 100 π₯ = 150π π = 10
ππΈ =π π
π=
10
100= 1
π₯ Β± π§ Γ ππΈ = 150 Β± 1.96 Γ 1= 150 Β± 1.96= (148.04, 151.96)
Required sample size for margin of error
Given a target margin of error and confidence level, and information on the standard deviation of sample (or population), we can work backwards to determine the required sample size.
Previous measurements of primary school children heights show sd = 15cm. What should be the sample size in order to get a 95% confidence interval with a margin of error less than or equal 1cm?
Margin of error: β€ 1ππConfidence level: 95%π§ = 1.96π π = 15
ππΈ = π§ Γ ππΈ
1 = 1.96 Γ15
π
π = (1.96 Γ 15
1)2
π = (29.4)2 = 864.36Thus, we need a sample size of at least 865 primary school children
Hypothesis Testing
Null hypothesis π»0
βThe status quo that is assumed to be true
Alternative hypothesis (π»π)βAn alternative claim under consideration that will require statistical
evidence to accept, and thus, reject the null hypothesis
We will consider π»0 to be true and accept it unless the evidence in favour of π»π is so strong that we reject π»0 in favour of π»π.
Hypothesis Testing
Earlier, we found the sample of 100 primary school children had mean height = 150cm and sd = 10cm. Based on this statistic, does the data support the hypothesis that primary school children on average are shorter than 151cm?
π»0: ΞΌ = 151 #primary school students have mean height = 151
π»π: π < 151 #primary school students have mean height < 151
P-value
Probability of obtaining the observed result or results that are more βextremeβ, given that the null hypothesis is trueβP(observed or more extreme outcome | π»0 is true)
β If the p-value is low (i.e., lower than the significance level (πΌ), usually 5%), then we say that it is very unlikely to observe the data if the null hypothesis was true, and reject π»0
β If the p-value is high (i.e., higher than πΌ), we say that it is likely to observe the data even if the null hypothesis was true, and thus do not reject π»0
Hypothesis Testing and P-value
Recall that the sample of 100 primary school children had mean height = 150cm and sd = 10cm. Also take sig. level = 0.05
π₯ = 150cm; sd = 10cm; SE =10
100= 1 #what we know from the sample
π ~π(π = 151, ππΈ = 1) #null hypothesis of the population
Test Statistic:
π =150 β 151
1= β1
P-value: π π < β1 = 1 β 0.8413= 0.1587
Since p-value is higher than 0.05, we do not reject π»0
π = 151150
0.1587
Hypothesis Testing and P-value
Interpreting p-valueβ If in fact, primary school children have mean height of 151cm, there is a
15.9% chance that a random sample of 100 children would yield a sample mean of 150cm or lower
βThis is a pretty high probability
βThus, the sample mean of 150 could have
likely occurred by chance
Two-sided Hypothesis Testing
What is the probability that the children have mean height different from 151cm?
π»0: ΞΌ = 151 #primary school students have mean height = 151
π»π: π β 151 #primary school students have mean height β 151
P-value: π π < β1 + π π > 1= 2 Γ 1 β 0.8413= 0.3174
π = 151150
0.1587 0.1587
152
Hypothesis Testing and Confidence Intervals
If the confidence interval contains the null value, donβt reject π»0. If the confidence interval does not contain the null value, reject π»0.βPreviously, we found the 95% confidence interval for heights of primary
school children to be (148, 152). Given that our null hypothesis(π»0 =151cm) falls within this 95% CI, we do not reject it.
A two-sided hypothesis with significance level πΌ is equivalent to a confidence interval with πΆπΏ = 1 β πΌ
A one-sided hypothesis with a significance level πΌ is equivalent to a confidence interval with πΆπΏ = 1 β 2πΌ
148 cm 152 cm
95% confident that the average height is between 148 and 152 cm
Decision Errors
Which error is worse to commit (in a research/business context)?βType II: Declaring the defendant innocent when they are actually guilty
βType I: Declaring the defendant guilty when they are actually innocent
βBetter that ten guilty persons escape than that one innocent sufferβ
- William Blackstone
Fail to reject π»0 Reject π»0
π»0 is True Type I error
π»0 is False Type II error
Type I Error rate
We reject π»0 when the p-value is less than 0.05 (πΌ=0.05)β I.e., Should π»0 actually be true, we do not want to incorrectly reject it
more than 5% of the time
βThus, using a 0.05 significance level is equivalent to having a 5% chance of making a Type I error
Choosing significance levelsβ If Type I Error is costly, we choose a lower significance level (e.g., 0.01)
β E.g., spam filtering
β If Type II Error is costly, we choose a higher significance level (e.g., 0.10)β E.g., airport baggage screening
Fail to reject π»0 Reject π»0
π»0 is True Type I error (πΌ)
π»0 is False Type II error (π½)
Studentβs t Distribution
According to CLT, the distribution of sample statistics is approximately normal, if: βPopulation is normal
βSample size is large (n > 30)
If so, we can use the population sd (π) to compute a z-score
However, sample sizes are sometimes small and we often do not know the standard deviation of the population (π)βThus, the normal distribution may not be appropriate
Thus, we rely on the t distribution
Shape of the t distribution
Bell shaped but thicker tails than the normalβThus, observations are more likely to fall beyond 2sd from the mean
βThe thicker tails are helpful in adjusting for the less reliable data on the standard deviation (when n is small and/or π is unknown)
Shape of the t distribution
Has one parameter, degrees of freedom (df), which determines the thickness of the tailsβdf refers to the number of independent observations in data set
βNumber of independent observations = sample size minus 1
βE.g., in a sample size of 8, there are (8-1) degrees of freedom
What happens to the shape of the t distribution when df increases?β It approaches the normal distribution
When to use the t distribution
In general, we use the t distribution when:βN is small (n < 30) and/or;
βπ is unknown
However, nowadays, our sample sizes are usually above 30βThus, why bother with the t distribution?
βBecause 95% of the world prefers the t distribution to the normal and youβll definitely encounter it eventually
β If youβre unsure, use the t distribution since it approximates to the normal distribution with large sample sizes
Independent and Dependent t-tests
When to use independent and dependent t-tests?βDependent: when evaluating the effect between two related samples
β You feed a group of 100 people fast food everyday
β Did they gain weight after 30 days?
β Independent: when evaluating the effect between two independent samplesβ You feed 50 males and 50 females fast food everyday
β Did males or females gain more weight after 30 days?
You conduct a study with two groups and have them exercise three times a day for 30 days (group A = crossfit, group B = yoga).βHow would you test the difference between crossfit and yoga participants?
βHow would you test the difference in weight between day 0 and day 30 for yoga participants?
Effect Size
When samples become large enough, you often get significant resultsβHowever, is it practically significant?
Effect size is a simple way to quantify difference between two groupsβEmphasizes the size of the difference (without effect of sample size)
βCohenβs d is one of the most common ways to measure effect size
Effect size:
Proper calculation for ππ·ππππππ:
Simple calculation for ππ·ππππππ:
Time for practice
In this lab session we will cover:β Independent t-tests
βDependent (paired) t-tests
βEffect size (Cohenβs d)
GitHub repository: https://github.com/eugeneyan/Statistical-Inference