# Two-Way ANOVA using R

Nikki Kamouneh

Posted on
ANOVA R Two-Way

This tutorial is going to take the theory learned in our Two-Way ANOVA tutorial and walk through how to apply it using R. We will be using the Moore dataset from the carData package. This data frame consists of subjects in a “social-psychological experiment who were faced with manipulated disagreement from a partner of either of low or high status. The subjects could either conform to the partner’s judgment or stick with their own judgment.” (John Fox, Sanford Weisberg and Brad Price (2018). carData: Companion to Applied Regression Data Sets. R package version 3.0-2. https://CRAN.R-project.org/package=carData).

Start by loading the packages we’ll use.

library(tidyverse)
library(carData)
library(car)
library(emmeans)

Moore <- Moore %>%
mutate(
partner.status = factor(
partner.status,
levels = c("low", "high")
),
fcategory = factor(
fcategory,
levels = c("low", "medium", "high")
)
)

Depending on the package used to perform two-way ANOVA, R will default to either Type-I or Type-II sum of squares. To be consistent with output from SPSS, we’ll use Type-III sum of squares in this tutorial. An in-depth summary of the types of sum of squares can be found here.

We are interested in exploring an individuals conformity based on their partner’s status:

• Low Status
• High Status

We are also interested in exploring whether their F-score category (a measure of authoritarianism) affects outcomes or interacts with partner status. Our three treatment levels are:

• Low F-score
• Medium F-score
• High F-score

Our sample size is $$N = 45$$. First, let’s inspect the data for outliers or funky distributions. The following boxplot shows the distribution of scores on the conformity variable within each combination of partner.status and fcategory.

Moore %>%
ggplot(aes(x = fcategory, y = conformity, color = partner.status)) +
geom_boxplot() +
xlab("F-Score Category") +
ylab("Conformity") +
scale_color_discrete(name = "Partner Status")