This number is how many trees they pointlessly looked at again after already getting the fruit - it corresponds with memory errors.
E1 Revisits: Prepare the data
Read in the data and pre-process it.
Show the code
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 treee1 <- e1 %>%filter(fl>0)# remove the second (and any subsequent) *consecutive* duplicatese1 <- e1 %>%group_by(pp, rr, tb) %>%filter(is.na(tl !=lag(tl)) | tl !=lag(tl)) %>%ungroup()# remove trials where they failed to get 10 fruite1 <- e1 %>%group_by(pp, rr, tb) %>%mutate(max_fr =max(fr)) %>%ungroup() %>%filter(max_fr==10) %>%select(-c(ex, max_fr, te, tt, st, xx, yy, ll))# 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(e1$pp),rr=unique(e1$rr),tb=unique(e1$tb),fr=0 ) )e1 <-full_join(x=design, y=e1, by =join_by(pp, rr, tb, fr)) %>%group_by(pp, rr, tb) %>%arrange(pp, rr, tb, fr, tm, .by_group =TRUE) %>%replace_na(list(ix=0, tm=0, tl=0, fl=-1)) %>%ungroup()# annotate with revisite1 <- e1 %>%group_by(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)e1 <- e1 %>%select(pp, rr, tb, fr, isrv) %>%group_by(pp, rr, tb, fr) %>%summarise(nrv=sum(isrv)) %>%ungroup()# add the stage IVe1 <- e1 %>%mutate(st =ifelse(tb<=5, "early", "late") ) %>%select(pp,rr, st, tb, fr, nrv)# factorse1 <- e1 %>%mutate(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 == 10 which are all # constrained to be zeronrev_data_for_aov <- e1 %>%group_by(pp, rr, st, fr) %>%summarise(nrv=mean(nrv)) %>%filter(fr!=10) %>%mutate(fr=as_factor(fr)) %>%ungroup()# collapse over trials to stagesnrev_data_for_ggplot <- nrev_data_for_aov %>%group_by(pp, rr, st) %>%summarise(nrv=mean(nrv)) %>%ungroup()saveRDS(nrev_data_for_ggplot, "e1_nrevisits_plot_data.rds")
E1 Revisits: ANOVA
2 * 2 * 10
A 2x2x10 ANOVA with the within factors resource distribution (patchy, dispersed) and trial (early [mean trials 1-5], late [mean trials 6-10]) and number of fruit consumed (1-10)
pre.means = nrev_data_for_aov %>%group_by(fr, pp, st) %>%# average over resourcessummarise(mean.nrv=mean(nrv)) %>%group_by(fr, pp) %>%# average over stagesummarise(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, "E1 Nrevisits fruit means")