Download as pdf or txt
Download as pdf or txt
You are on page 1of 151

Advanced Biostatistics

By
Hirbo Shore (MPH, Assistant Professor)
School of Public Health, CHMS-HU
hamakiya@gmail.com

1
Course objective
• At the end of the course students will be able to:
– Describe the relationship between two or more variables

– Explain changes of trends of events

– Explain the context and meaning of statistical test results

– Estimate the probability peoples survival for a given length


of time

– Calculate, interpret and write report on a given health and


health related dataset

2
Course contents
1. Chapter One: Analysis of Continuous Data

2. Chapter Two: Advanced Regression Analysis

3. Chapter Three: Survival Analysis

4. Chapter Four: Time series analysis:

5. Chapter Five: Longitudinal Data Analysis

6. Chapter Six: Non-parametric Tests

3
Methods Instruction
• Lecture

• In-class exercise

• Take-home assignments

• Question and discussions

• Independent reading

• Computer demonstrations (STATA and SPSS)

4
Evaluation

• Class participation

• Assignment

• Final examination

5
References
1. Pagano M and Gabuvereau K. Principles of Biostatistics, 2nd Edition
2. Wayne W. Daniel. Biostatistics; A Foundation for Analysis in the Health
Sciences
3. Eric Vittinghoff • David V. Glidden Stephen C. Shiboski Charles E.
McCulloch. Regression Methods in Biostatistics: Linear, Logistic,
Survival, and Repeated Measures Models
4. Hubert Gatignon. Statistical Analysis of Management Data, Third
Edition.
5. Scott M.Lynch. Using Statistics in Social Research: A Concise Approach

6
Statistical methods for continuous
data

7
Comparison of two groups
• The statistical idea used in the test of hypotheses share the
roots with those used in confidence interval

• Hypothesis testing is a way of organizing and presenting


evidence that helps reach a decision

• The emphasis of confidence interval and hypothesis testing is


different

8
Comparison of two groups,…

• The CI provides the limits that are likely to contain the


parameter

• Hypothesis testing aids in reaching decision about whether or


not we believe that the hypothesized value of the parameter is
correct

• Hypothesis testing provide information about the decision that


is not provided with the confidence interval

9
Comparison of two groups,…
• Hypothesis testing for the difference of two means
• Assumptions
– The two populations are normally distributed

– The two populations have the same variance.

– The two samples are independent of each other


– Each sample is obtained using independent random sampling from its
corresponding population
• The test procedures used are different depending on where the
means are independent or dependent

10
Comparison of two groups,…
• Difference of Two Independent Means

• Assumptions

– The variance are known

– The variance are unknown but equal

– The variance are unknown and unequal

11
Comparison of two groups,…
• Difference of Two Independent Means
– Normality assumption
• The underlying population distributions are approximately
normally distributed is fairly robust.

• As long as the underlying population distributions are


approximately symmetrical and mound shaped, the use of the t-
test is valid.
• Check distributions are approximately mound shaped and
symmetrical by examining the distribution of the data in your
sample

12
Comparison of two groups,…
• Difference of Two Independent Means
– Known variance
H0: µ1-µ1 = 0
H1: µ1-µ1 ≠ 0

Test statistics
ഥ 1−𝑥
𝑥 ഥ 2 −∆0
𝑍=
𝜎12 𝜎22
+
𝑛1 𝑛2

13
Comparison of two groups,…
• Difference of Two Independent Means
– Unknown but equal population variance

• The degrees of freedom for this test are n1 + n2 – 2


• Test statistics

𝑥ҧ 1−𝑥ҧ 2 𝑛1−1 𝑆12+ 𝑛2−1 𝑆12


𝑡= , Sp=
𝑆𝑃2 𝑆𝑃2 𝑛1+𝑛2−2
+
𝑛1 𝑛2

14
Example
• To compute mean,
stata command: bysort sex: sum Blood_gluc (I used metsyn data)

n1=280
n2=567
𝑥ҧ 1=121.8464
𝑥ҧ 2=120.3475
Sp=2594.8194

display ((279)*53.33543^2+(566)*49.7158^2)/(279+566)=2594.8194

15
Example
• E.g Stata command; ttest v1, by(catvar)
ttest Blood_gluc, by(sex)

16
Comparison of two groups,…
• Difference of Two Independent Means
– Unknown and unequal population variance
– The degrees of freedom for this test are not the usual n1 +
n2 - 2

𝑥ҧ 1−𝑥ҧ 2
– Test statistics t’= , with df=f
𝑆𝑃2 𝑆𝑃2
𝑛1
+𝑛
2

𝑠12 𝑠22
( 𝑛1 + 𝑛2 )
f= 𝑠2 𝑠22
( 𝑛1 )/𝑛1−1+( 𝑛 )/𝑛2−1
1 2

17
Comparison of two groups,…
• E.g., ttest d4, by(sex) unequal

18
Comparison of two groups,…
• Two dependent means
Assumptions
– The population of difference scores is normally distributed.
– The two samples are dependent (e.g. before and after, pairs
of knees)
– Each sample is obtained using independent random
sampling.

19
Comparison of two groups,…
• Two dependent means
• Start by calculating the difference scores for each pair and
• then perform a t-test on the new variable
• Hypothesis
Ho: µd=µdo, H1: µd ≠ µdo
• Test statistics

𝑑−𝜇
t= 𝑑𝑜
𝑆𝑑/ 𝑛

20
Example: paired test
• Using data of blood pressure measurement before and after intervention
• Stata COMMAND
– ttest bp_before== bp_after

21
ANOVA

Comparison of more than two


groups

22
Comparison of more than two groups
• The hypothesis to be tested for k means (k≥2)
H0: µ1=µ2=µ3=…µk
• All population means are equal or
• No treatment effect
H1: Not all of the population means are the same
• At least one population mean is different
• There is a treatment effect
– Note: doesn’t mean that all means are different or some
pairs may be the same

23
Comparison of more than two groups,…
– If we reject null hypothesis, we cannot conclude that at
least one population mean doesn’t equal another population
mean

– Other methods are needed to determine which population


means are different

– If the global test is not performed, multiple test between


different pairs of means will alter the alpha level for the
experiment as whole
24
Comparison of more than two groups,…
• For example, if four groups levels with their six possible
combination are to be compared, and each comparison is made by
using alpha=0.05

– 5% chance that each comparison will falsely be called significant

– a types I error may occur six times; overall 30%(approximation)

• It doesn’t mean that all the comparisons are not independent

25
Comparison of more than two groups,…
– The overall error =1-(1-α)k, where α is the significancy
level and k is the number of significancy tests the can be
done

– For the above example

1-(1-0.05)6=0.265

– ANOVA protects researchers against error inflation

26
ANOVA,…
• The technique whereby the total variation present in the data
set is partitioned into several component

• Each of component of variation is associated with a specific


source of variation

• Its important to know the magnitude of the contribution of


each of the source of variation to total variation

27
ANOVA,…
• Purpose of ANOVA
– To estimate and test hypotheses about population variances

– To estimate and test hypotheses about population means

28
ANOVA,…

• Instead of dealing with means as data point we deal with


variation

• There is variation within the group (data)

• There is variation between group means

• If the groups are equivalent, then the variance between and


within groups would be equal

• Expected variation used to calculate statistical significance as


expected differences
29
ANOVA
Definitions 1
– Response variables
• The variable of interest to be measured in experiment.
• Also referred to as dependent variable
Definition 2
– Factors
• Variables whose effect on the response is of interest to
experimenter
• Categorical variable

30
ANOVA
• Definition 3

– Factor levels

• The values of the factors utilized in the experiment

• Definition 4

– Experimental unit

• The object on which the response of the factors are


observed or measured

31
One-way ANOVA

32
One way ANOVA
• The simplest type of analysis of variance

• There is only one factor

• Assumption
– Data constitute independent random sample from the respective
populations

– Each of the population from which each sample comes is normally


distributed

– Each of the population has the same variance

33
One way ANOVA,…
Never Previous recent
disclosed disclosed disclosed

Random Random Random

x11 x21 x31


x12 x22 x32
CD4% . . .
change . . .
. . .
x1n1 x2n2 x3n3

CD4% change for each self-disclosure categories

34
One way ANOVA,…

35
One way ANOVA,…
• Hypothesis Testing Steps
Step 1. Description of data
– The measurements resulting from a completely randomized
experimental design, along with the means and totals that can be
computed from them

36
One way ANOVA,…
• Step 2. Assumption
– The Model

37
One way ANOVA,…

• Components of the model


– that a typical observation from the total set of data under
study is composed of;

1. the grand mean

2. a treatment effect

3. an error term representing the deviation of the


observation from its group mean.

38
One way ANOVA,…

• Assumptions of the Model


– The assumptions for the fixed-effects model are as follows:

39
Oneway ANOVA,…
• Step 3: Hypotheses
– 𝐻0 : the means for the k groups are equal
𝜇1 = 𝜇2 = ⋯ = 𝜇𝑘
– 𝐻1 : at least one of the means is different from the others
– Step 4. test statistics
• The test statistic for one-way analysis of variance is a
computed variance ratio(V.R)
Variance 𝑏𝑒𝑡𝑤𝑒𝑒𝑛
Variance Ratio= Variance 𝑤𝑖𝑡ℎ𝑖𝑛 = F

40
Oneway ANOVA,…
• F-statistic is compared to an F-distribution which has two
degrees-of-freedom parameters df1 and df2
• df1 = k − 1,
df2 = n − k
(where k=#groups and
n=sample size)
F=t2
One-way ANOVA,…
• Step 5. Distribution of test statistic

– V.R is distributed as the F distribution when H0 is true and


the assumptions are met

• Step 6. Decision rule

– Reject the null hypothesis if the computed value of V.R is


equal or greater than the critical value of F for the chosen α
level.

42
One-way ANOVA,…
• If calculated F>F tabulated→ reject H0

– F tabulated depends on α, the df for the numerator and df


for denominator

– Significant F only tell us there are difference, not where the


difference lie

43
One-way ANOVA,…
• Step 7. Calculation of test statistic
– Partitioning of the total variation present in the observed data into its
basic components, each of which is attributable to an identifiable
source

• The Total Sum of Squares (SST)

– sum the squared deviations for each treatment


group, and add the k group totals

44
One- way ANOVA…
• Between-group sum squares (SSB)
SSB=
• Within-group sum of squares(SSW)

– Total variance=variance between+ variance within


TSS=SSB+SSW

45
One-way ANOVA…
• Between groups degree of freedom

df = k-1

• Within group degree of freedom

df = n-k, where n=n1+n2+…+nk

46
One-way ANOVA,…
• Mean Square
– When we divide the sum of squares (SS) by its degrees of freedom (df),
we obtain what is called mean square (MS)

47
One-way ANOVA, …
• Between-group mean square (MSB)

MSB=𝑆𝑆𝐵
𝑘−1

• Within-group mean square(MSW)

MSW=𝑆𝑆𝑊
𝑛−𝑘

• F-statistics to test the null hypothesis


𝑀𝑆𝐵
F=𝑀𝑆𝑊 , with df=(k-1, n-k)

48
One-way ANOVA,…

49
One-way ANOVA,…
Treatment 1 Treatment 2 Treatment 3 Treatment 4
y11 y21 y31 y41

y12 y22 y32 y42


y13 y23 y33 y43
y14 y24 y34 y44
y15 y25 y35 y45
y16 y26 y36 y46

y17 y27 y37 y47


y18 y28 y38 y48
y19 y29 y39 y49
y110 y210 y310 y410
𝟏𝟎 𝟏𝟎 𝟏𝟎 𝟏𝟎

ഥ𝟏 = ෍ 𝒚𝟏𝒋
𝒚 ഥ𝟐 = ෍ 𝒚𝟐𝒋
𝒚 ഥ𝟑 = ෍ 𝒚𝟑𝒋
𝒚 ഥ𝟒 = ෍ 𝒚𝟒𝒋
𝒚
𝒋=𝟏 𝒋=𝟏 𝒋=𝟏 𝒋=𝟏
𝟏𝟎 𝟏𝟎 𝟏𝟎 𝟏𝟎

ഥ𝟏)2/10 − 1 + ෍ 𝒚𝟐𝒊 − 𝒚
෍(y1𝑖 − 𝒚 ഥ𝟐 𝟐 /𝒏 − 𝟏) + ෍(y3i − 𝒚
ഥ3)2/10 − 1 + ෍ 𝒚𝟒𝒊 − 𝒚
ഥ𝟒 𝟐 /𝒏 − 𝟏)
𝒋=𝟏 𝒋=𝟏 𝒋=𝟏 𝒋=𝟏

50
One-way ANOVA,…
• Height (in inches) of children with four different groups
Group 1 Group 2 Group 3 Group 4
60 50 48 47
67 52 49 67
42 43 50 54
67 67 55 67
56 67 56 68
62 59 61 65
64 67 61 65
59 64 60 56
72 63 59 60
71 65 64 65

51
One-way ANOVA,…
• Hypothesis testing
1. Data generated from randomly selected group
2. H0: μgr1=μgr2=μgr3=μgr4
H1: at least one of the means is different from the others
3. Statistics: Variance Ratio
4. Distribution of test statistic
Numerator df= 4-1=3
Denumerator df=40-4=36
α=5%

52
ANOVA model
Height (in inches) of children with four different groups

Group 1 Group 2 Group 3 Group 4 Calculate the sum of squares between


60 50 48 47 groups
67 52 49 67 • Mean for group 1= 62
42 43 50 54
• Mean for group 2= 59.7
• Mean for group 3= 56.3
67 67 55 67
• Mean for group 4= 61.4
56 67 56 68
• Grand mean= 59.85
62 59 61 65
64 67 61 65 SSB=(62-59.85)2+(59.7-59.85)2
59 64 60 56 +(56.3-59.85)2 +(61.4-59.85)2
72 63 59 60 =196.5
71 65 64 65

53
• SSW=(60-62)2+(67-62)2+(42-62)2+…+(72-62)2 + (50- 59.7)2
(5259.7)2 + (43-59.7)2+…(65-59.7)2+ (48-56.3)2+(49-
56.3)2 +(5056.3)2 +…+ (64-56.3)2+(47-61.4)2+(67-
61.4)2+(54-61.4)2+…+(65-61.4)2

=2060.6

54
ANOVA model
• Calculate the sum squares within group
MSB=196.5
3
=65.5 𝑀𝑆𝐵
F=𝑀𝑆𝑊 , with df=(k-1, n-k)
MSW=2060.6
36
=57.24 65.5
F=57.24 =1.1443269
Decision: since calculated F <tabulated F

1.443269<2.8662656, there is no sufficient evidence to


reject H0

55
ANOVA model
5. Rejection rule
calculated F>F tabulated→ reject H0

tabulated F 3, 36, 0.95 =2.866, read from F table: F0.95, 3, 36


Or
stata command: display invF(3, 36, 0.95)

df of numerator df of denominator 1-α

56
Model using stata
• Descriptive statistics

57
Assessing normality
• Shapiro-Wilk Test (Ho: Distribution is normal)

• P-value > α indicates that we cannot reject a H0: that the data
are from a normally distributed population

58
Assessing Homogeneity of Variances
• Bartlett’s test of Homogeneity of Variances
– Assume the variance are equal across sample subsamples,
or groups.
– it presumes that the distribution of the (dependent) variable
is normal
– P-value > α, indicate nots sufficient evidence to reject
H0: 𝜎12 = 𝜎22 =…. =𝜎𝑘2

59
Assessing Homogeneity of Variances
• Levene’s test for Equality of Variances
– Used when the data deviate from normality, and especially
in smaller samples

– more robust to non-normality

– P-value of Levene's test < α, the null hypothesis of equal


variances is rejected and it is concluded that there is a
difference between the variances in the population

60
ANOVA model
• ANOVA table
– Stata command: oneway height group

61
ANOVA model
stata command: oneway height group, tabulate

62
ANOVA model
stata command: anova height group

This model provides regression information in addition to ANOVA

63
Multiple comparison procedures
• Pairwise Comparisons in ANOVA

– A statistically significant ANOVA(F-test) only tells that at


least two of the groups differ, but not which one differs.

– Determine which groups differ requires more sophisticated


analyses to correct for the problem of multiple comparison

– Once the between groups difference is identified, it a must


to identify which of k-groups differ

64
Multiple comparison procedures

• Pairwise Comparisons in ANOVA


– Testing procedures should be used for assessing the
statistical significance of all possible pairwise differences
between groups, without inflation of the overall or family-
wise type-I error rate (FER), which can arise from testing
multiple null hypotheses

65
Multiple comparison procedures
• If you didn’t specify the comparisons of interest ahead of time,
then you to pay a price for making all pairwise comparisons to
keep all types-I error rate to α

• Alternatively, run a limited number of planned comparisons

• The are two types of comparisons

– Planned

– unplanned

66
Multiple comparison procedures
• Contrast
– A simple contrast hypothesis compares two population
means
• H0: µ1=µ4 , (special linear contrast)
– A complex contrast hypothesis has multiple population
means on either side
• H0: (µ1+µ1)/2=µ3
• H0: (µ1+µ2)/2=(µ3+µ4+µ5)/3

67
Multiple comparison procedures

• Planned comparisons
– Most statistical packages allow custom planned contrast
hypotheses

– The p-values are valid under strict conditions

– The conditions maintain Type-I error rate across the whole


experiment

68
Multiple comparison procedures
• Conditions for planned comparisons

– Contrasts are selected before looking at the residuals

– Must be ignored if the overall null hypothesis is rejected

– Each contrast is based on independent information from


other contrast

– The number of planned comparisons must not be more than


the corresponding df (k-1)

69
Multiple comparison procedures
• Unplanned comparisons(post-hoc test)
– Done when difference is noticed when looking at the
results

– Comparisons can be made but no need to adjust for α-level


for Type-I error

70
Multiple comparison procedures

• Choices of multiple comparisons


– Depend of the types of experimental design used and the
comparisons of interest to the analysis

71
Multiple comparison procedures
• Bonferroni methods
• Used for pairwise comparisons when the sample sizes of
the treatments are equal or not
• Adjust P-value by most conservative amount
– Divide P-value by the number of tests
• All pairwise difference(y1-y2) are compared against the
statistics
𝑀𝑆𝐵 𝑀𝑆𝑊
𝑡 𝛼 ,𝑛−𝑘 𝑛𝑖
+ 𝑛 , where C is total number of possible comparison
2𝑐 𝑗

72
Multiple comparison procedures
• Scheff’s test
– More general procedure for comparing all possible linear
combination of treatment means (contrasts)

– Confidence interval for pairwise comparisons is generally


wider than Tukey’s or Bonferonni’s confidence interval

– Suitable for pairwise comparison between all groups, not


simply pairwise compare

– Correct for the increased risk of a Type-I error (FER)

73
Multiple comparison procedures
• Tukey’s Honestly Significant Difference(HSD), Equal sample size
– makes use of a single value against which all differences
are compared

– α is the chosen level of significance, k is the number of


means in the experiment, N is the total № of observations,
n is the number of observations in a treatment, MSE is the
error, and q(studentized range distribution) is obtained by
entering α, k, and N – k

74
Tukey’s Honestly Significant Difference(HSD), unequal
sample size
– Also known as Tukey-Kramer method
– All pairwise differences (𝑦ത𝐴 − 𝑦ത𝐵) are compared with the
statistics

1 𝑀𝑆𝑊 𝑀𝑆𝑊 𝑀𝑆𝑊


𝑞𝛼,𝑘,𝑛−𝑘 ( 𝑛 + 𝑛 ) = 𝑞𝛼,𝑘,𝑛−𝑘 2(𝑛𝑖−𝑛𝑗)
2 𝑖 𝑗

where q is the studentized range distribution with df k, n-k

– If the difference exceed the above value, the differences are


significantly different from zero
75
Multiple comparison procedures

• The Newman-Keuls procedure

– All the means are arranged in increasing order and


Newman-Keuls statistic q is computed

ഥ 𝐴−𝑦
𝑦 ഥ𝐵
q= 𝑀𝑆𝑊 1 1
,
2
(𝑛 +𝑛 )
𝐴 𝐵

• where 𝑦ത𝐴𝑎𝑛𝑑 𝑦ത𝐵 are the two means being compared and
nA and nB are corresponding sample size

76
Multiple comparison procedures
• The critical value depends on αT the total risk of erroneously
asserting a difference for all comparisons combined, γd , the df
for MSW and parameter P, which is the number of means
being tested.

– E.g., comparing the largest and smallest of four mean


means, P=4; when comparing the second smallest and
smallest mean, P=2

77
Examples
• stata command: oneway height group, bonferroni

78
Example…
oneway height group, scheff

79
Example…
oneway height group, sidak

80
Tukey’s test

81
Tukey’s test

82
Tukey’s Honestly Significant Difference(HSD)

83
The Newman-Keuls

84
Exercise
• In a study of 90 patients on renal dialysis, Farhad Atassi (47)
assessed oral home care practices. He collected data from 30
subjects who were in (1) dialysis for less than one year, (2)
dialysis for 1 to 3 years, arid dialysis for more than 3 years.
The following table shows plaque index scores for these
subjects A higher score indicates a greater amount of plaque.
Do analysis of variance, check assumption, pairwise
comparison. Use α=5%

85
Exercise,…

86
Two-way ANOVA

87
Two way ANOVA
• The technique for analyzing the data from a randomized
complete block design

• an observation is categorized on the basis of two criteria—the


block to which it belongs as well as the treatment group to
which it belongs

• There are two independent categorical variable, factor say X1


and X2, which affect the dependent variable

88
Two way ANOVA
• If X1 has k levels and X2 m levels, then the analysis is referred
to as a k by m or k x m ANOVA

• The treatment groups are formed by making all possible


combinations of the two factors

• Examle
IV-1 IV-2 DV
Disclosure status WHO Stages CD4 count
Type of exercise Types of diet Weight change
HP pt interaction types of services satisfaction score

89
Two way ANOVA
• Advantages

– Compare relative influences on inpendent variable

– Examine interactions between independent variable

90
Two way ANOVA
Steps in two way anova
Step 1: Data.

– After identifying the treatments, the blocks, and the


experimental units, the data, for convenience

Step 2: Assumptions.

– The model for the randomized complete block design and


its underlying assumptions are as follows:

91
Two way ANOVA
• The model

92
Two way ANOVA
Step 3: Hypothesis testing
H0: 𝜏𝑗(𝑡𝑟𝑒𝑎𝑡𝑚𝑒𝑛𝑡 𝑒𝑓𝑓𝑒𝑐𝑡) = 0
HA: at least 𝜏𝑗 ≠ 0
Step 4: Test statistic
– The test statistic is V.R.(variance Ratio)
Step 5: Distribution of test statistic
– When is true and the assumptions are met, V.R. follows an
F distribution.
Step 6: Decision rule
– Reject the null hypothesis if the computed value of the test statistic V.R.
is equal to or greater than the critical value of F.

93
Two way ANOVA
Step 7: Calculation of test statistic
– total sum of squares for the randomized complete block
design can be partitioned into three components, one each
attributable to treatments (SSTr ), blocks (SSBl ), and error
(SSE )

• SST = SSBl + SSTr + SSE

94
Two way ANOVA
• The formulas for the quantities

Degrees of freedom for each componen


• total= kn-1
• Block= n-1
• Treatment: k-1
• Residual error: (n-1)(k-1)

95
Two way ANOVA
• Step 8: Statistical decision
– When the null hypothesis is true, therefore, the quantity
MSTr/MSE is distributed as F with k-1 numerator degrees
of freedom and (n-1)(k-1) denominator degrees of freedom.

– The computed variance ratio, therefore, is compared with


the critical value of F

96
Two way ANOVA
• ANOVA Table for the Randomized Complete Block Design

97
Two way ANOVA
Step 9: Conclusion.
– If we reject we conclude that the alternative hypothesis is
true.
– If we fail to reject we conclude that may be true.
Step 10: p value.
– The following example illustrates the use of the
randomized complete block design.

98
Two way ANOVA

• Let assume that there are two factors, A and B

• The effect of a single variable is known as the main effect

• The effect of two variables considered together is interaction

• We, therefore, assess

– The main effect of variable A

– The main effect of variable B

– The interaction between A and B

99
Two way ANOVA
• There are three sets of null hypothesis
1. The population means of the first factor are equal
2. The population means of the second factor are equal
3. There is no interaction between the two factor
– The main effect involves the independent variable at a time

– The interaction effect that one factor has on the other factor

– The within variation/error is the sum of the squares of within each


treatment group
• df is the product of the two degree of freedom for each variable

100
Two way ANOVA
• Interaction effect
– If the interaction is significant, the model is called
interaction model
– If the interaction is not significant, the model is called an
additive model
• Interaction or profile plots
– Used to look at outcome of mean for two factors
– Parallel line suggest an additive model
– None parallel suggest interaction
– The plot should not be the deciding factors whether or not
to run the model
101
Two way ANOVA
• With variation
– The with variation is the sum of squares within each
treatment group
– The within variance is the within variation divided by its
degree of freedom
– The within group is called error
• Error assumption
– All errors are normally distributed
– All errors have expected value zero
– All errors have the same variance
– All errors are independent

102
Two way ANOVA
• Structure if analysis for a two-way ANOVA

Total variability

Between treatment Within treatment


variability variability

Factor A Factor B Interaction


variability variability variation

103
Two way ANOVA
• Example 1
– A physical therapist wished to compare three methods for
teaching patients to use a certain prosthetic device.

– He felt that the rate of learning would be different for


patients of different ages and wished to design an
experiment in which the influence of age could be taken
into account

104
Two way ANOVA
• Solution
– The randomized complete block design is the
appropriate design for this physical therapist.
• Data:
– Three patients in each of five age groups were selected to
participate in the experiment, and one patient in each age
group was randomly assigned to each of the teaching
methods.
– The methods of instruction constitute our three treatments,
and the five age groups are the blocks

105
Two way ANOVA
• Assumptions
– We assume that each of the 15 observations constitutes a
simple random of size 1 from one of the 15 populations
defined by a block-treatment combination

106
Two way ANOVA
• Hypothesis testing
H0: 𝜏𝑗 = 0
HA: at least one 𝜏𝑗 ≠ 0
• Test statistic
– Variance ratio(V.R)=MSTr/MSE
• Distribution of test statistic
– When H0 is true and the assumptions are met, V.R. follows
an F distribution with 2 and 8 degrees of freedom

107
Two way ANOVA
• Decision rule
– Reject the null hypothesis if the computed V.R. is equal to
or greater than the critical F, to be 4.46 (from the table) or
stata command: display invF(2,8, 0.95)
• Calculation of test statistic.
– We compute the following sums of squares:

108
Two way ANOVA
• Statistical decision
– Since our computed variance ratio, 20.91, is greater than
4.46, we reject the null hypothesis of no treatment effects
• ANOVA table

109
Two way ANOVA
• Conclusion
– We conclude that not all treatment effects are equal to zero,
or equivalently, that not all treatment means are equal
• P-value
– For this test p-value<0.005

110
Two way ANOVA

• Stata command and outputs


• Data structure treatment
1
Age group
1
Score
7
Treatmet 1 2 8
1=A 1 3 9
2=B 1 4 10
1 5 11
3=C
2 1 9
Age group 2 2 9
1= Under 20 2 3 9
2= 20 to 29 2 4 9
2 5 12
3= 30 to 39
3 1 10
4= 40 to 49 3 2 10
5= 50 and over 3 3 12
3 4 12
3 5 14

111
Two way ANOVA

112
Two way ANOVA
• Exercise:
A remotivation team in a psychiatric hospital conducted an experiment to
compare five methods for remotivating patients. Patients were grouped
according to level of initial motivation. Patients in each group were randomly
assigned to the five methods. At the end of the experimental period the patients
were evaluated by a team composed of a psychiatrist, a psychologist, a nurse,
and a social worker, none of whom was aware of the method to which patients
had been assigned. The team assigned each patient a composite score as a
measure of his or her level of motivation

113
Two way ANOVA
• Data

Do these data provide sufficient evidence to indicate a difference in mean


scores among methods?
Let α=0.05.

114
Repeated measure ANOVA

115
Repeated measure ANOVA
– A repeated measures design is one in which measurements
of the same variable are made on each subject on two or
more different occasions
• Used in a repeated measures design is a desire to control for
variability among subjects

• Help control for extraneous variation among subjects

• fewer subjects are needed for the repeated measures

• Can use small sample sizes

• Allows for study overtime

116
Repeated measure ANOVA

– Each individual received different treatment

– Repeated measure reduces variation due to difference of


subject across treatment programs

• Single-Factor Repeated Measures Design

– The repeated measures design in which one additional


factor is introduced into the experiment

117
Repeated measure ANOVA
• Assumptions
1. The subjects under study constitute a simple random
sample from a population of similar subjects.

2. Each observation is an independent simple random sample


of size 1 from each of kn populations, where n is the
number of subjects and k is the number of treatments to
which each subject is exposed

118
Repeated measure ANOVA
3. The kn populations have potentially different means, but
they all have the same variance.

4. The k treatments are fixed; that is, they are the only
treatments about which we have an interest in the current
situation. We do not wish to make inferences to some
larger collection of treatments.

5. There is no interaction between treatments and subjects;


that is, the treatment and subject effects are additive.

119
Repeated measure ANOVA
• The Model
– The model for the fixed-effects additive single-factor
repeated measures design is
xij = µ + βi + τj + εij
i= 1, 2, …, n; j = 1, 2, ... , k

120
Repeated measure ANOVA

• Spherical assumption
– the variances of the differences between all combinations
of related groups (levels) are equal

– Violated when the variances of the differences between all


combinations of related groups are not equal

121
Repeated measure ANOVA
• Violation of sphericity
– homogeneity of variances in a between-subjects ANOVA

– serious for the repeated measures ANOVA, with violation


increases the Type I error rate

– sphericity test for violation is very important

– corrections have been developed to produce a more valid


critical F-value

122
Repeated measure ANOVA
• The correction is achieved by estimating the degree to which
sphericity has been violated and applying a correction factor to
the degrees of freedom of the F-distribution

• Example

123
• Looking at our results, at first glance, it would appear that the
variances between the paired differences are not equal
(13.9 vs. 17.4 vs. 3.1); the variance of the difference between Time
2 and Time 3 is much less than the other two combinations.

• This might lead us to conclude that our data violates the


assumption of sphericity.

124
Testing for Sphericity

• Mauchly's Test of Sphericity


– is a formal way of testing the assumption of sphericity.

– Often failing to detect departures from sphericity in small


samples and over-detecting them in large samples, it is
nonetheless a commonly used test

125
Testing for Sphericity

• Mauchly's Test of Sphericity

– tests the null hypothesis that the variances of the


differences are equal.

– if Mauchly's Test of Sphericity is statistically significant


(p < .05), we can reject the null hypothesis and sphericity
has been violated.

126
Testing for Sphericity
• Correction for violation of spherity assumption
– applied to the degrees of freedom (df), such that a valid
critical F-value can be obtained
– the degree to which sphericity is present, or not, is
represented by a statistic called epsilon (ε).
– An epsilon of ε = 1 indicates that the condition of
sphericity is exactly met.
– The further epsilon decreases below 1 (i.e., ε < 1), the
greater the violation of sphericity

127
Lower-Bound Estimate
• The lowest value that epsilon (ε) can take is called the lower-
bound estimate (or the lower-bound adjustment) and is
calculated as:

• Lower bounder estimate (𝜀) =𝑘−1


1
, k is number of repeated
measure

128
Lower-Bound Estimate

• the greater the number of repeated measures, the greater the


potential for the violation of sphericity

• the lower-bound estimate used for correcting degrees of


freedom for the "worst case scenario".

• This provides a correction that is far too conservative


(incorrectly rejecting the null hypothesis).

129
Greenhouse-Geisser Correction

• The Greenhouse-Geisser procedure estimates epsilon (𝜀)Ƹ in


order to correct the degrees of freedom of the F-distribution
• Gives appropriate critical value for worst situation in which
assumptions are maximally violated

df𝑡𝑖𝑚𝑒 /𝑐𝑜𝑛𝑑𝑖𝑡𝑖𝑜𝑛 = 𝜺ො (k-1)

df𝑒𝑟𝑟𝑜𝑟 = 𝜺ො (k-1)(n-1)

130
Huynd-Feldt Correction

• estimates epsilon (𝜀)ǁ in order to correct the degrees of freedom


of the F-distribution
• is over conservative, especially for small sample sizes

df𝑡𝑖𝑚𝑒 /𝑐𝑜𝑛𝑑𝑖𝑡𝑖𝑜𝑛= 𝜺෤ (k-1)

df𝑒𝑟𝑟𝑜𝑟= 𝛆෤ (k-1)(n-1)

131
132
Repeated measure ANOVA

• Detecting assumption violations

• Bartlett’s test of sphericity

• Mauchly test for sphericity

• Doing an initial analysis of descriptive data gives the best


indication how variances change over time and how they
related to each other

133
Repeated measure ANOVA
• Example 1
Researchers examined subjects with chronic, nonspecific low back pain. In this
study, 18 of the subjects completed a survey questionnaire assessing physical
functioning at baseline, and after 1, 3, and 6 months. Table below shows the
data for these subjects who received a sham treatment that appeared to be
genuine osteopathic manipulation. Higher values indicate better physical
functioning.

134
Repeated measure ANOVA
The goal of the experiment was to determine if subjects would report
improvement over time even though the treatment they received would provide
minimal improvement. We wish to know if there is a difference in the mean
survey values among the four points in time.

135
Data

136
Repeated measure ANOVA
• Solution:
1. Data
2. Assumptions. We assume that the assumptions for the fixed-effects,
additive single-factor repeated measures design are met.
3. Hypotheses.
H0 : µB = µM1 = µM3 = µM6
H0: not all µ’s are equal
4. Test statistic
V.R == treatment MS/error MS.
5. Distribution of test statistic
– F with 4-1=3 numerator degrees of freedom and 71-3-
17=51denominator degrees of freedom
137
Repeated measure ANOVA
• Degree of freedom
N=72, s=18, a=4
– df between=4-1=3

– dfwithin=N-a=72-4=68

– dfsubjects=18-1=17

– dferror=dfwithin-dfsubject=68-17=51

– dftotal=N-1=72-1=71

138
Repeated measure ANOVA
6. Decision rule.
• Let . The critical value of F is 2.80 (obtained by
interpolation). Reject if computed V.R. is equal to or
greater than 2.80.
7. Calculation of test statistic

Stata comman for repeated measurement ANOVA

– anova score subject measument, repeated(measument)

139
Repeated measure ANOVA

140
Repeated measure ANOVA

• Example 2
– Researchers want to test a new anti-anxiety medication. they measured
the anxiety of 9 participants three times: once before taking the
medication, once one week after taking the medication, and once two
weeks after taking medication. Anxiety rated on a scale of 1-10, which
10 being “high anxiety” and 1 being “low anxiety. Are there any
difference between the three conditions using α=5%

141
Repeated measure ANOVA
• Steps
1. Data
2. Assumptions. We assume
that the assumptions for the
fixed-effects, additive
single-factor repeated
measures design are met.
3. Hypotheses.
H0: μbefore= μweek1= μweek2
HA: not all means are equal

142
Repeated measure ANOVA
4. Test statistic
V.R == treatment MS/error MS.
5. Distribution of test statistic
– F –statistics
– Calculating degree of freedom
N=27 S=9 a=3
– dfbetween=a-1=3-1=2
– dfwithin= N-a=27-3=24
– dfsubject= S-1=9-1=8
– dferror= dfwithin- dfsubject=24-8= 16
– dftotal=27-1=26

143
Repeated measure ANOVA
• Calculate test statisics4
σ σ 𝒂𝒊 𝟐 𝑻𝟐
• SSbetween= − , or
𝒔 𝑵
– Before sum=72, Week1 sum=61, Week2 sum=32
𝑻𝟐 𝟏𝟔𝟓𝟐
– T=165, = = 1008.33
𝑵 𝟐𝟕
𝟕𝟐𝟐+𝟔𝟏𝟐+𝟑𝟐𝟐 𝑻𝟐
– SSbetween= − =1103.22-1008.33=94.9
𝟗 𝑵

144
Repeated measure ANOVA
σ σ 𝒂 𝟐
• SSwithin=Y2- 𝒊
or
𝒔

σ 𝒀2= (92+…+82) +(72+…+82) +(42+…+82)

σ 𝒀2=1127-1103.22=23.78

145
Repeated measure ANOVA
σ σ 𝒔𝒊 𝟐 𝑻 𝟐
• SSsubject= - or
𝒂 𝑵
Subject 1 sum =20, Subject 2 sum =17, Subject 2 sum =15
Subject 4 sum =18, Subject 5 sum =20, Subject 6 sum =19,
Subject 7 sum =16, Subject 8 sum =18, Subject 9 sum =22

σ σ 𝒔𝒊 𝟐 202+172+152+182+202+192+162+182+222
• = =1021
𝒂 3
σ σ 𝒔𝒊 𝟐 𝑻𝟐
• - =1021-1005.33=15.67
𝒂 𝑵

146
Repeated measure ANOVA
SS df MS F
SSbetween 94.9 2 47.45 93.61
SSwithin 23.78 24 0.991
SSsubject 15.67 8 1.96
Sserror 8.11 16 0.51
Total 118.68 26 4.5646154

SSerror=SSwithin-SSsubject
=23.78-15.67 =8.11
SSTotal=SSbetween+ Sswithin
=94.9+23.78=118.68

147
Repeated measure ANOVA
Msbetween=94.9/2=47.4

M𝑺error= 8.11/16=0.506875

47.45
F= = 93.612824
0.506875

148
Repeated measure ANOVA
• Stata output:

149
Repeated measure ANOVA

150
THANK YOU
FOR
THANK YOU
FOR
!!
THANK YOU FOR YOUR ATTENTION!!

151

You might also like