Revisits

This number is how many trees they pointlessly looked at again after already getting the fruit - it corresponds with memory errors.

e2 Revisits: Prepare the data

Read in the data and pre-process it.

Show the code
e2 <- readRDS("002-00-e2-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
e2 <- e2 %>% filter(fl>0)

# remove the second (and any subsequent) *consecutive* duplicates
e2 <- e2 %>% 
  group_by(pp, rr, tb) %>% 
  filter(is.na(tl != lag(tl)) | tl != lag(tl)) %>% 
  ungroup()

# remove trials where they failed to get 14 fruit
e2 <- e2 %>%
  group_by(pp, rr, tb) %>%
  mutate(max_fr = max(fr)) %>%
  ungroup() %>%
  filter(max_fr==14) %>% 
  select(-c(ex, max_fr, st, xx, yy, ln)) 

# currently some trials don't have entries for fruit of zero
# these trials are where they found a fruit on the first tree
# We want to say that these were:
# number of revisits = 0 
# (not number of revisits = "a structural missing")
design <-
  tibble(
    expand.grid(
      pp=unique(e2$pp),
      rr=unique(e2$rr),
      tb=unique(e2$tb),
      fr=0
    )
  )
design <- 
  left_join(
    design, 
    e2 %>% group_by(pp) %>% summarise(ff=unique(ff)),
    join_by(pp)
    )
e2 <- 
  full_join(
    design, 
    e2,
    join_by(pp, rr, tb, fr, ff)
    ) %>% 
  arrange(pp, rr, tb, fr)

# annotate with revisit
e2 <- e2 %>% 
  group_by(ff, pp, rr, tb) %>% 
  mutate(isrv = duplicated(tl)) %>% 
  ungroup()  

# get number of revisits per fruit
# (is how many times they looked at a tree that 
#  they saw before on this trial on the way to 
#  getting this particular fruit)
e2 <- e2 %>% 
  select(ff, pp, rr, tb, fr, isrv) %>% 
  group_by(ff, pp, rr, tb, fr) %>% 
  summarise(nrv=sum(isrv)) %>% 
  ungroup()

# add the stage IV
e2 <- e2 %>% 
  mutate(
    st = ifelse(tb<=10, "early", "late")
  ) %>% 
  select(ff, pp, rr, st, tb, fr, nrv)

# factors
e2 <- e2 %>% 
  mutate(ff=as_factor(ff), pp=as_factor(pp), rr=as_factor(rr), st=as_factor(st)) %>% 
  ungroup()

# collapse over trials - what was the average number of revisits for this fruit,
# now that the absence of visits to trees while fr was zero contributes a zero
# not a structural missing. Also prune entries for fr == 14 which are all 
# constrained to be zero
nrev_data_for_aov <- e2 %>% 
  group_by(ff, pp, rr, st, fr) %>% 
  summarise(nrv=mean(nrv)) %>% 
  filter(fr!=14) %>% 
  mutate(fr=as_factor(fr)) %>% 
  ungroup()

# collapse over trials to yield a value for each fruit
nrev_data_for_ggplot <- e2 %>% 
  group_by(ff, pp, rr, fr) %>% 
  summarise(nrv=mean(nrv)) %>% 
  filter(fr!=14) %>% 
  mutate(fr=as_factor(fr)) %>% 
  ungroup()

saveRDS(nrev_data_for_ggplot, "e2_nrevisits_plot_data.rds")

e2 Revisits: ANOVA

2 x 2 * 2 * 10

A 2x2x2x10 ANOVA with the within factors resource distribution (patchy, dispersed) and trial (early [mean trials 1-5], late [mean trials 6-10]); between fading; and as dv number of fruit consumed (1-10)

Run the ANOVA

Show the code
options(contrasts=c("contr.sum","contr.poly"))
e2_revisits_ANOVA <- 
  ezANOVA(data=nrev_data_for_aov,
          dv=nrv,
          wid=pp,
          within=c(rr, st, fr),
          between=ff,
          type=3, 
          return_aov = TRUE)
Warning: Data is unbalanced (unequal N per group). Make sure you specified a
well-considered value for the type argument to ezANOVA().
Show the code
if("Sphericity Corrections" %in% names(e2_revisits_ANOVA)){
  corr=aovSphericityAdjustment(e2_revisits_ANOVA)$ANOVA %>% tibble()
} else {
  corr=e2_revisits_ANOVA$ANOVA %>% tibble()  
  }

Table the ANOVA.

Show the code
prettify_sphericity_3_way(
  aovSphericityAdjustment(e2_revisits_ANOVA), 
  "e2 NRevisits ANOVA")
e2 NRevisits ANOVA
Effect DFn DFd F p sig
ff 1 40 16.97 0.000 ***
rr 1 40 2.86 0.098
st 1 40 0.72 0.401
fr 1.2 49.6 21.63 0.000 ***
ff:rr 1 40 3.53 0.067
ff:st 1 40 1.35 0.252
ff:fr 1.2 49.6 8.87 0.003 **
rr:st 1 40 1.31 0.259
rr:fr 2.2 87.6 0.61 0.562
st:fr 2.6 105.7 0.92 0.422
ff:rr:st 1 40 0.13 0.718
ff:rr:fr 2.2 87.6 0.21 0.833
ff:st:fr 2.6 105.7 1.16 0.327
rr:st:fr 3.4 137.9 0.52 0.698
ff:rr:st:fr 3.4 137.9 0.91 0.449

Report the ANOVA

The effect of fading was F(1, 40) = 16.97, p<.001.

The effect of resources was F(1, 40) = 2.86, p=0.098.

The effect of stage was F(1, 40) = 0.72, p=0.401.

The effect of fruit was F(1.2, 49.6) = 21.63, p<.001.

The fruit x resources was F(2.2, 87.6) = 0.61, p=0.562.

e2 NRevisits: Plot

Fourteen points along the x axis, each participant contributes one point per cell, facet for fading

Show the code
ggplot(data=nrev_data_for_ggplot, aes(y=nrv, x=fr, group=rr, shape=rr, fill=rr)) +
  facet_wrap(~ff, nrow=2)+
  my_fgms_theme+
  ggtitle("(b): Revisits (memory errors)")+
  ylab("Revisits")+
  xlab("Trials")+
  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=3, position=pd)

e2 NRevisits: Stage means

Table means for fading

Show the code
frpremeans = nrev_data_for_aov %>% group_by(ff, pp, rr) %>%
  summarise(mu=mean(nrv)) %>%
  summarise(mu=mean(mu))
frmeans <- frpremeans %>%
  summarise(mean=mean(mu), sd=sd(mu))
prettify_means(frmeans, "e2 NRevisits stage means")
e2 NRevisits stage means
ff mean sd
fade 0.05 0.05
no_fade 0.15 0.10

e2 NRevisits: Fruit means

Show the code
pre.means = nrev_data_for_aov %>%
  group_by(fr, pp, st) %>%
  # average over resources
  summarise(mean.nrv=mean(nrv)) %>%
  group_by(fr, pp) %>%
  # average over stage
  summarise(mean.nrv=mean(mean.nrv))
ok.means = pre.means %>%
  group_by(fr) %>%
  summarise(mean=mean(mean.nrv), sd=sd(mean.nrv))
prettify_means(ok.means, "e2 Nrevisits fruit means")
e2 Nrevisits fruit means
fr mean sd
0 0.02 0.03
1 0.03 0.04
2 0.04 0.05
3 0.04 0.05
4 0.06 0.05
5 0.05 0.05
6 0.07 0.07
7 0.05 0.04
8 0.08 0.07
9 0.07 0.06
10 0.08 0.09
11 0.10 0.10
12 0.22 0.26
13 0.48 0.67