t-test and ANOVA
Haramaya University
College of Health and Medical Science
Analysis of Quantitative Variable
Comparison of groups by other
numeric variable
The t-test
One-way ANOVA
T-test
We use t-test in either of the following three ways:
a. One sample t-test:
 It is used to compare the estimate of a sample with a
hypothesized population mean to see if the sample is
significantly different.
 Assumptions which should be fulfilled before we use this
method:
• The dependent variable is normally distributed within
the population
• The data are independent (scores of one participant are
not dependent on scores of the other)
T-test cont…
 Hypothesis: Ho: μ = μo Vs HA: μ≠ μo ,
Where μo is the hypothesized mean value
The test statistics is : tcalc = (x
̄ – μ)/(s/√n)
 We compare the calculated test statistics (tcalc) with the
tabulated value (ttab) at n-1 degree of freedom
No Distance in
miles
Drug use No Distance in
miles
Drug
use
1 14.5 no 10 18.4 yes
2 13.4 no 11 16.9 yes
3 14.8 yes 12 12.6 not
4 19.5 yes 13 13.4 not
5 14.5 no 14 16.3 yes
6 18.2 yes 15 17.1 yes
7 16.3 no 16 11.8 not
8 14.8 no 17 13.3 yes
9 20.3 yes 18 14.5 not
Mean 15.59
Standard deviation 2.43
T-test cont…
E.g. Data: The distance covered by marathon runners until a
physiological stress develops and whether they used drug or not
T-test cont..
It is believed that the mean distance covered before
feeling physiological stress is 15 miles
Hypotheses: Ho: = μ = 15 versus HA: μ ≠ 15
Level of significance: α = 5%
= 15.59, S = 2.43,
tcalc = (x – μ)/(s/√n) = 1.03, and P-value = 0.318
At 17 degree of freedom and α = 0.05, ttab = 2.110,
Since tcal = 1.03 < 2.110 = ttab, or α = 0.05 < 0.318 =p-value
we fail to reject Ho
x
̄
T-test cont..
b. Paired t- test
 Each observation in one sample has one and only one mate in
the other sample dependent to each other.
 For example, the independent variable can be measurements like:
before and after (e.g before and after an intervention), or
repeated measurement (e.g. using digital and analog apparatus),
or when the two data sources are dependent (e.g. data from
mother and father of respondent)
Hypothesis: Ho: μd = 0 Vs HA: μd ≠ 0
T-test cont..
Subject BP before BP after Difference (di)
1 130 110 -20
2 125 130 +5
3 140 120 -20
4 150 130 -20
5 120 110 -10
6 130 130 0
7 120 115 -5
8 135 130 -5
9 140 130 -10
10 130 120 -10
d (Average of d) -9.5
Sd (Standard deviation of d) 8.64
Example : The blood pressure (BP) of 10 mothers were measured before
and after taking a new drug.
T-test cont..
Hypothesis: Ho: μd = 0 Versus HA: μd ≠ 0
Set the level of significance or α = 0.05
d = -9.5, Sd = 8.64, n = 10,.
tcalc = (d – μd)/(sd/√n) = 3.48 and p-value = 0.0075,
At n-1 = 9 df and α = 0.05, ttab = 2.26
Since ttab = 2.26 < 3.48 = tcalc or p-value = 0.0075 < 0.05 = α
We reject Ho
T-test cont..
c. Two independent samples t-test
 Used to compare two unrelated or independent groups
 Assumptions include:
The variance of the dependent variable in the two
populations are equal
The dependent variable is normally distributed within
each population
The data are independent (scores of one participant are
not related systematically to the scores of the others)
 Hypothesis: Ho: μt = μc Vs HA: μt ≠ μc ,
Where μt and μc are the population mean of treatment and
control (placebo) groups respectively.
T-test cont..
 The test statistics is:
tcalc = (x t – xc)/√S2/(nt + nc),
 Where S2 = {(nt-1)St
2 + (nc-1)Sc
2}/(nt +nc -2)
 S2 = is the pooled (combined) variance of both groups.
 We compare the tcalc with the tabulated at n1+n2 -2 degree of
freedom and decide accordingly
Example
Do the marathon runners grouped by their drug intake status differ in
their average distance coverage before they feel any physiological
stress?
Hypothesis: Ho: μt = μc Vs HA: μt ≠ μc, where μt and μc are for drug
users and non-users respectively
Set the level of significance, α = 5%,
xc = 13.98, sc = 1.33, xt = 17.20, st= 2.21
tcalc = (xc – xt)/√S2/(nc + nt) = -3.741, and its p-value = 0.002
S2 = is the pooled (combined) variance of both groups.
At 16 df and α = 0.05, ttab = -2.12
Since tcal= |-3.741| > |-2.12|, or P-Value = 0.002 < 0.05 = α
We reject Ho
T-test cont…
 Here in the case of two independent sample t-test, we
have one continuous dependent variable (interval/ratio
data) and;
 one nominal or ordinal independent variable with only
two categories
 In this last case (i.e. two independent
sample t-test), what if there are
more than two categories for the
independent variable we have?
One way-Analysis Of Variance
(One-way ANOVA)
 Are the birth weights of children in different geographical
regions the same?
 Are the responses of patients to different medications and
placebo different?
 Are people with different age groups have different
proportion of body fat?
 Do people from different ethnicity have the same BMI?
One way-Analysis Of Variance
cont…
 All the above research questions have one common
characteristic: That is each of them has two variables: one
categorical and one quantitative
 Main question: Are the averages of the quantitative variable
across the groups (categories) the same?
 Because there is only one categorical independent variable
which has two or more categories (groups), the name one
way ANOVA comes.
16
One-way ANOVA cont…
 Also called Completely Randomized Design
 Experimental units (subjects) are assigned randomly
to treatments/groups. Here subjects are assumed to
be homogeneous
17
 One way ANOVA is a method for testing the hypothesis:
 More formally, we can state hypotheses as:
H0: There is no difference among the mean of treatments effects
HA: There is difference at least between two treatments effects
or
Ho: µ1 = µ2 = µ3 =…. = µa (if there are ‘a’ groups)
HA: at least one group mean is different
There is no difference between two or more population
means (usually at least three); or
There is no difference between a number of treatments
Analysis of variance cont…
Why Not Just Use t-tests?
 Since t-test considers two groups at a time, it will be
tedious when many groups are present
 Conducting multiple t-tests can lead also to severe
inflation of the Type I error rate (false positives) and is
not recommended
 However, ANOVA is used to test for differences
among several means without increasing the Type I
error rate
 The ANOVA uses data from all groups at a time to
estimate standard errors, which can increase the
power of the analysis
Assumptions of One Way ANOVA)
 The data are normally distributed or the samples have
come from normally distributed populations and are
independent.
 The variance is the same in each group to be compared
(equal variance).
 Moderate departures from normality may be safely ignored,
but the effect of unequal standard deviations may be serious.
 We test the equality of means among groups by using the
variance
 The difference between variation within groups and
variation between groups may help us to compare the
means
 If both are equal, it is likely that the observed difference is
due to chance and not real difference
Note that:
Total Variability = Variability between + Variability within
Analysis of variance cont…
22
Decomposing the total variability
n a n a n a
 Total SS = Σ Σ (xij – )2 = ΣiΣjxij
2 - (ΣiΣjxij)2 /na = SST
i=1 j=1
n a n a a n
 Within SS = Σ Σ (xij – j)2 = ΣiΣjxij
2 - Σj(Σixij)2/n = SSW
i=1 j=1
n a a n
 Between SS = Σ Σ ( i j – )2 = Σj(Σixij)2/n - (ΣiΣjxij)2 /na = SSB
i=1 j=1
This is assuming each of the ‘a’ groups has equal size, ‘n’.
SST = SSW + SSB
Sum of squares and ANOVA Table
 If there are real differences among groups’ means, the between
groups variation will be larger than the within variation
Source of
variation
df SS MS F
Between groups a-1 SSB = A - CF SSB/(a-1) MSB/MSW
Within groups na-a SSW = T - A SSW/(na –a)
Total na-1 SST = T - CF
Example on one-way ANOVA
The following table shows the red cell folate levels (μg/l) in three groups of
cardiac bypass patients who were given three different levels of nitrous oxide
ventilation. (Level of nitrous oxide for group I > group II’s > group III’s)
Group I
(n=8)
Group II
(n=9)
Group III
(n=5)
243
251
275
291
347
354
380
392
Total=2533
Mean =316.6
SD = 58.7
206
210
226
249
255
273
285
295
309
2308
256.4
37.1
241
258
270
293
328
1390
278.0
33.8
Example Cont….
We can see the box plot just to have some
impression about it
Example cont…
Ho: μ1 = μ2 = μ3
HA: Differences exist between at least two of the means
Since the P-value is less than 0.05, the null hypothesis is rejected
Source of variation df SS Mean
square
F P
Between groups
Within groups
2
19
15516
39716
7758
2090
3.71 0.044
Total 21 55232
Pair-wise comparisons of group means
post hoc tests or multiple comparisons
 ANOVA test tells us only whether there is statistically significant
difference among groups means, but
 It doesn’t tell us which particular groups are significantly
different
 To identify them, we use either a priori (pre-planed) or post hoc
tests
Pair-wise comparisons of group means
(post hoc tests) cont…
 When you look at the data it may seem worth comparing all
possible pairs.
 In this case, a post hoc test such as
 Scheffe, Benferroni (modified t-test),
 Tuckey methods,
 Least Squares Difference (LSD), etc will be employed.
Benferroni method or Modified t-test (Steps)
I. Find tcalc for the pairs of groups of interest (to be compared)
II. The modified t-test is based on the pooled estimate of
variance from all the groups (which is the residual variance
in the ANOVA table), not just from pair being considered.
III. If we perform k paired comparisons, then we should
multiply the P value obtained from each test by k; that is, we
calculate P' = kP with the restriction that P' cannot exceed 1.
Where, , that is the number of possible comparisons
Benferroni method or Modified t-test
 Returning to the red cell folate data given above, the residual
standard deviation is = 45.72.
(a) Comparing groups I and II
t = (316.6 - 256.4) / (45.72 x √(1/9 +1/8)
= 2.71 on 19 degrees of freedom.
 The corresponding P-value = 0.014 and the
corrected P value is P' = 0.014x3
= 0.042
Group I and II are different
Benferroni method or Modified t-test
(b) Comparing groups I and III
 t = (316.6 - 278.0) / (45.72 x √(1/8+1/5)
= 38.6/26.06
= 1.48 on 19 degrees of freedom.
 The corresponding P value = 0.1625 and
 The corrected P value is P' = 0.1625x3
= 0.4875
Group I and III are not different
Benferroni method or Modified t-test
(c) Comparing Groups II and III
 t = (278 - 256.4) / (45.72 x √(1/5+1/9)
= 21.6/25.5
= 0.85 on 19 degrees of freedom.
 The corresponding P value = 0.425 and the corrected P value
is P' = 1.00
Group I and III are not different
Therefore, the main explanation for the difference between
the groups that was identified in the ANOVA is thus the
difference between groups I and II.
Which post hoc method Shall I use? cont…
 The Bonferroni approach uses a series of t tests ( that is
the LSD technique) but corrects the significance level
for multiple testing by dividing the significance levels by
the number of tests being performed
 Since this test corrects for the number of comparisons
being performed, it is generally used when the number
of groups to be compared is small.
Which post hoc method Shall I use? Cont..
 Tukey’s Honesty Significance Difference (Tukey’s HSD)
test also corrects for multiple comparisons, but it considers
the power of the study to detect differences between groups
rather than just the number of tests being carried out;
 That is, it takes into account sample size as well as the
number of tests being performed.
 This makes it preferable when there are a large number of
groups being compared, since it reduces the chances of a
Type I error occurring.
One way ANOVA’s limitations
 This technique is only applicable when there is one
treatment used.
 Note that this single treatment can have 3, 4,… ,many
levels.
 Thus nutrition trial on children weight gain with 4
different feeding styles could be analyzed this way,
but a trial of BOTH nutrition and mothers health
status could not

Lecture-6 (t-test and one way ANOVA.ppt

  • 1.
    t-test and ANOVA HaramayaUniversity College of Health and Medical Science Analysis of Quantitative Variable
  • 2.
    Comparison of groupsby other numeric variable The t-test One-way ANOVA
  • 3.
    T-test We use t-testin either of the following three ways: a. One sample t-test:  It is used to compare the estimate of a sample with a hypothesized population mean to see if the sample is significantly different.  Assumptions which should be fulfilled before we use this method: • The dependent variable is normally distributed within the population • The data are independent (scores of one participant are not dependent on scores of the other)
  • 4.
    T-test cont…  Hypothesis:Ho: μ = μo Vs HA: μ≠ μo , Where μo is the hypothesized mean value The test statistics is : tcalc = (x ̄ – μ)/(s/√n)  We compare the calculated test statistics (tcalc) with the tabulated value (ttab) at n-1 degree of freedom
  • 5.
    No Distance in miles Druguse No Distance in miles Drug use 1 14.5 no 10 18.4 yes 2 13.4 no 11 16.9 yes 3 14.8 yes 12 12.6 not 4 19.5 yes 13 13.4 not 5 14.5 no 14 16.3 yes 6 18.2 yes 15 17.1 yes 7 16.3 no 16 11.8 not 8 14.8 no 17 13.3 yes 9 20.3 yes 18 14.5 not Mean 15.59 Standard deviation 2.43 T-test cont… E.g. Data: The distance covered by marathon runners until a physiological stress develops and whether they used drug or not
  • 6.
    T-test cont.. It isbelieved that the mean distance covered before feeling physiological stress is 15 miles Hypotheses: Ho: = μ = 15 versus HA: μ ≠ 15 Level of significance: α = 5% = 15.59, S = 2.43, tcalc = (x – μ)/(s/√n) = 1.03, and P-value = 0.318 At 17 degree of freedom and α = 0.05, ttab = 2.110, Since tcal = 1.03 < 2.110 = ttab, or α = 0.05 < 0.318 =p-value we fail to reject Ho x ̄
  • 7.
    T-test cont.. b. Pairedt- test  Each observation in one sample has one and only one mate in the other sample dependent to each other.  For example, the independent variable can be measurements like: before and after (e.g before and after an intervention), or repeated measurement (e.g. using digital and analog apparatus), or when the two data sources are dependent (e.g. data from mother and father of respondent) Hypothesis: Ho: μd = 0 Vs HA: μd ≠ 0
  • 8.
    T-test cont.. Subject BPbefore BP after Difference (di) 1 130 110 -20 2 125 130 +5 3 140 120 -20 4 150 130 -20 5 120 110 -10 6 130 130 0 7 120 115 -5 8 135 130 -5 9 140 130 -10 10 130 120 -10 d (Average of d) -9.5 Sd (Standard deviation of d) 8.64 Example : The blood pressure (BP) of 10 mothers were measured before and after taking a new drug.
  • 9.
    T-test cont.. Hypothesis: Ho:μd = 0 Versus HA: μd ≠ 0 Set the level of significance or α = 0.05 d = -9.5, Sd = 8.64, n = 10,. tcalc = (d – μd)/(sd/√n) = 3.48 and p-value = 0.0075, At n-1 = 9 df and α = 0.05, ttab = 2.26 Since ttab = 2.26 < 3.48 = tcalc or p-value = 0.0075 < 0.05 = α We reject Ho
  • 10.
    T-test cont.. c. Twoindependent samples t-test  Used to compare two unrelated or independent groups  Assumptions include: The variance of the dependent variable in the two populations are equal The dependent variable is normally distributed within each population The data are independent (scores of one participant are not related systematically to the scores of the others)  Hypothesis: Ho: μt = μc Vs HA: μt ≠ μc , Where μt and μc are the population mean of treatment and control (placebo) groups respectively.
  • 11.
    T-test cont..  Thetest statistics is: tcalc = (x t – xc)/√S2/(nt + nc),  Where S2 = {(nt-1)St 2 + (nc-1)Sc 2}/(nt +nc -2)  S2 = is the pooled (combined) variance of both groups.  We compare the tcalc with the tabulated at n1+n2 -2 degree of freedom and decide accordingly
  • 12.
    Example Do the marathonrunners grouped by their drug intake status differ in their average distance coverage before they feel any physiological stress? Hypothesis: Ho: μt = μc Vs HA: μt ≠ μc, where μt and μc are for drug users and non-users respectively Set the level of significance, α = 5%, xc = 13.98, sc = 1.33, xt = 17.20, st= 2.21 tcalc = (xc – xt)/√S2/(nc + nt) = -3.741, and its p-value = 0.002 S2 = is the pooled (combined) variance of both groups. At 16 df and α = 0.05, ttab = -2.12 Since tcal= |-3.741| > |-2.12|, or P-Value = 0.002 < 0.05 = α We reject Ho
  • 13.
    T-test cont…  Herein the case of two independent sample t-test, we have one continuous dependent variable (interval/ratio data) and;  one nominal or ordinal independent variable with only two categories  In this last case (i.e. two independent sample t-test), what if there are more than two categories for the independent variable we have?
  • 14.
    One way-Analysis OfVariance (One-way ANOVA)  Are the birth weights of children in different geographical regions the same?  Are the responses of patients to different medications and placebo different?  Are people with different age groups have different proportion of body fat?  Do people from different ethnicity have the same BMI?
  • 15.
    One way-Analysis OfVariance cont…  All the above research questions have one common characteristic: That is each of them has two variables: one categorical and one quantitative  Main question: Are the averages of the quantitative variable across the groups (categories) the same?  Because there is only one categorical independent variable which has two or more categories (groups), the name one way ANOVA comes.
  • 16.
    16 One-way ANOVA cont… Also called Completely Randomized Design  Experimental units (subjects) are assigned randomly to treatments/groups. Here subjects are assumed to be homogeneous
  • 17.
    17  One wayANOVA is a method for testing the hypothesis:  More formally, we can state hypotheses as: H0: There is no difference among the mean of treatments effects HA: There is difference at least between two treatments effects or Ho: µ1 = µ2 = µ3 =…. = µa (if there are ‘a’ groups) HA: at least one group mean is different There is no difference between two or more population means (usually at least three); or There is no difference between a number of treatments Analysis of variance cont…
  • 18.
    Why Not JustUse t-tests?  Since t-test considers two groups at a time, it will be tedious when many groups are present  Conducting multiple t-tests can lead also to severe inflation of the Type I error rate (false positives) and is not recommended  However, ANOVA is used to test for differences among several means without increasing the Type I error rate  The ANOVA uses data from all groups at a time to estimate standard errors, which can increase the power of the analysis
  • 19.
    Assumptions of OneWay ANOVA)  The data are normally distributed or the samples have come from normally distributed populations and are independent.  The variance is the same in each group to be compared (equal variance).  Moderate departures from normality may be safely ignored, but the effect of unequal standard deviations may be serious.
  • 20.
     We testthe equality of means among groups by using the variance  The difference between variation within groups and variation between groups may help us to compare the means  If both are equal, it is likely that the observed difference is due to chance and not real difference Note that: Total Variability = Variability between + Variability within Analysis of variance cont…
  • 21.
    22 Decomposing the totalvariability n a n a n a  Total SS = Σ Σ (xij – )2 = ΣiΣjxij 2 - (ΣiΣjxij)2 /na = SST i=1 j=1 n a n a a n  Within SS = Σ Σ (xij – j)2 = ΣiΣjxij 2 - Σj(Σixij)2/n = SSW i=1 j=1 n a a n  Between SS = Σ Σ ( i j – )2 = Σj(Σixij)2/n - (ΣiΣjxij)2 /na = SSB i=1 j=1 This is assuming each of the ‘a’ groups has equal size, ‘n’. SST = SSW + SSB
  • 22.
    Sum of squaresand ANOVA Table  If there are real differences among groups’ means, the between groups variation will be larger than the within variation Source of variation df SS MS F Between groups a-1 SSB = A - CF SSB/(a-1) MSB/MSW Within groups na-a SSW = T - A SSW/(na –a) Total na-1 SST = T - CF
  • 23.
    Example on one-wayANOVA The following table shows the red cell folate levels (μg/l) in three groups of cardiac bypass patients who were given three different levels of nitrous oxide ventilation. (Level of nitrous oxide for group I > group II’s > group III’s) Group I (n=8) Group II (n=9) Group III (n=5) 243 251 275 291 347 354 380 392 Total=2533 Mean =316.6 SD = 58.7 206 210 226 249 255 273 285 295 309 2308 256.4 37.1 241 258 270 293 328 1390 278.0 33.8
  • 24.
    Example Cont…. We cansee the box plot just to have some impression about it
  • 25.
    Example cont… Ho: μ1= μ2 = μ3 HA: Differences exist between at least two of the means Since the P-value is less than 0.05, the null hypothesis is rejected Source of variation df SS Mean square F P Between groups Within groups 2 19 15516 39716 7758 2090 3.71 0.044 Total 21 55232
  • 26.
    Pair-wise comparisons ofgroup means post hoc tests or multiple comparisons  ANOVA test tells us only whether there is statistically significant difference among groups means, but  It doesn’t tell us which particular groups are significantly different  To identify them, we use either a priori (pre-planed) or post hoc tests
  • 27.
    Pair-wise comparisons ofgroup means (post hoc tests) cont…  When you look at the data it may seem worth comparing all possible pairs.  In this case, a post hoc test such as  Scheffe, Benferroni (modified t-test),  Tuckey methods,  Least Squares Difference (LSD), etc will be employed.
  • 28.
    Benferroni method orModified t-test (Steps) I. Find tcalc for the pairs of groups of interest (to be compared) II. The modified t-test is based on the pooled estimate of variance from all the groups (which is the residual variance in the ANOVA table), not just from pair being considered. III. If we perform k paired comparisons, then we should multiply the P value obtained from each test by k; that is, we calculate P' = kP with the restriction that P' cannot exceed 1. Where, , that is the number of possible comparisons
  • 29.
    Benferroni method orModified t-test  Returning to the red cell folate data given above, the residual standard deviation is = 45.72. (a) Comparing groups I and II t = (316.6 - 256.4) / (45.72 x √(1/9 +1/8) = 2.71 on 19 degrees of freedom.  The corresponding P-value = 0.014 and the corrected P value is P' = 0.014x3 = 0.042 Group I and II are different
  • 30.
    Benferroni method orModified t-test (b) Comparing groups I and III  t = (316.6 - 278.0) / (45.72 x √(1/8+1/5) = 38.6/26.06 = 1.48 on 19 degrees of freedom.  The corresponding P value = 0.1625 and  The corrected P value is P' = 0.1625x3 = 0.4875 Group I and III are not different
  • 31.
    Benferroni method orModified t-test (c) Comparing Groups II and III  t = (278 - 256.4) / (45.72 x √(1/5+1/9) = 21.6/25.5 = 0.85 on 19 degrees of freedom.  The corresponding P value = 0.425 and the corrected P value is P' = 1.00 Group I and III are not different Therefore, the main explanation for the difference between the groups that was identified in the ANOVA is thus the difference between groups I and II.
  • 32.
    Which post hocmethod Shall I use? cont…  The Bonferroni approach uses a series of t tests ( that is the LSD technique) but corrects the significance level for multiple testing by dividing the significance levels by the number of tests being performed  Since this test corrects for the number of comparisons being performed, it is generally used when the number of groups to be compared is small.
  • 33.
    Which post hocmethod Shall I use? Cont..  Tukey’s Honesty Significance Difference (Tukey’s HSD) test also corrects for multiple comparisons, but it considers the power of the study to detect differences between groups rather than just the number of tests being carried out;  That is, it takes into account sample size as well as the number of tests being performed.  This makes it preferable when there are a large number of groups being compared, since it reduces the chances of a Type I error occurring.
  • 34.
    One way ANOVA’slimitations  This technique is only applicable when there is one treatment used.  Note that this single treatment can have 3, 4,… ,many levels.  Thus nutrition trial on children weight gain with 4 different feeding styles could be analyzed this way, but a trial of BOTH nutrition and mothers health status could not