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:
First, load the engineer's salary data from engineer.csv:
>engineer<-read.csv("engineer.csv", header = TRUE)
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', ylab = "Salary",main='Salary v.s. Profession') >boxplot(Salary~Region, data = engineer,xlab='Region', ylab = "Salary",main='Salary v.s. Region')
Also...