Introduction To Two-Way ANOVA
Introduction To Two-Way ANOVA
Introduction To Two-Way ANOVA
R Exercises
Homework
Introduction
R Exercises
Homework
interest or they can be one experimental factor and one blocking factor.
A blocking factor is a known source of variability, such as the
subject or, more generally, the experimental unit. We expect this factor to account for a substantial portion of the variability in the response. We wish to control for this variability but are not interested in comparing the particular levels of this factor.
A cross-classied experiment is said to be balanced if every
pair of conditions occurs the same number of times. You can check with the xtabs function.
Introduction
R Exercises
Homework
Introduction
R Exercises
Homework
written as: H0 : Y 1 = Y 2 = Y 3
For the two-way ANOVA, we have the potential to test three For heuristic purposes, suppose that we have a dataset with
separate hypothesis tests: one for each way and one for the interaction eect. We do not have to test all 3, but if we do, we refer to this as a full factorial ANOVA.
These hypotheses are:
Levels of First IV
a1 a2 Mean
Levels of Second IV b1 b2 11 12 X X 21 22 X X .1 .2 X X
Mean 1. X 2. X X
Introduction
R Exercises
Homework
Introduction
R Exercises
Homework
F
M SA M Se M SB M Se M SAB M Se
SS
df 5 4
MS
computing the F -critical value. Determining statistical signicance follows the same pattern for the t test only we have two sources of df : between and within.
For the two-way ANOVA, the df needed for testing that eect
are the df due to that eect and the dferror . Therefore, the df numerator could be dierent for each eect.
SS 80
df
MS 40
22 437
Introduction
R Exercises
Homework
Introduction
R Exercises
Homework
SSA = nK
j =1 K
)2 j. X (X .k X )2 (X j. X .k X )2 jk X (X
at http://faculty.smu.edu/kyler/courses/7311/twoway1.txt
Make sure that you include header=T > head(twoway)
1 2 3 4 5 6 gender program gre 2 1 24 2 1 27 2 1 33 2 1 25 2 1 26 2 1 30
SSB = nJ
k=1 K J
SSAB = n
k=1 j =1 K J
SSError =
k=1 j =1 i=1 K J n
jk )2 (Xijk X )2 (Xijk X
k=1 j =1 i=1
> str(twoway)
data.frame: 48 $ gender : int $ program: int $ gre : int obs. of 3 variables: 2 2 2 2 2 2 2 2 1 1 ... 1 1 1 1 1 1 1 1 1 1 ... 24 27 33 25 26 30 22 29 33 26 ...
SST otal =
Introduction
R Exercises
Homework
Introduction
R Exercises
Homework
data.frame: 48 obs. of 3 variables: $ gender : Factor w/ 2 levels "1","2": 2 2 2 2 2 2 2 2 1 1 ... $ program: Factor w/ 3 levels "1","2","3": 1 1 1 1 1 1 1 1 1 1 ... $ gre : int 24 27 33 25 26 30 22 29 33 26 ...
15
20
25
30
> twoway$gender <- factor(twoway$gender) > twoway$program <- factor(twoway$program) > str(twoway)
Introduction
R Exercises
Homework
Introduction
R Exercises
Homework
Interaction Plot
> interaction.plot(twoway$gender, twoway$program, twoway$gre)
32
twoway$program 3 1 2
mean of twoway$gre
Df Sum Sq Mean Sq F value Pr(>F) 1 38.52 38.521 2.2942 0.1370 2 60.67 30.333 1.8066 0.1762 44 738.79 16.791
30
31
27
28
29
1 twoway$gender
Introduction
R Exercises
Homework
Introduction
R Exercises
Homework
Testing Assumptions
> bartlett.test(gre ~ gender * program, twoway)
Bartlett test of homogeneity of variances data: gre by gender by program Bartletts K-squared = 3.865, df = 1, p-value = 0.0493 Tables of means Grand mean 27.85417 gender gender 1 2 26.958 28.750
Investigation of Means
> model.tables(m2, "means")
program program 1 2 3 27.187 26.938 29.437 gender:program program gender 1 2 3 1 27.38 27.12 26.37 2 27.00 26.75 32.50
Introduction
R Exercises
Homework
Introduction
R Exercises
Homework
In-Class Assignment
Run a two-way ANOVA with the following dataset
GT
Regular
Special Ed.
Teaching Method 1 2 3 40 32 30 36 29 35 38 36 33 24 20 18 21 29 26 20 25 26 22 20 18 18 18 14 16 19 19
Introduction
R Exercises
Homework
Take-Home Assignment
1. Create a dataset of no less than 20 people with two categorical/grouping/independent variables and one dependent variable. Make the dataset a 4x2 design. Create the dataset in such a way that the main eect for the rst way is not statistically signicant, the main eect for the second way is not statistically signicant, but the interaction eect is statistically signicant. 2. Create a dataset of no less than 20 people with two categorical/grouping/independent variables and one dependent variable. Make the dataset a 4x2 design. Create the dataset in such a way that the main eect for the rst way is statistically signicant, the main eect for the second way is statistically signicant, but the interaction eect is not statistically signicant.