-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2WayANOVA.Rmd
47 lines (36 loc) · 1.24 KB
/
2WayANOVA.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
---
title: "2-way ANOVA"
author: "FMU Biology Department"
output: word_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## Analysis
This documents includes code for creating a data object in R, creating an informative plot, and running an 2-way Analysis of Variance (ANOVA).
```{r fullcode, eval=TRUE}
#Create data frame
dat1 = data.frame(rating = c(13,16,8,15,9,
29,35,24,27,32,
57,59,52,55,60),
city = c("Charleston","Charleston","Charleston","Charleston","Charleston",
"Columbia","Columbia","Columbia","Columbia","Columbia",
"Florence","Florence","Florence","Florence","Florence"),
politics = c("R","R","D","D","I",
"R","R","D","D","I",
"R","R","D","D","I"))
#Print data frame
dat1
#Create Boxplot
boxplot(dat1$rating~dat1$city,
ylab = "Rating (%)", xlab = "City")
#Create Boxplot
boxplot(dat1$rating~dat1$politics,
ylab = "Rating (%)", xlab = "Policital affiliation")
#ANOVA
res = aov(dat1$rating~dat1$city * dat1$politics)
#Display ANOVA results
summary(res)
#Tukey post-hoc comparisons
TukeyHSD(res)
```