Statistical inference: Hypothesis Testing and t-tests

24
Statistical Inference Week 3: Hypothesis Testing and t-tests

Transcript of Statistical inference: Hypothesis Testing and t-tests

Statistical InferenceWeek 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

Thank you for your attention!Eugene Yan