Lecture 8 T Test New
Lecture 8 T Test New
Lecture 8 T Test New
t - test
Jing Wang
aydgwwangjing@163.com
24/2/7 安医大公卫学院流统系 王静 制作
Review some key concepts of the last lessons
24/2/7 安医大公卫学院流统系 王静 制作
1. Statistical inference
draw conclusions of population from
sampled data.
Statistical Inference
Population Sample
Statistical Inference
24/2/7 安医大公卫学院流统系 王静 制作
2 Sampling error of mean
The difference between the sample mean and
population mean, or among different sample
means, caused by individual variation and
sampling.
It is expressed by two aspects:
① X ≠
② Xi ≠Xj
24/2/7 安医大公卫学院流统系 王静 制作
3 Standard error of mean, SEM
S
X SX
n n
24/2/7 安医大公卫学院流统系 王静 制作
4 t-distribution
X X
t , n 1
SX S n
It is a statistical distribution law of
sampling error of mean and a theory
foundation of statistical inference.
24/2/7 安医大公卫学院流统系 王静 制作
t-test
t-test is a type of hypothesis test based
on t-distribution.
24/2/7 安医大公卫学院流统系 王静 制作
• Example1: Hemoglobin of 25 lead workers of a sample
were measured, the mean was 130g/L and standard
deviation is 25.6g/L. It is known that the average
hemoglobin of general adult is 140g/L.
n 25 ,X 130.0 g / L , s 25.6 g / L
1 140 g/L
24/2/7 安医大公卫学院流统系 王静 制作
μ2 = μ1 μ2 ≠ μ1
X ≠ μ1
Population 1
Population 1 Population 2
Sample
μ1=140g/L μ1=140g/L μ2
n=25
x=130.0g/L
n=25
s=25.6 g/L
x=130.0g/L
s=25.6 g/L
24/2/7 安医大公卫学院流统系 王静 制作
Question: Which is the truth?
24/2/7 安医大公卫学院流统系 王静 制作
Two probable conclusions are denoted as H0 and H1 (two
hypotheses) respectively.
H0 —— Null hypothesis
H0: μ2 = μ1= 140 , X≠μ1 is due to sampling error
H1 —— Alternative hypothesis
H1: μ2 ≠μ1 , X≠μ1 is due to the two different populations
24/2/7 安医大公卫学院流统系 王静 制作
Assume that the null hypothesis H0 holds;
24/2/7 安医大公卫学院流统系 王静 制作
P<0.05
If it is less possible to occur the current sample
situation and even more unfavorable situation under
,then reject
H0 ; otherwise,
H 0 not reject . H0
P>0.05
( is called the significance level of test, or testing criterion
=0.05 )
24/2/7 安医大公卫学院流统系 王静 制作
Three steps of a hypothesis test
24/2/7 安医大公卫学院流统系 王静 制作
Step1: Set hypotheses and the significance level of test
H1: μ2 ≠μ1
= 0.05.
24/2/7 安医大公卫学院流统系 王静 制作
Step2: Select an appropriate test method and calculate
the test statistic (such as t value)
X
Then t ~ t distribution
S
n
24/2/7 安医大公卫学院流统系 王静 制作
Step3: Determine P value and make a conclusion
P-value in the hypothesis test: the probability of
the current sample situation (such as t value) and
even more unfavorable (or extremely) situation
under H0 .
.4
.3
=24
f(t)
.2
.1 P
P
0.0
-5.0 -4.0 -3.0 -2.0 -1.0 0.0 1.0 2.0 3.0 4.0 5.0
24/2/7 安医大公卫学院流统系 王静 制作
Conclusion:
① conclusion in statistics: If the P ≤ (=0.05) , we could say
that the difference is statistically significant at level , then H0 is
rejected. Otherwise, H0 isn’t rejected. (the writing of these
conclusions is same for all the hypothesis tests)
24/2/7 安医大公卫学院流统系 王静 制作
Design types of t-test
One sample t- test
Paired / matched t-test
Two samples t-test
24/2/7 安医大公卫学院流统系 王静 制作
Conditions of t-test:
24/2/7 安医大公卫学院流统系 王静 制作
One sample t- test
Aim: comparison between one sample mean
(X) and a population mean ().
24/2/7 安医大公卫学院流统系 王静 制作
• Example1: Hemoglobin of 25 lead workers of a sample
were measured, the mean was 130g/L and standard
deviation is 25.6g/L. It is known that the average
hemoglobin of general adult is 140g/L.
n 25 ,X 130.0 g / L , s 25.6 g / L
1 140 g/L
24/2/7 安医大公卫学院流统系 王静 制作
Set hypotheses :
H 0 : 2 1 140
H 1 : 2 140
0.05
24/2/7 安医大公卫学院流统系 王静 制作
If H 0 : 2 1 140 holds,
t
-1.953 1.953
24/2/7 安医大公卫学院流统系 王静 制作
Conclusion :
Two-sided , P=0.06258 >0.05. On the level of =
0.05 , H0 isn’t rejected ; we could say that there
has no difference on hemoglobin between the lead
workers and general adults, the population mean of
hemoglobin of lead workers 2 = 140 g/L.
24/2/7 安医大公卫学院流统系 王静 制作
Paired / matched t-test
Two types of paired designs
① paired design on a same individual
Such as:
Serum IgG measured before and after taking
medicine for measles→ if the medicine is effective
fat contents of a beverage product measured by two
methods→ if the measurements of these two
methods are different
24/2/7 安医大公卫学院流统系 王静 制作
Example i Before After
(1) (2) (3)
1 1206.44 1678.44
12 boys with measles
2 921.69 1293.36
treated by a medicine, 3 1294.08 1711.66
the IgG(mg/dl) was 4 945.36 1416.70
measured before and 5 721.36 1204.55
after the treatment as 6 692.32 1147.30
24/2/7 安医大公卫学院流统系 王静 制作
Example
10 beverage products were randomly sampled, two methods were
used to determine the fat content. Has there difference
between the measurements of two methods?
24/2/7 安医大公卫学院流统系 王静 制作
② paired design on two different individuals
Such as:
20 pigs are divided into 10 pairs matched on
birthweight, two pigs in each pair have same or
nearly same birthweight, then, two pigs in each
pair are all randomly treated by two treatments.
→ if these two treatments are different
( detail data was omitted )
24/2/7 安医大公卫学院流统系 王静 制作
Example 2 i Before After Difference di
(1) (2) (3) (4)=(3)-(2)
1 1206.44 1678.44 472.00
12 boys with measles
2 921.69 1293.36 371.67
treated by a 3 1294.08 1711.66 417.58
medicine, the 4 945.36 1416.70 471.34
IgG(mg/dl) was 5 721.36 1204.55 483.19
measured before and 6 692.32 1147.30 454.97
after the treatment as 7 980.01 1379.59 399.58
8 691.01 1091.46 400.45
follows.
9 910.39 1360.34 449.95
Is the medicine effective? 10 568.56 1091.83 523.27
11 1105.52 1728.03 622.51
12 757.43 1398.86 641.44
24/2/7 安医大公卫学院流统系 王静 制作
Assume that if the medicine has no effect on IgG, all
the differences (di) should follow a normal distribution
whose population mean is “0”.
Paired t-test is aim to compare the new sample
mean (d, mean of the differences) with the known
population mean “0”.
Paired t-test is equivalent to One-sample t-test.
24/2/7 安医大公卫学院流统系 王静 制作
Population 1: hemoglobin of
general adult men
μ0=0 μd ?
n=12
d=475.66
s=84.27
24/2/7 安医大公卫学院流统系 王静 制作
Sample
μd= μ 0 =0
n=12
d=475.66
s=84.27
24/2/7 安医大公卫学院流统系 王静 制作
Hypothesis testing of paired t-test
H 0: d 0 H 1 : d 0 0.05
24/2/7 安医大公卫学院流统系 王静 制作
Step 2 : Select an appropriate test and
calculate the test statistics (t value)
24/2/7 安医大公卫学院流统系 王静 制作
Step 3 : Determine P value, and make a conclusion
Two-sided , P=0.00000000068 <0.05. On the level of =
0.05 , H0 is rejected;
we could say that there has difference between the IgG
before and after treatment on the measles boys;
combined with the detail information of data, it could be
concluded that “after treatment, IgG of boys with measles
could be increased”, then “this medicine has effect on
measles”.
24/2/7 安医大公卫学院流统系 王静 制作
Example 3
10 beverage products were randomly sampled, two
methods were used to determine the fat content. Is
there difference between the two methods?
24/2/7 安医大公卫学院流统系 王静 制作
(1) Set hypotheses and the significance
level of test
H0 : d = 0
H1 : d≠0
=0.05
24/2/7 安医大公卫学院流统系 王静 制作
(2) calculate the test statistic
n=10 , d=2.724 , d2=0.8483 ,
d d / n 2.724 /10 0.2724
( d ) 2
(2.724) 2
d 2 0.8483
Sd n 10 0.1087
n 1 10 1
0.2724
t 7.925, 10 1 9
0.1087 10
24/2/7 安医大公卫学院流统系 王静 制作
(3) Determine P value, and make a conclusion
24/2/7 安医大公卫学院流统系 王静 制作
Independent two samples / groups t-test
Two independent samples taken from normal
populations are compared their means.
X 1 ≠ X 2 , 1= 2 ?
Conditions:
① quantitative variable in the population follows a
normal distribution.
②
The variances are equal ( 2)
2
1
2
24/2/7 安医大公卫学院流统系 王静 制作
Example 4
Two groups of rats were fed by different food, one group (n1=7)
fed by higher protein and the other group (n2=12) fed by
lower protein. Comparing the effects of different food on
increasing weight.
Groups 1 2 3 4 5 6 7 8 9 10 11 12 Mean SD
Lower
70 118 101 85 107 132 94 101 20.62
protein
Higher
134 146 104 119 124 161 107 83 113 129 97 123 120 20.48
protein
24/2/7 安医大公卫学院流统系 王静 制作
Two independent samples taken from normal
populations are compared their means.
μ1 μ2
n1=7 n2=12
X1 X2
s1 s2
X1 ≠ X2, 1= 2 ?
24/2/7 安医大公卫学院流统系 王静 制作
We should think about “whether the variances are
equal between the two normal populations” firstly.
And, we only know it through performing a
hypothesis test.
12 22
2
2
1
2
24/2/7 安医大公卫学院流统系 王静 制作
First: to perform homogeneity of variance test
(F-test)
H 0: 12 = 22
H1: 12 22
=0.05
S12
F 2 ~ F 1 , 2 , 1 n1 1, 2 n2 1
S2
24/2/7 安医大公卫学院流统系 王静 制作
F - distribution
24/2/7 安医大公卫学院流统系
安徽医科大学流行病与卫生统计学
王静 制作
系 王静
if F F 2,( 1,
2)
P , reject H 0 ,variances are not equal.
if F F 2,( 1,
2)
P , not reject H 0 ,variances are equal.
24/2/7 安医大公卫学院流统系 王静 制作
When the two population variances are
equal, then do Pooled t-test.
Sc2 is the variance by pooled estimation
with S12 and S22. (confederate)
X1 X 2
t , n1 n2 2
SX1X 2
24/2/7 安医大公卫学院流统系 王静 制作
When the two population variances are
not equal to each other, then do t’-test.
(t’ : t apostrophe )
t
X1 X 2
,
S 2X1 2
S X2 2
S 12 S 22 S 4X1 S 4X 2
n1 n2 n1 1 n2 1
24/2/7 安医大公卫学院流统系 王静 制作
Two groups of rats were fed by different food, one group
(n1=7) fed by higher protein and the other group
(n2=12) fed by lower protein. Comparing the effects
of different food on increasing weight.
Groups 1 2 3 4 5 6 7 8 9 10 11 12 Mean SD
Lower
70 118 101 85 107 132 94 101 20.62
protein
Higher
134 146 104 119 124 161 107 83 113 129 97 123 120 20.48
protein
24/2/7 安医大公卫学院流统系 王静 制作
First to test if two variances are equal
H 0: 12 = 22
H1: 12 22
=0.05
2
20.62
F 2
1.014 ~ F( 1,
), 1 7 1, 2 12 1
20.48 2
P=0.928
F 0.05 / 2, 11 ) 3.88 1.014
( 6,
P 0.05, reject
H 0 isn’t H 1
,
Variances are equal
rejected
24/2/7 安医大公卫学院流统系 王静 制作
Then to perform the pooled t-test
H 0 : 1 2
H1 : 1 2
0.05
24/2/7 安医大公卫学院流统系 王静 制作
( X X ) 2
( X X ) 2
sc2 1 1 2 2
n1 n2 2
X 1 ( X 1 ) / n1 X 2 ( X 2 ) / n2
2 2
n1 n2 2
177832 1440 2
/ 12 73959 707 2
/7
sc
2
446.12
12 7 2
2 1 1 1 1
s X 1 X x sc ( ) 446.12( ) 10.05
n1 n2 12 7
X 1 X 2 120 101
t 1 2 6 11 17
1.891 ,
s X1 X 2 10.05
24/2/7 安医大公卫学院流统系 王静 制作
Two-sided , P =0.0758 >0.05. On the level of
= 0.05 , H0 isn’t rejected ;
conclusion could be that there is no difference
on increasing weight between the higher
protein and lower protein groups, which is
equal to “higher or lower protein in food has no
effect on increasing weight”.
24/2/7 安医大公卫学院流统系 王静 制作
Questions for hypothesis testing
What does P-value mean?
What are the prerequisites of t-test?
Type I error & Type II error
Attentions for hypothesis testing
24/2/7 安医大公卫学院流统系 王静 制作
Q1: What does P-value mean?
-t t
24/2/7 安医大公卫学院流统系 王静 制作
Q2: What are the prerequisites of t-test?
24/2/7 安医大公卫学院流统系 王静 制作
Q3: What are Type I error & Type II error?
H 0 : 1 2 H1 : 1 2
24/2/7 安医大公卫学院流统系 王静 制作
① Under a certain sample size (n), if is
decreased , will be increased.
“the better the smallest ?”
② only increasing sample size n, and
would be decreased at the same time.
24/2/7 安医大公卫学院流统系 王静 制作
Q4: What are the attentions for hypothesis
testing?
Research design should be scientific and rigorous;
How to choose a certain hypothesis test should be
based on the different data.
Conclusion could not be absolute.
Conclusion should be reached from the point of
view in major ultimately.
Hypothesis test and confidence interval are equally
important and often used simultaneously.
24/2/7 安医大公卫学院流统系 王静 制作
24/2/7 安医大公卫学院流统系 王静 制作