-
Notifications
You must be signed in to change notification settings - Fork 0
/
001-10-number-of-trees.Rmd
139 lines (118 loc) · 4.14 KB
/
001-10-number-of-trees.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
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
# Number of trees
Experiment 1
```{r e1_ntrees_setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
knitr::opts_chunk$set(fig.path='e1_figures/')
knitr::opts_chunk$set(fig.width=7, fig.height=5)
options(dplyr.summarise.inform=F)
library(tidyverse)
library(ez)
library(gt)
e1 <- readRDS("001-00-e1-data.RDS")
# remove things from the raw data to make it suitable for this particular analysis
# remove samples that did not look at a tree
e1 <- e1 %>%
filter(fl>0)
# remove the second (and any subsequent) *consecutive* duplicates
e1 <- e1 %>%
group_by(pp, rr, tb) %>% filter(is.na(tl != lag(tl)) | tl != lag(tl)) %>% ungroup()
# remove trials where they failed to get 10 fruit
e1 <- e1 %>%
group_by(pp, te) %>%
mutate(max_fr = max(fr)) %>%
ungroup() %>%
filter(max_fr==10)
e1_ntrees <-
e1 %>%
transmute(
pp = as_factor(pp),
trial = tb, # is 1 to 10 for each condition of "resources"
resources = factor(rr, levels=c("dispersed", "patchy"), labels=c("dispersed", "patchy")),
stage = as_factor(ifelse(tb<=5, "early", "late")),
index = ix,
tree = tl)
e1_ntrees_TRIAL_SUMS <-
e1_ntrees %>%
group_by(pp, resources, stage, trial) %>%
summarise(ntrees=n())
e1_ntrees_PARTICIPANT_MEANS <-
e1_ntrees_TRIAL_SUMS %>%
group_by(pp, resources, stage) %>%
summarise(mean_ntrees_per_stage = mean(ntrees))
options(contrasts=c("contr.sum","contr.poly"))
e1_ntrees_ANOVA <-
ezANOVA(data=e1_ntrees_PARTICIPANT_MEANS,
dv=mean_ntrees_per_stage,
wid=pp,
within=c(resources,stage),
type=3)
e1_ntrees_ANOVA_TABLE <-
e1_ntrees_ANOVA$ANOVA %>%
select(-ges) %>%
gt() %>%
tab_header(
title="Number of trees",
subtitle = "ANOVA table"
) %>%
fmt_number(
columns = c("F"),
rows=everything(),
decimals=2
) %>%
fmt_number(
columns = c("p"),
rows=everything(),
decimals=3
) %>%
cols_align(
columns=`p<.05`,
align="center"
)
gtsave(e1_ntrees_ANOVA_TABLE, "e1_tables/e1_ntrees_ANOVA.png")
# Two points along the x axis, each participant contributes one point per cell
pd <- position_dodge(0.1)
e1_ntrees_PLOT2 <-
ggplot(data=e1_ntrees_PARTICIPANT_MEANS, aes(x=stage, y=mean_ntrees_per_stage, group=resources, pch=resources, fill=resources)
) +
theme_bw()+
theme(aspect.ratio = 1, panel.grid=element_blank(), axis.title.y=element_text(angle=0,vjust=0.5,hjust=0.5))+
scale_fill_manual(name="Resource\ndistribution",values=c("white", "black")) +
scale_shape_manual(name="Resource\ndistribution",values=c(24,19)) +
stat_summary(fun.data = mean_cl_normal, geom = "errorbar", width=0.1, position=pd) +
stat_summary(fun = mean, geom = "line", position=pd) +
stat_summary(fun = mean, geom = "point", size=4, position=pd)+
ggtitle("Number of trees visited during a trial")+
ylab("Number\nof\nTrees")+
xlab("Trial")+
scale_x_discrete(labels=c("early\ntrials 1 to 5", "late\ntrials 6 to 10"))
ggsave("e1_plots/e1_ntrees_PLOT2.png")
```
```{r out.width="50%"}
knitr::include_graphics("e1_tables/e1_ntrees_ANOVA.png")
```
```{r out.width="75%"}
knitr::include_graphics("e1_plots/e1_ntrees_PLOT2.png")
```
----
Here we put tables of means for the significant effects.
```{r}
# The way we do these means and sds is first aggregate over trials so that each pp contributes one mean value for each condition. Then we take the mean of those means, and the sd of those means separately for each cell
e1_ntrees_TRIAL_SUMS_premeans <- e1_ntrees_TRIAL_SUMS %>%
ungroup() %>%
select(c(resources,pp,ntrees)) %>%
group_by(resources,pp) %>%
summarise(ppXconditionMean=mean(ntrees))
e1_ntrees_TRIAL_SUMS_means = e1_ntrees_TRIAL_SUMS_premeans %>%
summarise(mean=mean(ppXconditionMean), sd=sd(ppXconditionMean)) %>%
gt() %>% fmt_number(c(2,3), everything(), 2) %>% tab_options(table.align='left')
```
-----
```{r}
e1_ntrees_TRIAL_SUMS %>%
ungroup() %>%
select(c(stage,pp,ntrees)) %>%
group_by(stage,pp) %>%
summarise(ppXconditionMean=mean(ntrees)) %>%
summarise(mean=mean(ppXconditionMean), sd=sd(ppXconditionMean)) %>%
gt() %>% fmt_number(c(2,3), everything(), 2) %>% tab_options(table.align='left')
```