Preliminaries

Load libraries

library(knitr)       #for R Markdown
library(MASS)        #for negative binomial glm (glm.nb)
library(lme4)        #for mixed models
library(emmeans)     #for posthoc
library(car)         #for Anova
library(survival)    #for survival analysis
library(coxme)
library(rptR)        #for repeatability analysis
library(merTools)    #for BLUPs REsim()
library(MuMIn)       #for model selection (dredge)
library(ggfortify)   #for plotting survival analysis
library(ggsignif)    #for labeling significance in ggplots
library(tidyverse)   #for data processing, put last to avoid function masking

Data processing

Read dataset, correct variable types, and derive variables.

data.raw <- read.csv("data_maze_062725.csv",                 
                 # to avoid reading errors
                 fileEncoding="UTF-8-BOM", na.strings = "")

data <- data.raw %>% 
  #correct factors and dates variable types
  mutate_at(c("ID","sex","assayer","trial","shelter_YN","shelter_quadrant"), as.factor) %>%
  mutate_at(c("found_date","morph_date","assay_date"), lubridate::mdy) %>%
  
  #derive variables
  mutate(
    
    #life history variables
    lat_meta = as.numeric(morph_date - found_date),
    age = as.numeric(assay_date - morph_date),
         
    #performance variables     
    lat_shelter_from_movement = as.numeric(lat_shelter - lat_move),
    lines_rate = lines_crossed/lat_trial,
    grids_rate = grids_explored/lat_trial,
    
    #for survival analysis and plotting
    shelter_10 = recode(shelter_YN, "Y" = 1, "N" = 0),
    move_10 = ifelse(lat_move==lat_trial, 0, 1)
    
    )

Make an aggregrate version of the dataset by frog ID

data_ind <- data %>%
  group_by(ID) %>%
  summarise(lat_move_avg = mean(lat_move),
            lat_shelter_avg = mean(lat_shelter),
            lat_shelter_mov_avg = mean(lat_shelter_from_movement),
            lat_shelter_improv = lat_shelter[trial == 1] - lat_shelter[trial == 5],
            lines_rate_avg = mean(lines_rate),
            grids_rate_avg = mean(grids_rate),
            prop_complete = sum(shelter_YN == "Y")/n(),
            found_date = mean(found_date),
            morph_date = mean(morph_date), 
            age = mean(age),
            lat_meta = mean(lat_meta)
            )

Personality

Are behaviors repeatable across trials and different among individuals?

Short summary

  • Boldness: marginally repeatable, did not change across trial.
  • Activity: repeatable, more active in later trials.
  • Exploration: repeatable, more exploratory in later trials.

Analysis: Repeatability

  • rpt{rptR}: Repeatability Estimation
  • P_permut: p-value from permutation test (more robust?)
  • LRT_P: p-value from likelihood ratio test

Boldness

rpt_result <- rpt(lat_move ~ (1 | ID), 
                  grname = "ID", 
                  data = data, 
                  datatype = "Gaussian", 
                  nboot = 1000, 
                  npermut = 1000)
## Bootstrap Progress:
## Permutation Progress for ID :
summary(rpt_result)$rpt %>% kable(digits = 3)
R SE 2.5% 97.5% P_permut LRT_P
rpt 0.109 0.082 0 0.291 0.07 0.105

Activity

rpt_result <- rpt(lines_rate ~ (1 | ID), 
                  grname = "ID", 
                  data = data, 
                  datatype = "Gaussian", 
                  nboot = 1000, 
                  npermut = 1000)
## Bootstrap Progress:
## Permutation Progress for ID :
summary(rpt_result)$rpt %>% kable(digits = 3)
R SE 2.5% 97.5% P_permut LRT_P
rpt 0.366 0.114 0.13 0.564 0.001 0

Exploration

rpt_result <- rpt(grids_rate ~ (1 | ID), 
                  grname = "ID", 
                  data = data, 
                  datatype = "Gaussian", 
                  nboot = 1000, 
                  npermut = 1000)
## Bootstrap Progress:
## Permutation Progress for ID :
summary(rpt_result)$rpt %>% kable(digits = 3)
R SE 2.5% 97.5% P_permut LRT_P
rpt 0.275 0.107 0.066 0.473 0.003 0.001

Analysis: changes across trials

boldness

mod <- coxme(Surv(lat_move, move_10) ~ as.numeric(trial) + (1 | ID), 
                     data = data %>% filter(trial != "6") %>% droplevels())

summary(mod)$coefficients
##                         coef exp(coef)   se(coef)    z         p
## as.numeric(trial) 0.01426566  1.014368 0.07661957 0.19 0.8522972

activity

mod <- lmer(sqrt(lines_rate) ~ as.numeric(trial) + (1|ID),
            data = data %>% filter(trial != "6") %>% droplevels())

summary(mod)$coefficients
##                     Estimate  Std. Error t value
## (Intercept)       0.08612302 0.028738428 2.99679
## as.numeric(trial) 0.02195858 0.006335003 3.46623
Anova(mod)
## Analysis of Deviance Table (Type II Wald chisquare tests)
## 
## Response: sqrt(lines_rate)
##                    Chisq Df Pr(>Chisq)    
## as.numeric(trial) 12.015  1  0.0005278 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

exploration

mod <- lmer(sqrt(grids_rate) ~ as.numeric(trial) + (1|ID),
            data = data %>% filter(trial != "6") %>% droplevels())

summary(mod)$coefficients
##                     Estimate  Std. Error  t value
## (Intercept)       0.07905419 0.026350603 3.000090
## as.numeric(trial) 0.01790594 0.006107426 2.931831
Anova(mod)
## Analysis of Deviance Table (Type II Wald chisquare tests)
## 
## Response: sqrt(grids_rate)
##                    Chisq Df Pr(>Chisq)   
## as.numeric(trial) 8.5956  1    0.00337 **
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Spaghetti Plots

Some visible pattern but also looks pretty chaotic!

fig_spg_boldness <-
  ggplot(data %>% filter(trial != 6), 
         aes(x = trial, y = lat_move, group = ID, color = ID)) +
  geom_line(alpha = 0.9, size = 1) +
  labs(x = "Trial number", y = "Latency to Move(s)") +
  
  scale_color_manual(values = rev(hcl.colors(20, palette = "Mako")),
                     name = "ID") +
  
  theme_classic(base_size = 15) +
  theme(legend.position = "none") + 
  scale_y_log10()


fig_spg_activity <-
  ggplot(data %>% filter(trial != 6), 
         aes(x = trial, y = lines_rate, group = ID, color = ID)) +
  geom_line(alpha = 0.9, size = 1) +
  labs(x = "Trial number", y = "# Lines crossed / Trial time (s)") +
  
  scale_color_manual(values = rev(hcl.colors(20, palette = "Mako")),
                     name = "ID") +
  
  theme_classic(base_size = 15) +
  theme(legend.position = "none")+ 
  scale_y_log10()


fig_spg_exploration <-
  ggplot(data %>% filter(trial != 6), 
         aes(x = trial, y = grids_rate, group = ID, color = ID)) +
  geom_line(alpha = 0.9, size = 1) +
  labs(x = "Trial number", y = "# Grids explored / Trial time (s)") +
  
  scale_color_manual(values = rev(hcl.colors(20, palette = "Mako")),
                     name = "ID") +
  
  theme_classic(base_size = 15) +
  theme(legend.position = "none")+ 
  scale_y_log10()
egg::ggarrange(fig_spg_boldness, fig_spg_activity, fig_spg_exploration,
               nrow = 3,
               labels = c("A","B","C"))

Box plots - by individual

Ordered by exploration median

fig_box_boldness <- 
  ggplot(data %>% filter(trial != 6), 
       aes(x = fct_reorder(ID, log10(grids_rate)),
           y = lat_move)) +
  geom_boxplot(aes(fill = fct_reorder(ID, log10(grids_rate))),
               alpha = 0.8) +
  geom_jitter(width = 0.2, alpha = 0.5) +
  
  scale_fill_manual(values = rev(hcl.colors(20, palette = "Mako"))) +
  
  labs(x = "Frog ID", y = "Latency to Move (s)") +
  guides(fill = "none")+ 
  theme_classic(base_size = 15)+ 
  scale_y_log10()


fig_box_activity <- 
  ggplot(data %>% filter(trial != 6), 
       aes(x = fct_reorder(ID, log10(grids_rate), .fun = median),
           y = lines_rate)) +
  geom_boxplot(aes(fill = fct_reorder(ID, log10(grids_rate), .fun = median)),
               alpha = 0.8) +
  geom_jitter(width = 0.2, alpha = 0.5) +
  
  scale_fill_manual(values = rev(hcl.colors(20, palette = "Mako"))) +
  
  labs(x = "Frog ID", y = "# Lines crossed / Trial time (s)") +
  guides(fill = "none")+ 
  theme_classic(base_size = 15)+ 
  scale_y_log10()


fig_box_exploration <- 
  ggplot(data %>% filter(trial != 6), 
       aes(x = fct_reorder(ID, log10(grids_rate), .fun = median),
           y = grids_rate)) +
  geom_boxplot(aes(fill = fct_reorder(ID, log10(grids_rate), .fun = median)),
               alpha = 0.8) +
  geom_jitter(width = 0.2, alpha = 0.5) +
  
  scale_fill_manual(values = rev(hcl.colors(20, palette = "Mako"))) +
  
  labs(x = "Frog ID", y = "# Grids explored / Trial time (s)") +
  guides(fill = "none")+ 
  theme_classic(base_size = 15)+ 
  scale_y_log10()
egg::ggarrange(fig_box_boldness, fig_box_activity, fig_box_exploration,
               nrow = 3,
               labels = c("A","B","C"))

Box plot - by trial

fig_box_boldness_trial <- 
  ggplot(data %>% filter(trial != 6), 
       aes(x = trial,
           y = lat_move,
           fill = trial)) +
  geom_boxplot(alpha = 0.8) +
  geom_jitter(width = 0.2, alpha = 0.5) +
  
  scale_fill_manual(values = rev(hcl.colors(5, palette = "Mako"))) +
  
  labs(x = "Trial number", y = "Latency to Move (s)") +
  guides(fill = "none")+ 
  theme_classic(base_size = 15)+ 
  scale_y_log10()


fig_box_activity_trial <- 
  ggplot(data %>% filter(trial != 6), 
       aes(x = trial,
           y = lines_rate,
           fill = trial)) +
  geom_boxplot(alpha = 0.8) +
  geom_jitter(width = 0.2, alpha = 0.5) +
  
  scale_fill_manual(values = rev(hcl.colors(5, palette = "Mako"))) +
  
  labs(x = "Trial number", y = "# Lines crossed / Trial time (s)") +
  guides(fill = "none")+ 
  theme_classic(base_size = 15)+ 
  scale_y_log10()


fig_box_exploration_trial <- 
  ggplot(data %>% filter(trial != 6), 
       aes(x = trial,
           y = grids_rate,
           fill = trial)) +
  geom_boxplot(alpha = 0.8) +
  geom_jitter(width = 0.2, alpha = 0.5) +
  
  scale_fill_manual(values = rev(hcl.colors(5, palette = "Mako"))) +
  
  labs(x = "Trial number", y = "# Grids explored / Trial time (s)") +
  guides(fill = "none")+ 
  theme_classic(base_size = 15)+ 
  scale_y_log10()
egg::ggarrange(fig_box_boldness_trial, fig_box_activity_trial, fig_box_exploration_trial,
               nrow = 3,
               labels = c("A","B","C"))

BLUPs

Best Linear Unbiased Predictors (BLUPs)

Notes: WORK IN PROGRESS - think more about the use of BLUPs

Probably not useful on its own, but can be used as derived index of personality tendencies?

model: personality variable ~ 1 + (1|ID)

the fixed effect is the overall mean

the random effects (BLUPs) are the individual frog’s offset, and can be interpreted as “personality score” of an individual in the population being analyzed.

Boldness

#fit model
mod <- lmer(lat_move ~ 1 + (1 | ID), 
            data = data %>% filter(trial != 6))


# extract BLUPs with confidence intervals
blup_ci <- REsim(mod, n.sims = 1000) 

fig_blup_boldness <-
  ggplot(blup_ci, aes(x = reorder(groupID, mean), y = mean)) +
  geom_point(size = 3) +
  geom_errorbar(aes(ymin = mean - sd, ymax = mean + sd), width = 0.2) +  # 1 SE
  geom_hline(yintercept = 0, linetype = "dashed", color = "gray50") +
  coord_flip() +
  labs(
    x = "Frog ID",
    y = "Boldness BLUPs"
    ) +
  theme_classic(base_size = 15)

Activity

#fit model
mod <- lmer(lines_rate ~ 1 + (1 | ID), 
            data = data %>% filter(trial != 6))


# extract BLUPs with confidence intervals
blup_ci <- REsim(mod, n.sims = 1000) 

fig_blup_activity <-
  ggplot(blup_ci, aes(x = reorder(groupID, mean), y = mean)) +
  geom_point(size = 3) +
  geom_errorbar(aes(ymin = mean - sd, ymax = mean + sd), width = 0.2) +  # 1 SE
  geom_hline(yintercept = 0, linetype = "dashed", color = "gray50") +
  coord_flip() +
  labs(
    x = "Frog ID",
    y = "Activity BLUPs"
    ) +
  theme_classic(base_size = 15)

Exploration

#fit model
mod <- lmer(grids_rate ~ 1 + (1 | ID), 
            data = data %>% filter(trial != 6))


# extract BLUPs with confidence intervals
blup_ci <- REsim(mod, n.sims = 1000) 

fig_blup_exploration <-
  ggplot(blup_ci, aes(x = reorder(groupID, mean), y = mean)) +
  geom_point(size = 3) +
  geom_errorbar(aes(ymin = mean - sd, ymax = mean + sd), width = 0.2) +  # 1 SE
  geom_hline(yintercept = 0, linetype = "dashed", color = "gray50") +
  coord_flip() +
  labs(
    x = "Frog ID",
    y = "Exploration BLUPs"
    ) +
  theme_classic(base_size = 15)
egg::ggarrange(fig_blup_boldness, fig_blup_activity, fig_blup_exploration,
               nrow = 1,
               labels = c("A","B","C"))

Behavioral Syndrome

Are different personality axes correlated?

Short summary

Data suggest behavioral syndrome among the three personality axes

  • boldness and activity is positively correlated
  • boldness and exploration is marginally, positively correlated
  • activity and exploration is positively correlated

Statistical Analyses

boldness-activity

mod_boldness_activity <- lmer(lines_rate ~ lat_move + (1|ID),
                              data = data)

summary(mod_boldness_activity)$coefficients
##                  Estimate   Std. Error   t value
## (Intercept)  4.731390e-02 1.042800e-02  4.537199
## lat_move    -2.411226e-05 1.014544e-05 -2.376661
Anova(mod_boldness_activity)
## Analysis of Deviance Table (Type II Wald chisquare tests)
## 
## Response: lines_rate
##           Chisq Df Pr(>Chisq)  
## lat_move 5.6485  1    0.01747 *
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

boldness-exploration

mod_boldness_exploration <- lmer(grids_rate ~ lat_move + (1|ID),
                              data = data)

summary(mod_boldness_exploration)$coefficients
##                  Estimate   Std. Error   t value
## (Intercept)  3.712475e-02 9.446547e-03  3.929981
## lat_move    -1.864109e-05 1.037335e-05 -1.797017
Anova(mod_boldness_exploration)
## Analysis of Deviance Table (Type II Wald chisquare tests)
## 
## Response: grids_rate
##           Chisq Df Pr(>Chisq)  
## lat_move 3.2293  1    0.07233 .
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

activity-exploration

mod_activity_exploration <- lmer(grids_rate ~ lines_rate + (1|ID),
                              data = data)

summary(mod_activity_exploration)$coefficients
##                 Estimate  Std. Error   t value
## (Intercept) -0.005804678 0.002093981 -2.772078
## lines_rate   0.936983299 0.025753056 36.383383
Anova(mod_activity_exploration)
## Analysis of Deviance Table (Type II Wald chisquare tests)
## 
## Response: grids_rate
##             Chisq Df Pr(>Chisq)    
## lines_rate 1323.8  1  < 2.2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Correlation plots - raw value

fig_boldness_activity <- 
  ggplot(data, aes(x = lat_move, y = lines_rate)) +
  geom_point(color = "black", size = 2) +
  geom_smooth(method = lm, alpha = 0.2, color = "SteelBlue", fill = "SteelBlue")+
  
  xlab("Latency to move (s)") +
  ylab("# Lines crossed / Trial time (s)") +
  
  theme_bw(base_size = 15)+
  theme(panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        aspect.ratio=1)

fig_boldness_exploration <- 
  ggplot(data, aes(x = lat_move, y = grids_rate)) +
  geom_point(color = "black", size = 2) +
  geom_smooth(method = lm, alpha = 0.2, color = "SteelBlue", fill = "SteelBlue")+
  
  xlab("Latency to move (s)") +
  ylab("# Grids explored / Trial time (s)") +
  
  theme_bw(base_size = 15)+
  theme(panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        aspect.ratio=1)

fig_activity_exploration <- 
  ggplot(data, aes(x = lines_rate, y = grids_rate)) +
  geom_point(color = "black", size = 2) +
  geom_smooth(method = lm, alpha = 0.2, color = "SteelBlue", fill = "SteelBlue")+
  
  xlab("# Lines crossed / Trial time (s)") +
  ylab("# Grids explored / Trial time (s)") +
  
  theme_bw(base_size = 15) +
  theme(panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        aspect.ratio=1)
egg::ggarrange(fig_boldness_activity, fig_boldness_exploration, fig_activity_exploration,
               nrow = 1,
               labels = c("A","B","C"))

Correlation Plots - log axes

fig_boldness_activity_log <- fig_boldness_activity + scale_x_log10() + scale_y_log10()
fig_boldness_exploration_log <- fig_boldness_exploration + scale_x_log10() + scale_y_log10()
fig_activity_exploration_log <- fig_activity_exploration + scale_x_log10() + scale_y_log10()
egg::ggarrange(fig_boldness_activity_log, fig_boldness_exploration_log, fig_activity_exploration_log,
               nrow = 1,
               labels = c("A","B","C"))

Correlation Plots - by individual

fig_boldness_activity_ind <- 
  ggplot(data_ind, aes(x = lat_move_avg, y = lines_rate_avg)) +
  
  # for overlaying trial level data - doesn't look good on the plot though
  # geom_point(data = data, aes(x = lat_move, y = lines_rate),
  #            color = "grey80", size = 1) +
  
  geom_point(color = "black", size = 2) +
  geom_smooth(method = lm, alpha = 0.2, color = "SteelBlue", fill = "SteelBlue")+
  
  xlab("Latency to move (s)") +
  ylab("# Lines crossed / Trial time (s)") +
  
  theme_bw(base_size = 15)+
  theme(panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        aspect.ratio=1)+
  scale_x_log10() + scale_y_log10()

fig_boldness_exploration_ind <- 
  ggplot(data_ind, aes(x = lat_move_avg, y = grids_rate_avg)) +
  geom_point(color = "black", size = 2) +
  geom_smooth(method = lm, alpha = 0.2, color = "SteelBlue", fill = "SteelBlue")+
  
  xlab("Latency to move (s)") +
  ylab("# Grids explored / Trial time (s)") +
  
  theme_bw(base_size = 15)+
  theme(panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        aspect.ratio=1)+
  scale_x_log10() + scale_y_log10()

fig_activity_exploration_ind <- 
  ggplot(data_ind, aes(x = lines_rate_avg, y = grids_rate_avg)) +
  geom_point(color = "black", size = 2) +
  geom_smooth(method = lm, alpha = 0.2, color = "SteelBlue", fill = "SteelBlue")+
  
  xlab("# Lines crossed / Trial time (s)") +
  ylab("# Grids explored / Trial time (s)") +
  
  theme_bw(base_size = 15)+
  theme(panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        aspect.ratio=1)+
  scale_x_log10() + scale_y_log10()
egg::ggarrange(fig_boldness_activity_ind, fig_boldness_exploration_ind, fig_activity_exploration_ind,
               nrow = 1,
               labels = c("A","B","C"))

Spatial Learning

Do frogs solve maze quicker and with less error over time?

Short summary

Frogs get to shelter faster in later trials compared to earlier trials. However, they made the same amount of errors.

Analysis

Latency to shleter

Treat trial as factor

coef: Log hazard ratio for that trial vs reference (trial 1)

mod_survival<- coxme(Surv(lat_shelter, shelter_10) ~ trial + (1 | ID), 
                     data = data %>% filter(trial != "6") %>% droplevels())

summary(mod_survival)$coefficients
##            coef exp(coef)  se(coef)    z           p
## trial2 1.131759  3.101108 0.6335911 1.79 0.074056915
## trial3 1.825024  6.202942 0.6382057 2.86 0.004241537
## trial4 1.575429  4.832814 0.6103238 2.58 0.009842896
## trial5 2.017205  7.517282 0.6337719 3.18 0.001458303

Overall effect of trial

mod_survival_0 <- coxme(Surv(lat_shelter, shelter_10) ~ (1 | ID), 
                     data = data %>% filter(trial != "6") %>% droplevels())

anova(mod_survival, mod_survival_0)
## Analysis of Deviance Table
##  Cox model: response is  Surv(lat_shelter, shelter_10)
##  Model 1: ~trial + (1 | ID)
##  Model 2: ~(1 | ID)
##    loglik  Chisq Df P(>|Chi|)   
## 1 -167.98                       
## 2 -175.31 14.663  4  0.005454 **
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Treat trial as numeric
mod_survival<- coxme(Surv(lat_shelter, shelter_10) ~ as.numeric(trial) + (1 | ID), 
                     data = data %>% filter(trial != "6") %>% droplevels())

summary(mod_survival)$coefficients
##                        coef exp(coef)  se(coef)    z           p
## as.numeric(trial) 0.3818918  1.465054 0.1161116 3.29 0.001005417

Number of wrong turns

mod <- glmer(wrong_turns ~ as.numeric(trial) + (1 | ID), 
             family = poisson,
             data = data %>% filter(trial != 6, path_seq != 1),
             control = glmerControl(optimizer = "bobyqa", optCtrl = list(maxfun = 2e5)))
summary(mod)
## Generalized linear mixed model fit by maximum likelihood (Laplace
##   Approximation) [glmerMod]
##  Family: poisson  ( log )
## Formula: wrong_turns ~ as.numeric(trial) + (1 | ID)
##    Data: data %>% filter(trial != 6, path_seq != 1)
## Control: glmerControl(optimizer = "bobyqa", optCtrl = list(maxfun = 2e+05))
## 
##      AIC      BIC   logLik deviance df.resid 
##    245.5    252.4   -119.8    239.5       71 
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -1.3594 -0.7187 -0.2431  0.5664  3.0120 
## 
## Random effects:
##  Groups Name        Variance Std.Dev.
##  ID     (Intercept) 0.1833   0.4281  
## Number of obs: 74, groups:  ID, 19
## 
## Fixed effects:
##                   Estimate Std. Error z value Pr(>|z|)  
## (Intercept)        0.42561    0.24193   1.759   0.0785 .
## as.numeric(trial) -0.01966    0.06507  -0.302   0.7626  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr)
## as.nmrc(tr) -0.805

Spagetti plot - latency

  ggplot(data %>% filter(trial != 6), 
         aes(x = trial, y = lat_shelter, group = ID, color = ID)) +
  geom_line(alpha = 0.9, size = 1) +
  labs(x = "Trial number", y = "Latency to Shelter (s)") +
  
  scale_color_manual(values = rev(hcl.colors(20, palette = "Mako")),
                     name = "ID") +
  
  theme_classic(base_size = 15) +
  theme(legend.position = "none") + 
  scale_y_log10()

Boxplot - wrong turns

  ggplot(data %>% filter(trial != 6, lines_crossed > 0), 
       aes(x = trial,
           y = wrong_turns,
           fill = trial)) +
  geom_boxplot(alpha = 0.8) +
  geom_jitter(width = 0.1, height = 0, alpha = 0.5) +
  
  scale_fill_manual(values = rev(hcl.colors(5, palette = "Mako"))) +
  
  labs(x = "Trial number", y = "Number of wrong turns") +
  guides(fill = "none")+ 
  theme_classic(base_size = 15)+
  theme(legend.position = "none") 

Accumulations plot

data_plot <- 
  survfit(Surv(lat_shelter, shelter_10) ~ trial,
          data = data %>% filter(trial != "6")) %>%  #filter out the accidental 6th trials
  fortify(surv.connect = TRUE) #make into a dataframe

fig_shelter_lat <- 
  
  ggplot(data_plot, aes(time, 1-surv, color = strata)) +
  
  #survival plot
  geom_step(linewidth = 1) +
  
  # axes and legends
  labs(x = "Time since start of trial (s)", y = "Proportion Frogs in Shelter") +
  
  scale_color_manual(values = rev(hcl.colors(7, palette = "BuPu")[1:5]),
                     name = "Trial number") +
  
  scale_y_continuous(expand = c(0,0), limit = c(0,0.61),
                     labels = scales::percent) +
  
  # adjust element themes
  theme_classic(base_size = 15)

fig_shelter_lat

ggsave("debug.png", width = 8, height = 4, dpi = 300)

Spatial Learning vs Personality

Are spatial learning ability correlated with personality?

Short summary

Frogs solve the maze faster when they are bolder, more active, and more exploratory. No correlation of spatial learning ability with any personality axes measured.

Analysis: trial correlations

mod <- coxme(Surv(lat_shelter_from_movement, shelter_10) ~ lat_move   + (1|ID), 
            data = data %>% filter(trial %in% 1:5))

summary(mod)
## Mixed effects coxme model
##  Formula: Surv(lat_shelter_from_movement, shelter_10) ~ lat_move + (1 |      ID) 
##     Data: data %>% filter(trial %in% 1:5) 
## 
##   events, n = 43, 100
## 
## Random effects:
##   group  variable       sd variance
## 1    ID Intercept 1.461049 2.134664
##                   Chisq    df         p   AIC   BIC
## Integrated loglik 21.88  2.00 1.777e-05 17.88 14.35
##  Penalized loglik 63.21 15.19 8.140e-08 32.82  6.07
## 
## Fixed effects:
##                coef  exp(coef)   se(coef)     z     p
## lat_move -0.0003426  0.9996574  0.0005804 -0.59 0.555
mod <- coxme(Surv(lat_shelter_from_movement, shelter_10)  ~  lines_rate   + (1|ID), 
            data = data %>% filter(trial %in% 1:5))

summary(mod)
## Mixed effects coxme model
##  Formula: Surv(lat_shelter_from_movement, shelter_10) ~ lines_rate + (1 |      ID) 
##     Data: data %>% filter(trial %in% 1:5) 
## 
##   events, n = 43, 100
## 
## Random effects:
##   group  variable       sd variance
## 1    ID Intercept 1.170296 1.369592
##                    Chisq   df p   AIC   BIC
## Integrated loglik  89.03  2.0 0 85.03 81.51
##  Penalized loglik 121.95 12.9 0 96.15 73.43
## 
## Fixed effects:
##                 coef exp(coef)  se(coef)    z        p
## lines_rate 3.835e+01 4.532e+16 5.370e+00 7.14 9.18e-13
mod <- coxme(Surv(lat_shelter_from_movement, shelter_10)  ~  grids_rate  + (1|ID), 
            data = data %>% filter(trial %in% 1:5))

summary(mod)
## Mixed effects coxme model
##  Formula: Surv(lat_shelter_from_movement, shelter_10) ~ grids_rate + (1 |      ID) 
##     Data: data %>% filter(trial %in% 1:5) 
## 
##   events, n = 43, 100
## 
## Random effects:
##   group  variable        sd  variance
## 1    ID Intercept 0.8328909 0.6937072
##                   Chisq    df p   AIC   BIC
## Integrated loglik 106.3  2.00 0 102.3 98.82
##  Penalized loglik 130.3 10.68 0 108.9 90.10
## 
## Fixed effects:
##                 coef exp(coef)  se(coef)    z       p
## grids_rate 5.632e+01 2.892e+24 7.783e+00 7.24 4.6e-13

Analysis: proportion completed

mod <- lm(prop_complete ~ lat_move_avg, data = data_ind)
summary(mod)
## 
## Call:
## lm(formula = prop_complete ~ lat_move_avg, data = data_ind)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.55543 -0.23182  0.01185  0.19333  0.58511 
## 
## Coefficients:
##                Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   0.6289361  0.1118112   5.625 2.45e-05 ***
## lat_move_avg -0.0005976  0.0002451  -2.438   0.0253 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.3319 on 18 degrees of freedom
## Multiple R-squared:  0.2483, Adjusted R-squared:  0.2065 
## F-statistic: 5.946 on 1 and 18 DF,  p-value: 0.02534
mod <- lm(prop_complete ~ lines_rate_avg, data = data_ind)
summary(mod)
## 
## Call:
## lm(formula = prop_complete ~ lines_rate_avg, data = data_ind)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.40689 -0.22548 -0.04316  0.22950  0.44737 
## 
## Coefficients:
##                Estimate Std. Error t value Pr(>|t|)    
## (Intercept)     0.20413    0.07884   2.589 0.018509 *  
## lines_rate_avg  5.65085    1.30870   4.318 0.000414 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.2683 on 18 degrees of freedom
## Multiple R-squared:  0.5088, Adjusted R-squared:  0.4815 
## F-statistic: 18.64 on 1 and 18 DF,  p-value: 0.0004143
mod <- lm(prop_complete ~ grids_rate_avg, data = data_ind)
summary(mod)
## 
## Call:
## lm(formula = prop_complete ~ grids_rate_avg, data = data_ind)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.39312 -0.25601 -0.00618  0.28196  0.39970 
## 
## Coefficients:
##                Estimate Std. Error t value Pr(>|t|)    
## (Intercept)     0.23581    0.07783   3.030 0.007200 ** 
## grids_rate_avg  6.16074    1.52906   4.029 0.000787 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.2776 on 18 degrees of freedom
## Multiple R-squared:  0.4742, Adjusted R-squared:  0.445 
## F-statistic: 16.23 on 1 and 18 DF,  p-value: 0.0007871

Analysis: improvements

Learning-Boldness

mod<- lm(lat_shelter_improv ~ lat_move_avg, data = data_ind)

summary(mod)$coefficients
##                 Estimate  Std. Error    t value   Pr(>|t|)
## (Intercept)  763.7362879 320.0255320  2.3864855 0.02819759
## lat_move_avg  -0.5481131   0.7014942 -0.7813509 0.44475226

Learning-activity

mod<- lm(lat_shelter_improv ~ lines_rate_avg, data = data_ind)

summary(mod)
## 
## Call:
## lm(formula = lat_shelter_improv ~ lines_rate_avg, data = data_ind)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -2004.51  -480.85   -86.47   848.36  1118.78 
## 
## Coefficients:
##                Estimate Std. Error t value Pr(>|t|)
## (Intercept)       463.4      280.8   1.650    0.116
## lines_rate_avg   2899.6     4661.8   0.622    0.542
## 
## Residual standard error: 955.7 on 18 degrees of freedom
## Multiple R-squared:  0.02104,    Adjusted R-squared:  -0.03335 
## F-statistic: 0.3869 on 1 and 18 DF,  p-value: 0.5417

Learning-exploration

mod<- lm(lat_shelter_improv ~ grids_rate_avg, data = data_ind)

summary(mod)
## 
## Call:
## lm(formula = lat_shelter_improv ~ grids_rate_avg, data = data_ind)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -2026.30  -531.62   -86.72   891.21  1107.29 
## 
## Coefficients:
##                Estimate Std. Error t value Pr(>|t|)  
## (Intercept)       524.4      270.0   1.942    0.068 .
## grids_rate_avg   1703.9     5305.6   0.321    0.752  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 963.1 on 18 degrees of freedom
## Multiple R-squared:  0.005697,   Adjusted R-squared:  -0.04954 
## F-statistic: 0.1031 on 1 and 18 DF,  p-value: 0.7518

Figure: improvement

For non-significant correlations, fitted line removed

fig_boldness_improv <-
  ggplot(data_ind,
         aes(x = lat_move_avg, y = lat_shelter_improv)) +
  geom_point(color = "black", size = 2) +
  # geom_smooth(method = lm, alpha = 0.2, color = "SteelBlue", fill = "SteelBlue")+
  
  xlab("Latency to move (s)") +
  ylab("Latency to shelter [day 1 - day 5]") +
  
  theme_bw(base_size = 15)+
  theme(panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        aspect.ratio=1)

fig_activity_improv <-
  ggplot(data_ind,
         aes(x = lines_rate_avg, y = lat_shelter_improv)) +
  geom_point(color = "black", size = 2) +
  # geom_smooth(method = lm, alpha = 0.2, color = "SteelBlue", fill = "SteelBlue")+
  
  xlab("# Lines crossed / Trial time (s)") +
  ylab("Latency to shelter [day 1 - day 5]") +
  
  theme_bw(base_size = 15)+
  theme(panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        aspect.ratio=1)

fig_exploration_improv <-
  ggplot(data_ind,
         aes(x = grids_rate_avg, y = lat_shelter_improv)) +
  geom_point(color = "black", size = 2) +
  # geom_smooth(method = lm, alpha = 0.2, color = "SteelBlue", fill = "SteelBlue")+
  
  xlab("# Grids explored / Trial time (s)") +
  ylab("Latency to shelter [day 1 - day 5]") +
  
  theme_bw(base_size = 15)+
  theme(panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        aspect.ratio=1)
egg::ggarrange(fig_boldness_improv, fig_activity_improv, fig_exploration_improv,
               nrow = 1,
               labels = c("A","B","C"))

Pace of Life Syndrome

Are personality and spatial learning ability correlated with life history traits?

Short summary

Overall, no strong evidence of POLS in personality

  • Time to metamorphosis is marginally correlated with boldness, but not activity or exploration

  • Frogs that metamorphosed faster are bolder.

  • Age at trial is marginally correlated with activity, but not boldness or exploration

  • Frogs that are older at the time of trial are more active.

Personality vs Life History

Analyses

Boldness-Meta time

mod<- lmer(lat_move ~ lat_meta + (1|ID), data = data%>% filter(trial %in% 1:5)%>% filter(ID != "M020"))
summary(mod)$coefficients
##               Estimate Std. Error   t value
## (Intercept) -696.20484 540.848687 -1.287245
## lat_meta      15.08576   7.842506  1.923590
Anova(mod)
## Analysis of Deviance Table (Type II Wald chisquare tests)
## 
## Response: lat_move
##           Chisq Df Pr(>Chisq)  
## lat_meta 3.7002  1    0.05441 .
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
mod <- lm (lat_move_avg ~ lat_meta, data = data_ind %>% filter(ID != "M020"))
summary(mod)
## 
## Call:
## lm(formula = lat_move_avg ~ lat_meta, data = data_ind %>% filter(ID != 
##     "M020"))
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -414.81 -210.28  -54.03  179.79  718.61 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)  
## (Intercept)  -693.52     542.71  -1.278   0.2185  
## lat_meta       15.01       7.87   1.907   0.0735 .
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 296.2 on 17 degrees of freedom
## Multiple R-squared:  0.1763, Adjusted R-squared:  0.1278 
## F-statistic: 3.638 on 1 and 17 DF,  p-value: 0.07352

Activity-Meta time

mod<- lmer(lines_rate ~ lat_meta + (1|ID),
                              data = data %>% filter(trial %in% 1:5)%>% filter(ID != "M020"))

summary(mod)$coefficients
##                 Estimate  Std. Error    t value
## (Intercept) 3.757068e-02 0.089948195 0.41769238
## lat_meta    4.751074e-05 0.001304282 0.03642674
Anova(mod)
## Analysis of Deviance Table (Type II Wald chisquare tests)
## 
## Response: lines_rate
##           Chisq Df Pr(>Chisq)
## lat_meta 0.0013  1     0.9709
mod <- lm (lines_rate_avg ~ lat_meta, data = data_ind %>% filter(ID != "M020"))
summary(mod)
## 
## Call:
## lm(formula = lines_rate_avg ~ lat_meta, data = data_ind %>% filter(ID != 
##     "M020"))
## 
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -0.038635 -0.034098 -0.004885  0.014849  0.172238 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)
## (Intercept) 3.807e-02  9.007e-02   0.423    0.678
## lat_meta    3.783e-05  1.306e-03   0.029    0.977
## 
## Residual standard error: 0.04916 on 17 degrees of freedom
## Multiple R-squared:  4.936e-05,  Adjusted R-squared:  -0.05877 
## F-statistic: 0.0008392 on 1 and 17 DF,  p-value: 0.9772

Exploration-Meta time

mod<- lmer(grids_rate ~ lat_meta + (1|ID),
                              data = data %>% filter(trial %in% 1:5)%>% filter(ID != "M020"))

summary(mod)$coefficients
##                  Estimate  Std. Error    t value
## (Intercept)  0.0455403114 0.079959267  0.5695439
## lat_meta    -0.0001942665 0.001159439 -0.1675521
Anova(mod)
## Analysis of Deviance Table (Type II Wald chisquare tests)
## 
## Response: grids_rate
##           Chisq Df Pr(>Chisq)
## lat_meta 0.0281  1     0.8669
mod <- lm (grids_rate_avg ~ lat_meta, data = data_ind %>% filter(ID != "M020"))
summary(mod)
## 
## Call:
## lm(formula = grids_rate_avg ~ lat_meta, data = data_ind %>% filter(ID != 
##     "M020"))
## 
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -0.032340 -0.027383 -0.009741  0.011043  0.155603 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)
## (Intercept)  0.0456566  0.0798621   0.572    0.575
## lat_meta    -0.0002001  0.0011580  -0.173    0.865
## 
## Residual standard error: 0.04359 on 17 degrees of freedom
## Multiple R-squared:  0.001753,   Adjusted R-squared:  -0.05697 
## F-statistic: 0.02986 on 1 and 17 DF,  p-value: 0.8649

Boldness-Age

mod<- lmer(lat_move ~ age + (1|ID),
                              data = data %>% filter(age < 500) %>% filter(trial %in% 1:5))

summary(mod)$coefficients
##                Estimate Std. Error    t value
## (Intercept) 376.6883171 262.023794  1.4376111
## age          -0.2598354   1.602838 -0.1621096
Anova(mod)
## Analysis of Deviance Table (Type II Wald chisquare tests)
## 
## Response: lat_move
##      Chisq Df Pr(>Chisq)
## age 0.0263  1     0.8712
mod <- lm (lat_move_avg ~ age, data = data_ind %>% filter(age < 500))
summary(mod)
## 
## Call:
## lm(formula = lat_move_avg ~ age, data = data_ind %>% filter(age < 
##     500))
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -321.5 -281.4 -112.1  193.4  736.4 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)
## (Intercept) 285.3020   269.3464   1.059    0.304
## age           0.3064     1.6468   0.186    0.855
## 
## Residual standard error: 326 on 17 degrees of freedom
## Multiple R-squared:  0.002033,   Adjusted R-squared:  -0.05667 
## F-statistic: 0.03462 on 1 and 17 DF,  p-value: 0.8546

Activity-Age

mod<- lmer(lines_rate ~ age + (1|ID),
                              data = data %>% filter(age < 500) %>% filter(trial %in% 1:5))

summary(mod)$coefficients
##                  Estimate   Std. Error   t value
## (Intercept) -0.0230747670 0.0370006730 -0.623631
## age          0.0004078297 0.0002256972  1.806977
Anova(mod)
## Analysis of Deviance Table (Type II Wald chisquare tests)
## 
## Response: lines_rate
##      Chisq Df Pr(>Chisq)  
## age 3.2652  1    0.07077 .
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
mod <- lm (lines_rate_avg ~ age, data = data_ind %>% filter(age < 500))
summary(mod)
## 
## Call:
## lm(formula = lines_rate_avg ~ age, data = data_ind %>% filter(age < 
##     500))
## 
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -0.049144 -0.019447 -0.005659  0.006769  0.171615 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.0024240  0.0391298  -0.062    0.951
## age          0.0002742  0.0002392   1.146    0.268
## 
## Residual standard error: 0.04736 on 17 degrees of freedom
## Multiple R-squared:  0.07173,    Adjusted R-squared:  0.01713 
## F-statistic: 1.314 on 1 and 17 DF,  p-value: 0.2676

Exploration-Age

mod<- lmer(grids_rate ~ age + (1|ID),
                              data = data %>% filter(age < 500) %>% filter(trial %in% 1:5))

summary(mod)$coefficients
##                  Estimate   Std. Error    t value
## (Intercept) -0.0124951229 0.0335910879 -0.3719773
## age          0.0002855841 0.0002051713  1.3919304
Anova(mod)
## Analysis of Deviance Table (Type II Wald chisquare tests)
## 
## Response: grids_rate
##      Chisq Df Pr(>Chisq)
## age 1.9375  1     0.1639
mod <- lm (grids_rate_avg ~ age, data = data_ind %>% filter(age < 500))
summary(mod)
## 
## Call:
## lm(formula = grids_rate_avg ~ age, data = data_ind %>% filter(age < 
##     500))
## 
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -0.037834 -0.022020 -0.008733  0.003422  0.155455 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.0007905  0.0350795  -0.023    0.982
## age          0.0002085  0.0002145   0.972    0.345
## 
## Residual standard error: 0.04246 on 17 degrees of freedom
## Multiple R-squared:  0.05265,    Adjusted R-squared:  -0.003078 
## F-statistic: 0.9448 on 1 and 17 DF,  p-value: 0.3447

Figure

For non-significant correlations, fitted line removed

Latency to Metamorphosis

fig_meta_boldness <-
  ggplot(data_ind, aes(x = lat_meta, y = lat_move_avg)) +
  geom_point(color = "black", size = 2) +
  geom_smooth(method = lm, alpha = 0.2, color = "SteelBlue", fill = "SteelBlue")+
  
  xlab("Latency to Metamorphose (days)") +
  ylab("Latency to Move (s)") +
  
  theme_bw(base_size = 15)+
  theme(panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        aspect.ratio=1) +
  scale_y_log10()
  
fig_meta_activity <-
  ggplot(data_ind, aes(x = lat_meta, y = lines_rate_avg)) +
  geom_point(color = "black", size = 2) +
  # geom_smooth(method = lm, alpha = 0.2, color = "SteelBlue", fill = "SteelBlue")+
  
  xlab("Latency to Metamorphose (days)") +
  ylab("# Lines crossed / Trial time (s)") +
  
  theme_bw(base_size = 15)+
  theme(panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        aspect.ratio=1)  + 
  scale_y_log10()
  
fig_meta_exploration <-
  ggplot(data_ind, aes(x = lat_meta, y = grids_rate_avg)) +
  geom_point(color = "black", size = 2) +
  # geom_smooth(method = lm, alpha = 0.2, color = "SteelBlue", fill = "SteelBlue")+
  
  xlab("Latency to Metamorphose (days)") +
  ylab("# Grids explored / Trial time (s)") +
  
  theme_bw(base_size = 15)+
  theme(panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        aspect.ratio=1)  + 
  scale_y_log10()  

Age at trial (With the outlier age removed)

fig_age_boldness <-
  ggplot(data_ind %>% filter(age < 500),
         aes(x = age, y = lat_move_avg)) +
  geom_point(color = "black", size = 2) +
  # geom_smooth(method = lm, alpha = 0.2, color = "SteelBlue", fill = "SteelBlue")+
  
  xlab("Age (days)") +
  ylab("Latency to Move (s)") +
  
  theme_bw(base_size = 15)+
  theme(panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        aspect.ratio=1) +
  scale_y_log10()
  
fig_age_activity <-
  ggplot(data_ind %>% filter(age < 500),
         aes(x = age, y = lines_rate_avg)) +
  geom_point(color = "black", size = 2) +
  geom_smooth(method = lm, alpha = 0.2, color = "SteelBlue", fill = "SteelBlue")+
  
  xlab("Age (days)") +
  ylab("# Lines crossed / Trial time (s)") +
  
  theme_bw(base_size = 15)+
  theme(panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        aspect.ratio=1)  + 
  scale_y_log10()
  
fig_age_exploration <-
  ggplot(data_ind %>% filter(age < 500),
         aes(x = age, y = grids_rate_avg)) +
  geom_point(color = "black", size = 2) +
  # geom_smooth(method = lm, alpha = 0.2, color = "SteelBlue", fill = "SteelBlue")+
  
  xlab("Age (days)") +
  ylab("# Grids explored / Trial time (s)") +
  
  theme_bw(base_size = 15)+
  theme(panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        aspect.ratio=1)  + 
  scale_y_log10()  
egg::ggarrange(fig_meta_boldness, fig_meta_activity, fig_meta_exploration,  
               fig_age_boldness, fig_age_activity, fig_age_exploration,
               nrow = 2,
               labels = c("A","B","C", "D", "E", "F"))

Learning ability vs Life History

Spatial learning index: difference between the latency to shelter in the first and the fifth trial.

Short summary

No evidence of spatial learning ability as part of POLS.

Analysis: latency improvemnt

Excluding M020 since we got it as an adult and the birthday and meta date is estimated:

mod<- lm(lat_shelter_improv ~ lat_meta, data = data_ind %>% filter(ID != "M020"))

summary(mod)$coefficients
##                Estimate Std. Error    t value  Pr(>|t|)
## (Intercept) -1185.96374 1628.03637 -0.7284627 0.4762462
## lat_meta       26.91024   23.60713  1.1399200 0.2701265
mod<- lm(lat_shelter_improv ~ age, data =  data_ind %>% filter(age < 500))

summary(mod)$coefficients
##                Estimate Std. Error    t value   Pr(>|t|)
## (Intercept) -682.078772   682.6867 -0.9991096 0.33175150
## age            8.511349     4.1740  2.0391349 0.05729593

Analysis: proportion completed

mod<- lm(prop_complete ~ lat_meta, data = data_ind %>% filter(ID != "M020"))

summary(mod)$coefficients
##                 Estimate Std. Error    t value  Pr(>|t|)
## (Intercept) -0.046396196 0.70454939 -0.0658523 0.9482637
## lat_meta     0.007062714 0.01021623  0.6913231 0.4986953
mod<- lm(prop_complete ~ age, data =  data_ind %>% filter(age<500))

summary(mod)$coefficients
##                 Estimate  Std. Error   t value    Pr(>|t|)
## (Intercept) -0.300184572 0.262933015 -1.141677 0.269415253
## age          0.004690716 0.001607593  2.917850 0.009592526

Figure

For non-significant correlations, fitted line removed M020 removed

** Improvement in latency**

fig_meta_improv <-
  ggplot(data_ind %>% filter(ID != "M020"),
         aes(x = lat_meta, y = lat_shelter_improv)) +
  geom_point(color = "black", size = 2) +
  # geom_smooth(method = lm, alpha = 0.2, color = "SteelBlue", fill = "SteelBlue")+
  
  xlab("Latency to Metamorphose (days)") +
  ylab("Latency to shelter [day 1 - day 5]") +
  
  theme_bw(base_size = 15)+
  theme(panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        aspect.ratio=1)


fig_age_improv <-
  ggplot(data_ind %>% filter(ID != "M020"),
         aes(x = age, y = lat_shelter_improv)) +
  geom_point(color = "black", size = 2) +

  geom_smooth(method = lm, alpha = 0.2, color = "SteelBlue", fill = "SteelBlue")+
  
  xlab("Age (days)") +
  ylab("Latency to shelter [day 1 - day 5]") +
  
  theme_bw(base_size = 15)+
  theme(panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        aspect.ratio=1) 
egg::ggarrange(fig_meta_improv, fig_age_improv,
               nrow = 1,
               labels = c("A","B"))

** Proportion completed**

fig_meta_comp <-
  ggplot(data_ind %>% filter(ID != "M020"),
         aes(x = lat_meta, y = prop_complete)) +
  geom_point(color = "black", size = 2) +
  #geom_smooth(method = lm, alpha = 0.2, color = "SteelBlue", fill = "SteelBlue")+
  
  xlab("Latency to Metamorphose (days)") +
  ylab("Proportion of assays completed") +
  
  theme_bw(base_size = 15)+
  theme(panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        aspect.ratio=1)


fig_age_comp <-
  ggplot(data_ind %>% filter(ID != "M020"),
         aes(x = age, y = prop_complete)) +
  geom_point(color = "black", size = 2) +

  geom_smooth(method = lm, alpha = 0.2, color = "SteelBlue", fill = "SteelBlue")+
  
  xlab("Age (days)") +
  ylab("Proportion of assays completed") +
  
  theme_bw(base_size = 15)+
  theme(panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        aspect.ratio=1) 
egg::ggarrange(fig_meta_comp, fig_age_comp,
               nrow = 1,
               labels = c("A","B"))