# Two-way ANOVA

Two-way ANOVA explores **if the means of two different factors are all equal**. We wish to determine if Factor A or Factor B or both Factor A and Factor B have significant effect on the scores.

## One-way ANOVA vs. Two-way ANOVA

In one-way ANOVA we only analyze for only one factor. In the example below, this factor has 3 levels (0mg, 50mg, 100mg).

In two-way ANOVA one more factor is added. In this example, this factor has 2 levels (Women, Men).

Factor A and Factor B can also be seen labeled:

- ‘Factor 1’ and ‘Factor 2’
- ‘Rows’ and ‘Columns’
- ‘Sample’ and ‘Columns’

In two-way ANOVA we wish to determine if Factor A or Factor B or both Factor A and Factor B have significant effect on the scores. So, this leads to three null hypotheses.

## How to interpret the null hypotheses?

In two-way ANOVA we make inference on the effect of three factor combinations: Factor A, Factor B and the interaction of Factor A and Factor B, so A, B and AB. Therefore, we have three **sets** of hypotheses:

**If, for example, we reject all three null hypotheses, we would say: **

### The H_{0} for Factor a, rows: Gender

There is sufficient evidence that Factor A (gender) does have significant effect on the scores

### The H_{0} for Factor b, columns, Dosages

There is sufficient evidence that Factor B (dosage) does have significant effect on the scores

### The H_{0} for Interaction (Factor a & b):

There is sufficient evidence that the interaction between Factor A and Factor B (gender and dosage) does have significant effect on the scores.

Below, I we will do a practical example.

## The 2-way ANOVA table

The two-way ANOVA table summarizes the values needed for our hypothesis tests:

The **F-crit** is the critical value of the **F-table** and the **F-score** is our **test statistic**. As we know it from other test statistic inferences, we reject the null hypothesis when our test statistic falls beyond the critical value.

## Assumptions

**Normally distributed**: Samples are drawn from populations that are normally or approximately normally distributed**Independence**: The samples must be independent**Equal variances**: The population variances must be equal**Same**: The groups must have the same sample size*n*

## The story

In the following we will run through the calculations for each of the values in the table using a fictive example:

Statisticians in a researchers’ group are to make a test for a new medication. They measure the relevant levels in 18 participants on 0mg, 50mg and 100mg dosages. Apart from the effect of the different dosages, the researchers also wish to know if the medication has different effects on gender. Consequently, they divide data as per gender (Factor A) and dosage (Factor B). The effect is measured as to a rating scale of 1-10, being the 10 maximum effect.

## Calculations of Sum of Squares (SS)

Statistical software returns the two-way ANOVA table without having to do any calculations and knowing how to interpret the table we can make the inferences. But understanding the values and the calculations can contribute to a deeper understanding of the procedure. So, let’s go through it:

### Different procedures and notations

In ANOVA there are different notations and different procedures to calculate the values. I will be following this procedure:

- Define hypotheses and alpha
- Calculate test statistics:
- Step 1): Sample data
- Step 2): Means table for SS Factor A
- Step 3): SS Factor B
- Step 4): SS Both. Interaction
- Step 5): SS Total
- Step 6): SS Error. Within
- Step 7): MS, F-values, critical values

- State results
- State conclusions

## Calculation of test statistics

Above, we defined our three hypotheses and we displayed sample data, so next step is to calculate test statistics. I find it helpful to see the formulas and calculations together with the different tables:

### Step 1: Sample data

We start off by displaying sample data:

### Step 2: Means table for Sum of Squares, Factor A (rows)

We calculate the sum of squares for factor A (SSA), with a means table:

### Step 3: Sum of Squares, Factor B (columns)

### Step 4: Sum of Squares, Both. Interaction

### Step 5: Sum of Squares total

### Step 6: Sum of Squares Error. Within

As shown in the two-way ANOVA table, the SS for Error (Within), can be calculated through the values that we already have:

### Step 7: Sum of Squares Error. Within

### Step 8: Mean squares, test statistic and critical values

** **

## Conclusions

Let’s recall our three null hypotheses:

We will now hold our **F-score** up against the respective **critical F-values** and we will interpret our **p-values** for factor 1 and 2 and for the **interaction of both**:

### Factor A, rows (gender)

Our F-score (2.5) falls beyond the critical F-value with a p-value of 0.1398. The estimated p-value shows nearly 14% probability of obtaining as extreme a test statistic as the one we have obtained (2.5), assuming that the null hypothesis is true.

We fail to reject H_{0} and conclude that the two means between gender are equal. There is evidence supporting the null hypothesis.

### Factor B, columns (treatment)

Our F-score (76.3) falls ‘way’ beyond the critical F-value (3.9) with a p-value close to zero. So, there is nearly no probability that we will obtain a result as extreme as the one we obtained (76.3) assuming that all three means should be equal.

We therefore reject H_{0}. There is clear evidence that not all three means are equal.

### Both factors, (gender and treatment)

Our F-score (9.1) falls also ‘way’ beyond the critical F-value (3.9) with a p-value of 0.0039. There is approximately 0.39% probability that we will obtain a result as extreme as the one we obtained (9.1) assuming that there is no interaction between gender and dosage.

We reject H_{0}. There is strong evidence that an interaction between gender and dosage is present.

** **

## Multiple comparison procedures

When we reject H0 in ANOVA, we can only say that not all means are equal. But that means that some of the means can still be equal. For example, if we are comparing four means, and we reject, we three out of the four means can still be equal.

In Multiple comparison, I list a few procedures that help solve for this.

** **

** **

## Two-way ANOVA in Excel

In Excel we can use **Data >> Data Analysis >> Anova: Two-Factor With Replication**. The ‘With Replication’ is when the participants do more than one sample. In our case, there 6 persons and each take three (>1) dosages. Therefore, we choose ‘With Replication’.

The groups, or each row factor must have the **same number of rows**. In our example, ‘Women’ has three rows and ‘Men’ has three rows.

** **

## Learning statistics

Learning material that I find very useful for two-way ANOVA:

- Per Bruun Brockhoff, DTU (Danish Technical University). Classroom session with screencast, using R:
- Video 19:18: 11A: A two way ANOVA intro
- Video 7:35: Two way ANOVA model
- … more videos in the series

- Statslectures (video 9:09). Great! Showing color illustrated tables, formulas and calculations together in one screen. That has been the inspiration for my page. Also, although based on my own mini dataset, I have used the idea behind the story: Factorial ANOVA, Two independent factors
- Eugene O’Loughlin (video 6:45): How To… Perform a two-way ANOVA in Excel 2013
- Pytolearn (text page): Two Way ANOVA (factorial)

#### Carsten Grube

Freelance Data Analyst

##### Normal distribution

##### Confidence intervals

##### Simple linear regression, fundamentals

##### Two-sample inference

##### ANOVA & the F-distribution

# 22 Comments

### Submit a Comment

You must be logged in to post a comment.

+34 616 71 29 85

Call me

Spain: Ctra. 404, km 2, 29100 Coín, Malaga

...........

Denmark: c/o Musvitvej 4, 3660 Stenløse

**Drop me a line**

*What are you working on just now? Can I help you, and can you help me? *

**About me**

Learning statistics. Doing statistics. Freelance since 2005. Dane. Living in Spain. With my Spanish wife and two children.

**Connect with me**

**What they say**

20 years in sales, analysis, journalism and startups. See what my customers and partners say about me.

Wow, that’s what I was seeking for, what a material! present here at this web site, thanks admin of this site.

Admiring the commitment you put into your blog and detailed information you offer.

It’s good to come across a blog every once in a while that

isn’t the same old rehashed material. Wonderful

read! I’ve saved your site and I’m adding your RSS feeds to my Google account.

Howdy, i read your blog from time to time and i

own a similar one and i was just curious if you get a lot of spam remarks?

If so how do you stop it, any plugin or anything you can advise?

I get so much lately it’s driving me crazy so any support is very much

appreciated.

Genuinely when someone doesn’t know afterward its up to other people that

they will assist, so here it takes place.

I have read so many articles or reviews on the topic of the

blogger lovers however this article is actually a pleasant article, keep

it up.

Keep on working, great job!

Lendo este artigo você vai assimilar o motivo pelo que nosso sistema de estresse ainda parecido estar retardado

no tempo. https://sites.google.com/view/orlistat-emagrece-bula-preco/in%C3%ADcio

I am genuinely grateful to the owner of this web site who has shared this enormous article at here.

I’m not that much of a online reader to be honest but your blogs really nice, keep it

up! I’ll go ahead and bookmark your site to come back later.

All the best

Hi there friends, good piece of writing and good arguments commented

at this place, I am truly enjoying by these.

I pay a visit everyday some web sites and information sites to read articles or reviews, except

this web site offers feature based articles.

I just could not leave your site prior to suggesting that I actually enjoyed the usual info an individual provide

to your guests? Is gonna be back continuously to check up on new posts

I have to thank you for the efforts you have put in penning this

site. I really hope to see the same high-grade content by you in the

future as well. In fact, your creative writing abilities has motivated me

to get my very own website now 😉

I was wondering if you ever thought of changing the page layout of your website?

Its very well written; I love what youve got

to say. But maybe you could a little more

in the way of content so people could connect with it better.

Youve got an awful lot of text for only having one or 2 pictures.

Maybe you could space it out better?

Your method of telling all in this article is actually fastidious, all

be capable of easily understand it, Thanks a lot.

Hmm is anyone else encountering problems with the images on this

blog loading? I’m trying to determine if its a problem on my end or if it’s the blog.

Any responses would be greatly appreciated.

Awesome blog you have here but I was curious if you knew of any message boards

that cover the same topics discussed here?

I’d really love to be a part of online community where I can get responses from other experienced people that share

the same interest. If you have any recommendations, please let me know.

Thanks!

Hey there! I could have sworn I’ve been to this blog before but after reading through some

of the post I realized it’s new to me. Anyways, I’m definitely glad I found it and I’ll be

bookmarking and checking back often!

I’m curious to find out what blog platform you have been using?

I’m having some minor security issues with my latest site and

I’d like to find something more risk-free. Do you have any solutions?

Good day! I know this is kinda off topic but I was wondering if you knew where I could get a captcha plugin for

my comment form? I’m using the same blog platform as yours and I’m having trouble finding one?

Thanks a lot!

What i don’t realize is actually how you are no longer really

much more neatly-preferred than you might be now.

You are very intelligent. You know thus considerably in relation to this subject, produced me individually believe it from

numerous numerous angles. Its like men and women don’t seem to be fascinated except it’s something to do

with Woman gaga! Your own stuffs great. Always deal with

it up!

When some one searches for his vital thing, thus he/she wishes to be available that in detail,

therefore that thing is maintained over here.