Performing two-way ANOVA

Two-way ANOVA can be viewed as an extension of one-way ANOVA because the analysis covers more than two categorical variables rather than just one. In this recipe, we will discuss how to conduct two-way ANOVA in R.

Getting ready

Download the GDP dataset from the following link and ensure that you have installed R on your operating system: https://github.com/ywchiu/rcookbook/raw/master/chapter5/engineer.csv.

How to do it…

Perform the following steps to perform two-way ANOVA:

  1. First, load the engineer's salary data from engineer.csv:
    >engineer<-read.csv("engineer.csv", header = TRUE)
    
  2. Plot the two boxplots of the salary factor in regard to profession and region:
    >par(mfrow=c(1,2))
    >boxplot(Salary~Profession, data = engineer,xlab='Profession', ...

Get R for Data Science Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.