Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Introduction To Two-Way ANOVA

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

Introduction

R Exercises

Homework

Introduction

R Exercises

Homework

Introduction to Two-Way ANOVA


In a two-way analysis of variance we analyze the dependence

of a continuous response on two, cross-classied factors.

Two-Way Analysis of Variance: ANOVA


Dr. J. Kyle Roberts
Southern Methodist University Simmons School of Education and Human Development Department of Teaching and Learning

The factors can be experimental factors that are both of

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

Hypothesis Test in Two-Way ANOVA


Recall that the null hypothesis for a one-way ANOVA can be

How the Data are Analyzed in a Two-Way

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

two independent variables each with two levels.


In a full factorial setting, we would view this data as:

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

H0:M ainA : 1. = 1. = = j. H0:M ainB : .1 = .2 = = .k H0:ABInteraction : 11 = 12 = 21 = 22 = = jk


where j are the rows and k are the columns.

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

The Two-Way ANOVA Summary Table


Source Main A Main B ABInter. Error Total SS df kA 1 kB 1 dfA dfB dft dfA dfB dfAB n1 MS
SSA dfA SSB dfB SSAB dfAB SSe dfe

Two-Way ANOVA Practice


p 2
SSA SSt SSB SSt SSAB SSt

F
M SA M Se M SB M Se M SAB M Se

Fill in the Missing Values Below. Use pf to compute p.

The statistical signicance of F can be obtained by

Source Main A Main B ABinter Error Total

SS

df 5 4

MS

0.22 600 752 2 0.11 0.08 0.04

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

Fill in the Missing Values Below. Use pf to compute p.

are the df due to that eect and the dferror . Therefore, the df numerator could be dierent for each eect.

Source Main A Main B ABinter Error Total

SS 80

df

MS 40

22 437

Introduction

R Exercises

Homework

Introduction

R Exercises

Homework

Partitioning the Sum of Squares


J

Two-Way ANOVA Data


Read in a table using read.table which resides on this website

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

Structuring and viewing data

Program vs. Gender


> barplot(tapply(twoway$gre, list(twoway$program, twoway$gender), + mean), beside = T, col = rainbow(3))

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 ...

> table(twoway$gender, twoway$program)


1 2 3 1 8 8 8 2 8 8 8
10 0 5

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)

Running the Data


> m1 <- aov(gre ~ gender + program, twoway) > summary(m1)

32

twoway$program 3 1 2

mean of twoway$gre

gender program Residuals

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

> m2 <- aov(gre ~ gender * program, twoway) > summary(m2)


Df Sum Sq Mean Sq F value Pr(>F) gender 1 38.52 38.521 2.5839 0.11544 program 2 60.67 30.333 2.0347 0.14340 gender:program 2 112.67 56.333 3.7788 0.03097 Residuals 42 626.12 14.908

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")

> bartlett.test(gre ~ program * gender, twoway)


Bartlett test of homogeneity of variances data: gre by program by gender Bartletts K-squared = 6.5532, df = 2, p-value = 0.03776

> fligner.test(gre ~ gender * program, twoway)


Fligner-Killeen test of homogeneity of variances data: gre by gender by program Fligner-Killeen:med chi-squared = 1.6152, df = 1, p-value = 0.2038

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

Post Hoc Tests


> TukeyHSD(m2)$"gender:program"
2:1-1:1 1:2-1:1 2:2-1:1 1:3-1:1 2:3-1:1 1:2-2:1 2:2-2:1 1:3-2:1 2:3-2:1 2:2-1:2 1:3-1:2 2:3-1:2 1:3-2:2 2:3-2:2 2:3-1:3 diff -0.375 -0.250 -0.625 -1.000 5.125 0.125 -0.250 -0.625 5.500 -0.375 -0.750 5.375 -0.375 5.750 6.125 lwr -6.13810348 -6.01310348 -6.38810348 -6.76310348 -0.63810348 -5.63810348 -6.01310348 -6.38810348 -0.26310348 -6.13810348 -6.51310348 -0.38810348 -6.13810348 -0.01310348 0.36189652 upr 5.388103 5.513103 5.138103 4.763103 10.888103 5.888103 5.513103 5.138103 11.263103 5.388103 5.013103 11.138103 5.388103 11.513103 11.888103 p adj 0.99995875 0.99999450 0.99949105 0.99516934 0.10654536 0.99999983 0.99999450 0.99949105 0.06898988 0.99995875 0.99876887 0.08000676 0.99995875 0.05082404 0.03144884

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.

You might also like