-
Notifications
You must be signed in to change notification settings - Fork 0
/
001-50-inter-tree-distance.Rmd
119 lines (99 loc) · 3.6 KB
/
001-50-inter-tree-distance.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
# Inter-tree distance
Experiment 1
```{r e1_inter_tree_distance_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 %>%
filter(is.na(tl != lag(tl)) | tl != lag(tl))
# 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_inter_tree_distance <-
e1 %>%
transmute(
pp = as_factor(pp),
trial = as.numeric(tb), # is 1 to 10 for each condition of "resources"
resources = factor(rr, levels=c("dispersed", "patchy"), labels=c("dispersed", "patchy")),
launch = factor(ll, levels=c("fruit", "not"), labels=c("launched_from_fruit", "launched_from_no_fruit")),
stage = as_factor(ifelse(trial<=5, "early", "late")),
xx = xx,
yy = yy,
index = ix)
# bear in mind that it needs to be done after reducing the data to valid tree-visits
e1_inter_tree_distance <- e1_inter_tree_distance %>%
group_by(pp, resources, trial) %>%
mutate(itdist = round(sqrt((lead(xx)-xx)^2 + (lead(yy)-yy)^2), 2))
e1_inter_tree_distance_TRIAL_VALUES <-
e1_inter_tree_distance %>%
group_by(pp, resources, stage, launch, trial) %>%
summarise(inter_tree_distance=mean(itdist, na.rm=TRUE))
e1_inter_tree_distance_PARTICIPANT_MEANS <-
e1_inter_tree_distance_TRIAL_VALUES %>%
group_by(pp, resources, stage, launch) %>%
summarise(mean_inter_tree_distance_per_stage = mean(inter_tree_distance))
options(contrasts=c("contr.sum","contr.poly"))
e1_inter_tree_distance_ANOVA <-
ezANOVA(data=e1_inter_tree_distance_PARTICIPANT_MEANS,
dv=mean_inter_tree_distance_per_stage,
wid=pp,
within=c(resources,stage,launch),
type=3)
e1_inter_tree_distance_ANOVA_TABLE <-
e1_inter_tree_distance_ANOVA$ANOVA %>%
select(-ges) %>%
gt() %>%
tab_header(
title="Inter-tree Distance",
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_inter_tree_distance_ANOVA_TABLE, "e1_tables/e1_inter_tree_distance_ANOVA.png")
# Two points along the x axis, each participant contributes one point per cell
e1_inter_tree_distance_PLOT2 <-
ggplot(
data=e1_inter_tree_distance_PARTICIPANT_MEANS,
aes(x=stage, y=mean_inter_tree_distance_per_stage, group=resources, pch=resources, fill=resources)
) +
facet_wrap(~launch)+
theme_bw()+
theme(aspect.ratio = 1, panel.grid=element_blank())+
scale_fill_manual(values=c("white", "black")) +
scale_shape_manual(values=c(24,19)) +
stat_summary(fun.data = mean_cl_normal, geom = "errorbar", width=0.2, position=position_dodge(0.25)) +
stat_summary(fun = mean, geom = "line", position=position_dodge(0.25)) +
stat_summary(fun = mean, geom = "point", size=3, position=position_dodge(0.25))
ggsave("e1_plots/e1_inter_tree_distance_PLOT2.png")
```
```{r out.width="50%"}
knitr::include_graphics("e1_tables/e1_inter_tree_distance_ANOVA.png")
```
```{r out.width="100%"}
knitr::include_graphics("e1_plots/e1_inter_tree_distance_PLOT2.png")
```