generated from nmfs-opensci/NOAA-quarto-simple
-
Notifications
You must be signed in to change notification settings - Fork 32
/
7_More_ANOVAs.qmd
186 lines (137 loc) · 5.63 KB
/
7_More_ANOVAs.qmd
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
---
title: "More ANOVAs"
---
<!-- COMMENT NOT SHOW IN ANY OUTPUT: Code chunk below sets overall defaults for .qmd file; these inlcude showing output by default and looking for files relative to .Rpoj file, not .qmd file, which makes putting filesin different folders easier -->
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
knitr::opts_knit$set(root.dir = rprojroot::find_rstudio_root_file())
```
Remember you should
- add code chunks by clicking the *Insert Chunk* button on the toolbar
or by pressing *Ctrl+Alt+I* to answer the questions!
- **render** your file to produce a markdown version that you can see!
- save your work often
- **commit** it via git!
- **push** updates to github
## Overview
This practice reviews the [More ANOVAs
lecuture](https://jsgosnell.github.io/cuny_biostats_book/content/chapters/More_ANOVAs.html){target="_blank"}.
## Examples
### If interaction is significant
Following the memory example from class, read in and check data
```{r}
memory <- read.table("http://www.statsci.org/data/general/eysenck.txt", header = T,
stringsAsFactors = T)
str(memory)
```
Let's put younger level first
```{r}
library(plyr)
memory$Age <- relevel(memory$Age, "Younger")
```
and graph
```{r}
library(Rmisc)
function_output <- summarySE(memory, measurevar="Words", groupvars =
c("Age", "Process"), na.rm = T)
library(ggplot2)
ggplot(function_output, aes(x=Age, y=Words,color=Process,
shape = Process)) +
geom_line(aes(group=Process, linetype = Process), size=2) +
geom_point(size = 5) +
ylab("Words remembered")+
xlab("Age") +
ggtitle("Process type interacts with age to impact memory")+
theme(axis.title.x = element_text(face="bold", size=28),
axis.title.y = element_text(face="bold", size=28),
axis.text.y = element_text(size=20),
axis.text.x = element_text(size=20),
legend.text =element_text(size=20),
legend.title = element_text(size=20, face="bold"),
plot.title = element_text(hjust = 0.5, face="bold", size=32))
```
There appears to be some interactions. Let' build a model
```{r}
memory_interactions <- lm(Words ~ Age * Process, memory)
```
and check assumptions.
```{r}
par(mfrow=c(2,2))
plot(memory_interactions)
```
These appear to be met, so look at output
```{r}
library(car)
Anova(memory_interactions, type = "III")
```
Since interaction is significant, analyze subsets. For example,
```{r}
memory_interactions_young <- lm(Words ~ Process, memory[memory$Age == "Younger",])
plot(memory_interactions_young)
Anova(memory_interactions_young, type = "III")
```
There is a significant difference in words recalled based on process,
but why? Investigate with post-hoc tests.
```{r}
library(multcomp)
comp_young <- glht(memory_interactions_young, linfct = mcp(Process = "Tukey"))
summary(comp_young)
```
### Blocking example
Following feather color example from class:
```{r}
# more than 2? ####
feather <- read.csv("https://raw.githubusercontent.com/jsgosnell/CUNY-BioStats/master/datasets/wiebe_2002_example.csv", stringsAsFactors = T)
str(feather)
set.seed(25)
special <- data.frame(Bird = LETTERS[1:16], Feather = "Special",
Color_index= feather[feather$Feather == "Typical", "Color_index"] +
.3 +runif(16,1,1)*.01)
feather <- merge(feather, special, all = T)
Anova(lm(Color_index ~ Feather + Bird, data=feather), type= "III")
library(multcomp)
compare <- glht(lm(Color_index ~ Feather + Bird, data=feather), linfct = mcp("Feather" = "Tukey"))
summary(compare)
```
```{r, error=T}
#note comparison doesn't work
Anova(lm(Color_index ~ Feather * Bird, data=feather), type= "III")
```
## Practice
### 1
A survey was conducted to see if athletes and non-athletes deal with
anger in the same way. Data is \@
angry \<-
read.csv("<https://docs.google.com/spreadsheets/d/e/2PACX-1vSaawG37o1ZUEs1B4keIJpZAY2c5tuljf29dWnzqQ0tHNCzfbz85AlWobYzBQ3nPPXJBLP-FWe4BNZB/pub?gid=1784556512&single=true&output=csv>",
stringsAsFactors = T)
and more information is at
<http://onlinestatbook.com/case_studies/angry_moods.html>.
Focus on the following variables:
Sports 1 = athletes, 2 = non-athletes Gender 1 = males, 2 = females
Expression (AE) index of general anger expression: (Anger-Out) +
(Anger-In) - (Control-Out) - (Control-In) + 48
Is there any evidence that gender or athlete status impact how anger is
expressed?
### 2
A professor carried out a long-term study to see how various factors
impacted pulse rate before and after exercise. Data can be found at
<http://www.statsci.org/data/oz/ms212.txt> With more info at
<http://www.statsci.org/data/oz/ms212.html>. Is there evidence that
frequency of exercise (Exercise column) and gender impact change in
pulse rate for students who ran (Ran column = 1)?
### 3
Data from Valdez et al 2023 is available \@
<https://docs.google.com/spreadsheets/d/e/2PACX-1vT2gaLu6pyRMlcbzarn3ej4bFmT_iHvrlNWJYSdrsLdUWIjcJi7rU11-ipvYpGnqD9qLDnbhNd2sDUW/pub?gid=1707080634&single=true&output=csv>.
Import it into to R and
- determine how the snail grazing and nitrogen levels impact number of
flowering shoots ( Shoot.density..m2)
- construct a plot to showcase your analysis
### 4
Find an example of a factorial ANOVA from a paper that is related to
your research or a field of interest. Make sure you understand the connections between the methods,
results, and graphs. Briefly answer the following questions
- What was the dependent variable?
- What were the independent variables?
- Was the interaction significant?
- If so, how did they interpret findings
- If not, were the main effects significant?