+34 616 71 29 85 carsten@dataz4s.com

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

One-way ANOVA vs Two-way ANOVA tables

 

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:

3 sets of hypotheses in two-way ANOVA

 

 

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

 

The H0 for Factor a, rows: Gender

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

The H0 for Factor b, columns, Dosages

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

The H0 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:

Two-way ANOVA table

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 n: The groups must have the same sample size

 

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:

Two-way ANOVA data set for analysis

 

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:

Means table for sum of squares rows

 

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

Sum of Squares Columns

 

Step 4: Sum of Squares, Both. Interaction

Sum of Squares_ both. interaction

 

Step 5: Sum of Squares total

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:

Sum of Squares Error. Within

 

Step 7: Sum of Squares Error. Within

Degrees of freedom df

 

Step 8: Mean squares, test statistic and critical values

Mean squares, test statistic, critical F-values

 

 

Conclusions

Let’s recall our three null hypotheses:

Two-way ANOVA hypotheses sets

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

Two-way ANOVA in Excel

 

Learning statistics

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

 

Carsten Grube

Carsten Grube

Freelance Data Analyst

0 Comments

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

What they say

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