Transcript H 0 - LICH

SUMMARY
Hypothesis testing
Self-engagement assesment
๐œ‡ = 7.8
๐œŽ = 0.76
Null hypothesis
song
Null hypothesis: I assume
that populations without
and with song are same.
At the beginning of our
calculations, we
assume the null
hypothesis is true.
no song
Hypothesis testing song
โ€ข population ๐œ‡ = 7.8, ๐œŽ = 0.76
โ€ข sample ๐‘› = 30, ๐‘ฅ = 8.2
๐‘=
Because of such a low probability,
we interpret 8.2 as a significant
increase over 7.8 caused by
undeniable pedagogical qualities
of the 'Hypothesis testing song'.
8.2 โˆ’ 7.8
= 2.85
0.76
30
corresponding probability is 0.0022
7.8 8.2
Four steps of hypothesis testing
1. Formulate the null and the alternative (this includes
one- or two-directional test) hypothesis.
2. Select the significance level ฮฑ โ€“ a criterion upon which
we decide that the claim being tested is true or not.
--- COLLECT DATA --3. Compute the p-value. The p-value is the probability that
the data would be at least as extreme as those
observed, if the null hypothesis were true.
4. Compare the p-value to the ฮฑ-level. If p โ‰ค ฮฑ, the
observed effect is statistically significant, the null is
rejected, and the alternative hypothesis is valid.
One-tailed and two-tailed
one-tailed (directional) test
two-tailed (non-directional) test
Z-critical value,
what is it?
NEW STUFF
Decision errors
โ€ข Hypothesis testing is prone to misinterpretations.
โ€ข It's possible that students selected for the musical lesson
were already more engaged.
โ€ข And we wrongly attributed high engagement score to the
song.
โ€ข Of course, it's unlikely to just simply select a sample with
the mean engagement of 8.2. The probability of doing so
is 0.0022, pretty low. Thus we concluded it is unlikely.
โ€ข But it's still possible to have randomly obtained a sample
with such a mean mean.
Four possible things can happen
Decision
State of
the world
Reject H0
Retain H0
H0 true
1
3
H0 false
2
4
In which cases we made a wrong decision?
Four possible things can happen
Decision
Reject H0
State of
the world
H0 true
H0 false
Retain H0
1
4
In which cases we made a wrong decision?
Four possible things can happen
Decision
Reject H0
State of
the world
H0 true
H0 false
Retain H0
Type I error
Type II error
Type I error
โ€ข When there really is no difference between the
populations, random sampling can lead to a difference
large enough to be statistically significant.
โ€ข You reject the null, but you shouldn't.
โ€ข False positive โ€“ the person doesn't have the disease, but
the test says it does
Type II error
โ€ข When there really is a difference between the populations,
random sampling can lead to a difference small enough to
be not statistically significant.
โ€ข You do not reject the null, but you should.
โ€ข False negative - the person has the disease but the test
doesn't pick it up
โ€ข Type I and II errors are theoretical concepts. When you
analyze your data, you don't know if the populations are
identical. You only know data in your particular samples.
You will never know whether you made one of these
errors.
The trade-off
โ€ข If you set ฮฑ level to a very low value, you will make few
Type I/Type II errors.
โ€ข But by reducing ฮฑ level you also increase the chance of
Type II error.
Clinical trial for a novel drug
โ€ข Drug that should treat a disease for which there exists no
โ€ข
โ€ข
โ€ข
โ€ข
โ€ข
โ€ข
therapy
If the result is statistically significant, drug will me
marketed.
If the result is not statistically significant, work on the drug
will cease.
Type I error: treat future patients with ineffective drug
Type II error: cancel the development of a functional drug
for a condition that is currently not treatable.
Which error is worse?
I would say Type II error. To reduce its risk, it makes
sense to set ฮฑ = 0.10 or even higher.
Harvey Motulsky, Intuitive Biostatistics
Clinical trial for a me-too drug
โ€ข Drug that should treat a disease for which there already
โ€ข
โ€ข
โ€ข
โ€ข
โ€ข
exists another therapy
Again, if the result is statistically significant, drug will me
marketed.
Again, if the result is not statistically significant, work on
the drug will cease.
Type I error: treat future patients with ineffective drug
Type II error: cancel the development of a functional drug
for a condition that can be treated adequately with
existing drugs.
Thinking scientifically (not commercially) I would minimize
the risk of Type I error (set ฮฑ to a very low value).
Harvey Motulsky, Intuitive Biostatistics
Engagement example, n = 30
H0 : ๐œ‡ = ๐œ‡๐‘†๐‘œ๐‘›๐‘”
HA : ๐œ‡ โ‰  ๐œ‡๐‘†๐‘œ๐‘›๐‘”
๐œ‡ = 7.8
๐œŽ = 0.76
๐‘› = 30
๐‘ฅ = 8.06
๐œ‡๐‘†๐‘œ๐‘›๐‘” = 7.91
Z = 1.87
Z = 0.79
๐›ผ = 0.05
two-tailed test
๐œ‡=0
www.udacity.com โ€“ Statistics
Engagement example, n = 30
Which of these four quadrants represent the result
of our hypothesis test?
Decision
Reject H0
State of
the world
Retain H0
H0 true
H0 false
www.udacity.com โ€“ Statistics
Engagement example, n = 30
Which of these four quadrants represent the result
of our hypothesis test?
Decision
Reject H0
State of
the world
H0 true
H0 false
Retain H0
X
Engagement example, n = 50
H0 : ๐œ‡ = ๐œ‡๐‘†๐‘œ๐‘›๐‘”
HA :๐œ‡ โ‰  ๐œ‡๐‘†๐‘œ๐‘›๐‘”
๐œ‡ = 7.8
๐œŽ = 0.76
๐’ = ๐Ÿ“๐ŸŽ
๐‘ฅ = 8.06
๐œ‡๐‘†๐‘œ๐‘›๐‘” = 7.91
Z = 2.42
Z = 1.02
๐›ผ = 0.05
two-tailed test
๐œ‡=0
www.udacity.com โ€“ Statistics
Engagement example, n = 50
Which of these four quadrants represent the result
of our hypothesis test?
Decision
Reject H0
State of
the world
Retain H0
H0 true
H0 false
www.udacity.com โ€“ Statistics
Engagement example, n = 50
Which of these four quadrants represent the result
of our hypothesis test?
Decision
Reject H0
State of
the world
H0 true
Retain H0
X
H0 false
www.udacity.com โ€“ Statistics
population of students that did
not attend the musical lesson
parameters are known
๐œ‡0
๐œŽ0
population of students that did
attend the musical lesson
unknown
sample
๐œ‡
๐œŽ
statistic
is known
๐‘ฅ
Test statistic
test statistic
๐‘ฅ โˆ’ ๐œ‡0
๐‘=๐œŽ
0
๐‘›
Z-test
We use Z-test if we know the population
mean ๐œ‡0 and the population s.d. ๐œŽ0 .
New situation
โ€ข An average engagement score in the population of 100
students is 7.5.
โ€ข A sample of 50 students was exposed to the musical
lesson. Their engagement score became 7.72 with the
s.d. of 0.6.
โ€ข DECISION: Does a musical performance lead to the
change in the students' engagement? Answer YES/NO.
โ€ข Setup a hypothesis test, please.
Hypothesis test
โ€ข H0: ๐œ‡0 = ๐œ‡
โ€ข H1: ๐œ‡0 โ‰  ๐œ‡
โ€ข In this case doing two-sided test is the only way to test the null.
You compare the sample mean of 7.72 with the population mean of
7.5. It seems that sample mean is larger than the population mean
(7.72 > 7.5), but the sample s.d. is 0.6. You can't setup the onetailed test as you can't guess the correct direction of the
relationship. Actually, you could very easily miss the correct
direction.
โ€ข ๐›ผ = 0.05
Formulate the test statistic
๐‘ฅ โˆ’ ๐œ‡0
๐‘=๐œŽ
0
๐‘›
population of students that did
not attend the musical lesson
๐œ‡0 known
๐œŽ0 unknown
but this is unknown!
โ€ข Instead of ๐œŽ0 we only know the sample s.d.
โ€ข We can use it as the point estimate of population
s.d.
โ€ข However, this will estimate s.d. for the population
exposed to the musical lesson, ๐œŽ0 in the above
formula is for "unperturbed" population.
โ€ข In this case, it is common to make an assumption
that both populations have the same standard
deviation.
population of students that did
attend the musical lesson
unknown
sample
๐œ‡
๐œŽ
๐‘ฅ
๐‘ 
t-statistic
๐‘ฅ โˆ’ ๐œ‡0
๐‘ก= ๐‘ 
๐‘›
one sample t-test
jednovýbฤ›rový t-test
Choose a correct alternative in the following statements:
1. The larger/smaller the value of ๐‘ฅ, the strongest the
evidence that ๐œ‡ > ๐œ‡0 .
2. The larger/smaller the value of ๐‘ฅ, the strongest the
evidence that ๐œ‡ < ๐œ‡0 .
3. The further the value ๐‘ฅ from ๐œ‡0 in either direction, the
stronger/weaker evidence that ๐œ‡ โ‰  ๐œ‡0 .
t-distribution
One-sample t-test
๐‘ฅ โˆ’ ๐œ‡0
๐‘ก= ๐‘ 
๐‘›
๐ป0 : ๐œ‡ = ๐œ‡0
๐ป๐ด : ๐œ‡ < ๐œ‡0
๐œ‡ > ๐œ‡0
๐œ‡ โ‰  ๐œ‡0
๐›ผ level
Quiz
๐‘ฅ โˆ’ ๐œ‡0
๐‘ก= ๐‘ 
๐‘›
โ€ข What will increase the t-statistic? Check all that apply.
1. A larger difference between ๐‘ฅ and ๐œ‡0 .
2. Larger ๐‘ .
3. Larger ๐‘›.
4. Larger standard error.
Z-test vs. t-test
โ€ข Use Z-test if
โ€ข you know the standard deviation of the population.
โ€ข If you know the sample ๐‘  AND you have large sample size
(traditionally over 30). In addition, you assume that the population
standard deviation is the same as the sample standard deviation.
โ€ข Use t-test if
โ€ข you don't know the population standard deviation (you know only
sample standard deviation ๐‘ ) and have a relatively small sample
size.
โ€ข Tip: If you know only the sample standard deviation,
always use t-test.
โ€ข For two sided test and ๐›ผ = 0.05, what are the critical
values at Z- and t-distributions?
Typical example of one-sample t-test
โ€ข You have to prepare 20 tubes with 30% solution od NaCl.
When you're finished, you measure the strength of 20
solutions. The mean strength is 31.5%, with the s.d. of
1.15%.
โ€ข Decide if you have 30% solution or not?
โ€ข ๐œ‡0 = 30%
โ€ข ๐ป0 : ๐œ‡ = 30%, ๐ป1 : ๐œ‡ โ‰  30%
โ€ข You use t-test in such a situation.
โ€ข You could use Z-test if you have a large sample (e.g., you
prepared 100 tubes), but generally it is always correct to
use t-test.
Dependent t-test for paired samples
โ€ข Two samples are dependent when the same subject
takes the test twice.
โ€ข paired t-test (párový t-test)
โ€ข This is a two-sample test, as we work with two samples.
โ€ข Examples of such situations:
โ€ข Each subject is assigned to two different conditions (e.g., use
QWERTZ keyboard and AZERTY keyboard and compare the error
rate).
โ€ข Pre-test โ€ฆ post-test.
โ€ข Growth over time.
Example
โ€ข 25 students attended a normal lesson. Their mean
engagement is ๐‘ฅ๐‘ = 5.08.
โ€ข The same 25 students then heard the โ€žHypotheses testing
songโ€œ. Their mean engagement score is ๐‘ฅ๐‘† = 7.80.
student 1
student 2
โ‹ฎ
student n
๐’™๐’Š ๐’š๐’Š ๐‘ซ๐’Š
๐‘ฅ1 ๐‘ฆ1 ๐ท1
๐‘ฅ2 ๐‘ฆ2 ๐ท2
โ‹ฎ โ‹ฎ โ‹ฎ
๐‘ฅ๐‘› ๐‘ฆ๐‘› ๐ท๐‘›
song
no song
๐‘ฅ๐‘– โˆ’ ๐‘ฆ๐‘–
Do the hypothesis test
โ€ข Now we follow the same procedure as for the one-sample
t-test, except that we use values of differences ๐ท.
โ€ข What will be the null? ๐‘› = 25, ๐‘ฅ๐‘ = 5.08, ๐‘ฅ๐‘† = 7.8
โ€ข ๐ป0 โˆถ ๐œ‡๐‘ = ๐œ‡๐‘†
โ€ข But this is equivalent to stating ๐ป0 โˆถ ๐œ‡๐‘ โˆ’ ๐œ‡๐‘† = 0
โ€ข And the alternative?
โ€ข ๐ป0 โˆถ ๐œ‡๐‘ โ‰  ๐œ‡๐‘†
โ€ข What is our point estimate for ๐‘ฅ๐‘ โˆ’ ๐‘ฅ๐‘† ?
โ€ข ๐‘ฅ๐‘ โˆ’ ๐‘ฅ๐‘† = 5.08 โˆ’ 7.8 = โˆ’2.72
Do the hypothesis test
โ€ข What else do we need to calculate a t-statistic?
โ€ข Wee need the standard deviation ๐‘  of mean differences.
โ€ข We have a paired samples table, so we know each value,
and we can easily calculate ๐‘  (do not forget, you're dividing
by ๐‘› โˆ’ 1!).
โ€ข Let's say it is ๐‘  = 3.69.
โ€ข The t-statistic ๐‘ก =
๐‘ฅ๐‘ โˆ’๐‘ฅ๐‘†
๐‘ 
๐‘›
โˆ’2.72
= 3.69
= โˆ’3.68
25
โ€ข Do we reject the null or do we fail to reject the null at the ๐›ผ =
0.05?
โ€ข Critical values for ๐‘‘. ๐‘“. = ๐‘› โˆ’ 1 = 24 for two-tailed ๐›ผ = 0.05 are ±2.064.
โ€ข We reject the null.
Dependent samples
โ€ข e.g., give one person two different conditions to see how
he/she reacts. Maybe one control and one treatment or
two types of treatments.
โ€ข Advantages
โ€ข we can use fewer subjects
โ€ข cost-effective
โ€ข less time-consuming
โ€ข Disadvantages
โ€ข carry-over effects
โ€ข order may influence results
Independent samples
โ€ข Disadvantages of dependent samples become
advantages of dependent samples and vice versa.
โ€ข We need more subjects, it's generally more time consuming and
more expensive.
โ€ข No carry-over effects (each subject only gets one treatment).
โ€ข Everything else is same
โ€ข ๐ป0 โˆถ ๐‘ฅ1 โˆ’ ๐‘ฅ2 = 0, ๐ป1 โˆถ ๐‘ฅ1 โ‰  ๐‘ฅ2
โ€ข ๐‘ก=
๐‘ฅ1 โˆ’๐‘ฅ2
SE
โ€ข Reject ๐ป0 if ๐‘ < ๐›ผ, fail to reject ๐ป0 if ๐‘ > ๐›ผ.
Independent samples
โ€ข However, the standard error changes because it is based on
two sample sizes and two standard deviations.
โ€ข If we subtract normally distributed data from another normally
distributed data, we get a new data set
๐‘ ๐œ‡1 , ๐œŽ1 โˆ’ ๐‘ ๐œ‡2 , ๐œŽ2 = ๐‘ ๐œ‡1 โˆ’ ๐œ‡2 , ๐œŽ12 + ๐œŽ22
โ€ข Similarly, for the sample:
๐‘ . ๐‘‘. =
๐‘ 12 + ๐‘ 22
This is true only if two
samples are independent!
โ€ข standard error
๐‘ . ๐‘‘.
=
๐‘›
๐‘ 12 + ๐‘ 22
=
๐‘›
๐‘ 12 + ๐‘ 22
=
๐‘›
๐‘ 12 ๐‘ 22
+
๐‘›
๐‘›
Independent samples
โ€ข However, the standard error changes because it is based on
two sample sizes and two standard deviations.
โ€ข If we subtract normally distributed data from another normally
distributed data, we get a new data set
๐‘ ๐œ‡1 , ๐œŽ1 โˆ’ ๐‘ ๐œ‡2 , ๐œŽ2 = ๐‘ ๐œ‡1 โˆ’ ๐œ‡2 , ๐œŽ12 + ๐œŽ22
โ€ข Similarly, for the sample:
๐‘ . ๐‘‘. =
๐‘ 12 + ๐‘ 22
โ€ข standard error
๐‘ . ๐‘‘.
=
๐‘›
๐‘ 12 + ๐‘ 22
=
๐‘›
๐‘ 12 + ๐‘ 22
=
๐‘›
๐‘ 12
๐‘ 22
+
๐‘›1
๐‘›2
An example
โ€ข Again, the musical lesson.
โ€ข Let's teach nN = 10 students without the musical
performance, and expose different n๐‘† = 20 students to the
song.
โ€ข What will be the null and the alternative?
โ€ข ๐ป0 : ๐œ‡๐‘ = ๐œ‡๐‘† , ๐ป๐ด : ๐œ‡๐‘ โ‰  ๐œ‡๐‘†
โ€ข Which direction will we use?
โ€ข two-tailed
An example
โ€ข ๐‘›๐‘ = 10, ๐‘›๐‘† = 20
โ€ข ๐‘ฅ๐‘ = 5.08, ๐‘ ๐‘ = 2.65
โ€ข ๐‘ฅ๐‘† = 7.80, ๐‘ ๐‘† = 2.18
โ€ข Standard error
๐‘†๐ธ =
๐‘ ๐‘2 ๐‘ ๐‘†2
+
=
๐‘›๐‘ ๐‘›๐‘†
2.652 2.182
+
= 0.97
10
20
โ€ข Calculate t-statistic
๐‘ฅ๐‘ โˆ’ ๐‘ฅ๐‘† 5.08 โˆ’ 7.80
๐‘ก=
=
= โˆ’2.80
๐‘†๐ธ
0.97
โ€ข How will you proceed further?
โ€ข calculate d.f., define ๐›ผ, find the critical t-value, compare the t-
statistic with the t-critical, decide about the null
An example
โ€ข ๐‘‘. ๐‘“. = 10 + 20 โˆ’ 2 = 28
โ€ข t-critical value for ๐›ผ = 0.05 is ±2.048
โ€ข Reject or fail to reject the null?
โ€ข Reject the null.
Summary of t-tests
โ€ข one-sample test (jednovýbฤ›rový test)
โ€ข you test H0 : ๐œ‡ = ๐œ‡0
โ€ข two-sample test (dvouvýbฤ›rový test)
โ€ข you test H0 : ๐œ‡1 โˆ’ ๐œ‡2 = 0
โ€ข dependent samples
โ€ข paired t-test (párový test)
โ€ข independent samples
โ€ข equal variances ๐œŽ1 ~๐œŽ2
โ€ข unequal variances ๐œŽ1 โ‰  ๐œŽ2
two-sample tests
F-test of equality of variances
โ€ข How to know if our variances are equal or not?
โ€ข var.test() in R, ๐ป0 : ๐œŽ1 = ๐œŽ2
โ€ข Test statistic is a ratio of two variances. It has an F-
distribution. Each numerator and denominator has certain
number of d.f.
source: Wikipedia
t-test in R
โ€ข t.test()
โ€ข Let's have a look into R manual:
http://stat.ethz.ch/R-manual/R-patched/library/stats/html/t.test.html
โ€ข See my website for link to pdf explaining various t-test in
R (with examples).
Assumptions
1. Unpaired t-tests are highly sensitive to the violation of
the independence assumption.
2. Populations samples come from should be
approximately normal.
โ€ข This is less important for large sample sizes.
โ€ข What to do if these assumptions are not fullfilled
1. Use paired t-test
2. Let's see further
Check for normality โ€“ histogram
Check for normality โ€“ QQ-plot
qqnorm(rivers)
qqline(rivers)
Check for normality โ€“ tests
โ€ข The graphical methods for checking data normality still
leave much to your own interpretation. If you show any of
these plots to ten different statisticians, you can get ten
different answers.
โ€ข H0: Data follow a normal distribution.
โ€ข Shapiro-Wilk test
โ€ข shapiro.test(rivers):
Shapiro-Wilk normality test
data: rivers
W = 0.6666, p-value < 2.2e-16
Nonparametric statistics
โ€ข Small samples from considerably non-normal
distributions.
โ€ข non-parametric tests
โ€ข No assumption about the shape of the distribution.
โ€ข No assumption about the parameters of the distribution (thus they
are called non-parametric).
โ€ข Simple to do, however their theory is extremely
complicated. Of course, we won't cover it at all.
โ€ข However, they are less accurate than their parametric
counterparts.
โ€ข So if your data fullfill the assumptions about normality, use
paramatric tests (t-test, F-test).
Nonparametric tests
โ€ข If the normality assumption of the t-test is violated, and
the sample sizes are too small, then its nonparametric
alternative should be used.
โ€ข The nonparametric alternative of t-test is Wilcoxon test.
โ€ข wilcox.test()
โ€ข http://stat.ethz.ch/R-manual/R-patched/library/stats/html/wilcox.test.html