Last updated: 2021-10-05

Checks: 7 0

Knit directory: exp_evol_respiration/

This reproducible R Markdown analysis was created with workflowr (version 1.6.2). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.


Great! Since the R Markdown file has been committed to the Git repository, you know the exact version of the code that produced these results.

Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment.

The command set.seed(20190703) was run prior to running the code in the R Markdown file. Setting a seed ensures that any results that rely on randomness, e.g. subsampling or permutations, are reproducible.

Great job! Recording the operating system, R version, and package versions is critical for reproducibility.

Nice! There were no cached chunks for this analysis, so you can be confident that you successfully produced the results during this run.

Great job! Using relative paths to the files within your workflowr project makes it easier to run your code on other machines.

Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility.

The results in this page were generated with repository version 1c2e52c. See the Past versions tab to see a history of the changes made to the R Markdown and HTML files.

Note that you need to be careful to ensure that all relevant files for the analysis have been committed to Git prior to generating the results (you can use wflow_publish or wflow_git_commit). workflowr only checks the R Markdown file, but you know if there are other scripts or data files that it depends on. Below is the status of the Git repository when the results were generated:


Ignored files:
    Ignored:    .DS_Store
    Ignored:    .Rhistory
    Ignored:    .Rproj.user/
    Ignored:    data/.DS_Store
    Ignored:    figures/.DS_Store
    Ignored:    output/.DS_Store

Untracked files:
    Untracked:  data/1.eclosion_wide.csv
    Untracked:  data/2.DesRes.csv
    Untracked:  data/2.StarvRes.csv
    Untracked:  data/3.metabolic_rates.csv
    Untracked:  data/4.metabolite_data.csv
    Untracked:  figures/desiccation.pdf
    Untracked:  figures/eclosion.pdf
    Untracked:  figures/eclosion_interaction_plot.pdf
    Untracked:  figures/metaboliteDAG.pdf
    Untracked:  figures/metabolite_plotCONTROLLED.pdf
    Untracked:  figures/metabolite_plotCONTROLLED_nolines.pdf
    Untracked:  figures/metabolite_plot_nolines.pdf
    Untracked:  figures/metabolites_supp.pdf
    Untracked:  figures/respirationDAG.pdf
    Untracked:  figures/respiration_figure_cycleI.pdf
    Untracked:  figures/respiration_figure_cycleI_inkscape.pdf
    Untracked:  figures/respiration_figure_noRQ.pdf
    Untracked:  figures/starvation.pdf
    Untracked:  output/brms_SEM_respiration_noslope.rds
    Untracked:  output/brms_metabolite_SEM_noslope.rds
    Untracked:  output/cox_brms_noslope.rds
    Untracked:  output/des_brm_noslope.rds
    Untracked:  output/metabolite_SEM_table.csv
    Untracked:  output/respirometry_SEM_table.csv
    Untracked:  output/sta_brm_noslope.rds
    Untracked:  output/stress_medians.csv
    Untracked:  output/wing_brms_noslope.rds

Unstaged changes:
    Modified:   analysis/metabolites.Rmd
    Deleted:    data/1.eclosion_times.csv
    Deleted:    data/2.metabolic_rates.csv
    Deleted:    data/3.DesRes.csv
    Deleted:    data/3.StarvRes.csv
    Deleted:    data/3.metabolite_data.csv
    Modified:   figures/metabolite_interaction_plot.pdf
    Modified:   figures/metabolite_pairs_plot.pdf
    Modified:   figures/metabolite_plot.pdf
    Modified:   figures/respiration_figure.pdf
    Modified:   figures/respiration_pairs_plot.pdf
    Modified:   output/cox_brms.rds
    Deleted:    output/coxmod.rds
    Deleted:    output/coxmod_dropINT.rds
    Deleted:    output/coxmod_dropSEX.rds
    Deleted:    output/coxmod_dropTRT.rds

Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes.


These are the previous versions of the repository in which changes were made to the R Markdown (analysis/resistance.Rmd) and HTML (docs/resistance.html) files. If you’ve configured a remote Git repository (see ?wflow_git_remote), click on the hyperlinks in the table below to view the files as they were in that past version.

File Version Author Date Message
Rmd 1c2e52c MartinGarlovsky 2021-10-05 wflow_publish(c(“analysis/index.Rmd”, “analysis/juvenile_development.Rmd”,
html 151e6fb MartinGarlovsky 2021-03-23 Build site.
Rmd 1e31ceb MartinGarlovsky 2021-03-23 wflow_publish(c(“analysis/juvenile_development.Rmd”, “analysis/resistance.Rmd”,
html 21567bb MartinGarlovsky 2021-03-12 Build site.
Rmd f7b49ff MartinGarlovsky 2021-03-12 wflow_publish(c(“analysis/juvenile_development.Rmd”, “analysis/resistance.Rmd”,
html ffb09dd MartinGarlovsky 2021-02-08 Build site.
Rmd 1b92046 MartinGarlovsky 2021-02-08 wflow_publish(c(“analysis/juvenile_development.Rmd”, “analysis/resistance.Rmd”,
html 8000504 Martin Garlovsky 2021-01-19 Build site.
Rmd 7bf6463 Martin Garlovsky 2021-01-19 wflow_publish(“analysis/resistance.Rmd”)
html 709456c Martin Garlovsky 2021-01-18 Build site.
Rmd c2d846f Martin Garlovsky 2021-01-18 wflow_publish(c(“analysis/juvenile_development.Rmd”, “analysis/resistance.Rmd”,
html 037f2fc lukeholman 2020-12-18 Build site.
Rmd 5c3ec4e lukeholman 2020-12-18 new title
html 41d232f lukeholman 2020-12-18 Build site.
html 6861115 lukeholman 2020-12-18 Build site.
html 0d5bcc9 lukeholman 2020-12-18 Build site.
html 989e86f lukeholman 2020-12-18 Build site.
Rmd 96d1188 Martin Garlovsky 2020-12-13 MDG commit
html 96d1188 Martin Garlovsky 2020-12-13 MDG commit
Rmd 7d4b609 Martin Garlovsky 2020-12-05 MDG commit
html 7d4b609 Martin Garlovsky 2020-12-05 MDG commit
Rmd 8e1e5c1 Martin Garlovsky 2020-12-04 MDG commit again
html 8e1e5c1 Martin Garlovsky 2020-12-04 MDG commit again
html 287d75b Martin Garlovsky 2020-12-04 MDG commit
html 45751bf Martin Garlovsky 2020-12-04 MDG commit
Rmd c175be4 Martin Garlovsky 2020-12-04 MDG commit
html c175be4 Martin Garlovsky 2020-12-04 MDG commit
html df61dde Martin Garlovsky 2020-12-04 MDG commit
Rmd 0714753 Martin Garlovsky 2020-12-04 workflowr::wflow_git_commit(all = T)
Rmd 3fdbcb2 lukeholman 2020-11-30 Tweaks Nov 2020

Load packages

library(tidyverse)

library(coxme)
library(brms)
library(tidybayes)
library(ggridges)

library(kableExtra)
library(knitrhooks) # install with devtools::install_github("nathaneastwood/knitrhooks")
library(showtext)

output_max_height() # a knitrhook option

options(stringsAsFactors = FALSE)

# set up nice font for figure
nice_font <- "Lora"
font_add_google(name = nice_font, family = nice_font, regular.wt = 400, bold.wt = 700)
showtext_auto()

Load data

# load desiccation resistance data
DesRes <- read.csv("data/2.DesRes.csv") %>% 
  # add event (all flies died)
  mutate(EVENT = 1,
         LINE = paste0(Treatment, substr(Replicate, 2, 2)),
         ID = paste(LINE, Vial, sep = ''))

# calculate survival times
# paste time and date
DesRes$d <- paste(DesRes$Death_date, DesRes$Death_time, sep = ' ')

# experiment start time
start_timeDes <- "04/02/2017 12:00"

DesRes$survival.time <- as.numeric(strptime(DesRes$d, format = "%d/%m/%Y %H") - strptime(start_timeDes, format = "%d/%m/%Y %H"))


# load starvation resistance data
StaRes <- read.csv("data/2.StarvRes.csv") %>% 
  # add event (all flies died)
  mutate(EVENT = 1,
         LINE = paste0(Treatment, substr(Replicate, 2, 2)),
         ID = paste(LINE, Vial, sep = ''))

# calculate survival times
# paste time and date
StaRes$d <- paste(StaRes$Death_date, StaRes$Death_time, sep = ' ')

# experiment start time
start_timeSta <- "04/02/2017 10:00"

StaRes$survival.time <- as.numeric(strptime(StaRes$d, format = "%d/%m/%Y %H") - strptime(start_timeSta, format = "%d/%m/%Y %H"))

# 5 individuals have missing survival times which we will right censor at max. survival time
# Two M females (M2) were right censored as survival time not recorded
# Three P females (P2 Vial 6 and P4 vial 9) were right censored as survival time not recorded
StaRes[which(is.na(StaRes$survival.time)), 'EVENT'] <- 0
StaRes[which(is.na(StaRes$survival.time)), 'survival.time'] <- max(na.omit(StaRes$survival.time))

Inspecting the raw data

bind_rows(
  DesRes %>% 
  select(Treatment, Sex, survival.time) %>% mutate(var = 'Desiccation'),
  StaRes %>% filter(EVENT == 1) %>% 
  select(Treatment, Sex, survival.time) %>% mutate(var = 'Starvation')
) %>% 
  mutate(var2 = paste(Treatment, Sex)) %>% 
  ggplot(aes(x = survival.time, y = Sex, fill = var2)) +
  geom_boxplot() +
  scale_fill_manual(values = c("pink", "skyblue", "red", "blue"), name = "",
                    labels = c('Monogamy Females', 'Monogamy Males',
                               'Polandry Females', 'Polandry Males')) +
  labs(x = 'Survival time (hours)') +
  facet_wrap(~var, ncol = 2) +
  theme_bw() +
  NULL

Version Author Date
151e6fb MartinGarlovsky 2021-03-23
21567bb MartinGarlovsky 2021-03-12
ffb09dd MartinGarlovsky 2021-02-08
709456c Martin Garlovsky 2021-01-18
989e86f lukeholman 2020-12-18
96d1188 Martin Garlovsky 2020-12-13
c175be4 Martin Garlovsky 2020-12-04
df61dde Martin Garlovsky 2020-12-04

Figure 1: Survival time in hours for flies in each treatment split by sex.

Survival analysis

We modeled desiccation and starvation resistance using survival analysis. We measured time in hours until death (EVENT = 1) for single sex triads of flies housed in vials (n = 7-10 vials per replicate per sex) containing no media and silica gel beads between the cotton and Parafilm enclosing the vial (desiccation resistance) or an agar media providing moisture only (starvation resistance). We monitored vials for deaths every two hours until all flies perished. For the starvation resistance assay five individuals (two M females and three E females) were right censored (EVENT = 0) at the end of the observation period as death times were not recorded or remained alive.

Kaplan-Meier survival curve

First we plot Kaplan-Meier survival curves.

survminer::ggsurvplot(survfit(Surv(survival.time, EVENT) ~ Treatment + Sex, data = DesRes),
                      conf.int = TRUE,
                      risk.table = FALSE,
                      linetype = "Sex",
                      palette = c("pink", "skyblue", "red", "blue"),
                      xlab = "Time (hours)",
                      legend = 'right',
                      legend.title = "",
                      legend.labs = c("M \u2640","M \u2642",
                                      'E \u2640','E \u2642'),
                      break.time.by = 12,
                      ggtheme = theme_bw()) 

Version Author Date
21567bb MartinGarlovsky 2021-03-12
ffb09dd MartinGarlovsky 2021-02-08
709456c Martin Garlovsky 2021-01-18
989e86f lukeholman 2020-12-18
96d1188 Martin Garlovsky 2020-12-13
df61dde Martin Garlovsky 2020-12-04
#ggsave(filename = 'figures/desiccation.pdf', width = 5.5, height = 5, dpi = 600, useDingbats = FALSE)

survminer::ggsurvplot(survfit(Surv(survival.time, EVENT) ~ Treatment + Sex, data = StaRes),
                      conf.int = TRUE,
                      risk.table = FALSE,
                      linetype = "Sex",
                      palette = c("pink", "skyblue", "red", "blue"),
                      xlab = "Time (hours)",
                      legend = 'right',
                      legend.title = "",
                      legend.labs = c("M \u2640","M \u2642",
                                      'E \u2640','E \u2642'),
                      break.time.by = 12,
                      ggtheme = theme_bw()) 

Version Author Date
151e6fb MartinGarlovsky 2021-03-23
21567bb MartinGarlovsky 2021-03-12
ffb09dd MartinGarlovsky 2021-02-08
709456c Martin Garlovsky 2021-01-18
989e86f lukeholman 2020-12-18
96d1188 Martin Garlovsky 2020-12-13
df61dde Martin Garlovsky 2020-12-04
#ggsave(filename = 'figures/starvation.pdf', width = 5.5, height = 5, dpi = 600, useDingbats = FALSE)

Figure 2: Kaplan-Meier survival curves for flies in each treatment split by sex. + indicates censored individuals (n = 5).

Median survival times

bind_rows(
  summary(survfit(Surv(survival.time, EVENT) ~ Treatment + Sex, data = DesRes))$table %>% 
    as_tibble() %>% 
    mutate(Treatment = c('M', 'M', 'E', 'E'),
           Sex = c('Female', 'Male', 'Female', 'Male')),
  summary(survfit(Surv(survival.time, EVENT) ~ Treatment + Sex, data = StaRes))$table %>% 
    as_tibble() %>% 
    mutate(Treatment = c('M', 'M', 'E', 'E'),
           Sex = c('Female', 'Male', 'Female', 'Male'))) %>% 
  mutate(`Median (± 95% CI)` = paste0(median, ' (', `0.95LCL`, '-', `0.95UCL`, ')')) %>% 
  dplyr::select(Treatment, Sex, N = records, `N events` = events, `Median (± 95% CI)`) %>%
  #write_csv('output/stress_medians.csv')
  kable() %>% 
  kable_styling(full_width = FALSE) %>%
  group_rows("Desiccation", 1, 4) %>%
  group_rows("Starvation", 5, 8)
Treatment Sex N N events Median (± 95% CI)
Desiccation
M Female 108 108 38 (38-42)
M Male 111 111 32 (32-34)
E Female 114 114 40 (38-42)
E Male 105 105 32 (32-34)
Starvation
M Female 120 118 59 (54-64)
M Male 120 120 42 (40-46)
E Female 120 117 68 (64-72)
E Male 120 120 44 (42-44)

Check proportional hazards assumption

Next we need to check that the proportional hazards assumption is not violated before fitting the model, where crossing hazards (lines) indicate violation of the proportional hazards assumption. For both desiccation and starvation we see crossing hazards for the male survival curves. We therefore fit accelerated failure time (AFT) models with a Weibull distribution (see here).

# assess proportional hazards assumption
par(mar = c(2, 2, 2, 2), mfrow = c(1, 2))
plot(survfit(Surv(survival.time, EVENT) ~ Treatment + Sex, data = DesRes), 
     lty = 1:2, lwd = 2,
     col = c("pink", "skyblue", "red", "blue"), 
     main = 'Desiccation',
     fun = "cloglog")

legend("topleft", c("M \u2640","M \u2642",'E \u2640','E \u2642'), 
       col = c("pink", "skyblue", "red", "blue"), 
       lty = 1:2, 
       lwd = 2,
       bty = 'n'
)

plot(survfit(Surv(survival.time, EVENT) ~ Treatment + Sex, data = StaRes), 
     lty = 1:2, lwd = 2,
     col = c("pink", "skyblue", "red", "blue"), 
     main = 'Starvation',
     fun = "cloglog")

Version Author Date
151e6fb MartinGarlovsky 2021-03-23
21567bb MartinGarlovsky 2021-03-12
709456c Martin Garlovsky 2021-01-18
989e86f lukeholman 2020-12-18
96d1188 Martin Garlovsky 2020-12-13
df61dde Martin Garlovsky 2020-12-04
par(mfrow = c(1, 1))

Fit the survival models for desiccation and starvation resistance

We fit an accelerated failure time model in brms using family = weibull(), with time (hours) to event (death) as the response and sexual selection treatment (Treatment; Monogamy or Elevated polyandry), Sex (female or male) and their interaction as predictors. See here for a helpful explanation on fitting survival models in brms. We also include replicate treatment as a random intercept term for each of the 8 lines and a random slope term to allow the effect of selection treatment to vary across replicate lines. We also include vial ID as a random intercept term as individuals housed in the same vial may show a correlated response.

if(!file.exists("output/des_brm.rds")){ # if the model doesn't exist fit it, else load it
  
  des_brm <- brm(survival.time | cens(1 - EVENT) ~ Treatment * Sex + (Treatment|LINE) + (1|ID),
               prior = c(set_prior("normal(0,0.5)", class = "b"),
                         set_prior("cauchy(0,0.1)", class = "sd")),
               iter = 5000, chains = 4, cores = 4,
               control = list(max_treedepth = 20,
                              adapt_delta = 0.999),
               data = DesRes, family = weibull())
  
  #saveRDS(des_brm, "output/des_brm_noslope.rds") # save with no random slope term
  saveRDS(des_brm, "output/des_brm.rds")
} else {
  des_brm <- readRDS('output/des_brm_noslope.rds')
}


if(!file.exists("output/sta_brm.rds")){ # if the model doesn't exist fit it, else load it
  
  sta_brm <- brm(survival.time | cens(EVENT) ~ Treatment * Sex + (Treatment|LINE) + (1|ID),
               prior = c(set_prior("normal(0,0.5)", class = "b"),
                         set_prior("cauchy(0,0.1)", class = "sd")),
               iter = 5000, chains = 4, cores = 4,
               control = list(max_treedepth = 20,
                              adapt_delta = 0.999),
               # brm uses 0 = event, 1 = censor so need to recode
               data = StaRes %>% mutate(EVENT = if_else(EVENT == 1, 0, 1)), 
               family = weibull())
  
  #saveRDS(sta_brm, "output/sta_brm_noslope.rds") # save with no random slope term
  saveRDS(sta_brm, "output/sta_brm.rds")
} else {
  sta_brm <- readRDS('output/sta_brm_noslope.rds')
}

Table of model parameter estimates - eclosion time

Formatted table

Taking the exponent of the coefficients gives an estimate of the multiplicative effect of the time to event compared to baseline (Monogamy females) (see here). For instance, for desiccation resistance, being male accelerates time to event by a factor of exp(-0.167) = 0.847 (95% confidence intervals = 0.795 - 0.902), i.e. Monogamy males live 0.847 times as long as Monogamy females.

des_test <- bind_rows(
  hypothesis(des_brm, 'TreatmentP = 0')$hypothesis,
  hypothesis(des_brm, 'Sexm = 0')$hypothesis,
  hypothesis(des_brm, 'TreatmentP:Sexm = 0')$hypothesis
) %>% 
  mutate(Parameter = c('Treatment (E)', 'Sex (M)', 'Treatment (E) x Sex (M)'),
         across(2:5, round, 3)) %>% 
  relocate(Parameter, Estimate, Est.Error, CI.Lower, CI.Upper, Star)

sta_test <- bind_rows(
  hypothesis(sta_brm, 'TreatmentP = 0')$hypothesis,
  hypothesis(sta_brm, 'Sexm = 0')$hypothesis,
  hypothesis(sta_brm, 'TreatmentP:Sexm = 0')$hypothesis
) %>% 
  mutate(Parameter = c('Treatment (E)', 'Sex (M)', 'Treatment (E) x Sex (M)'),
         across(2:5, round, 3)) %>% 
  relocate(Parameter, Estimate, Est.Error, CI.Lower, CI.Upper, Star)

des_pvals <- bayestestR::p_direction(des_brm) %>% 
  as.data.frame() %>%
  mutate(vars = map_chr(str_split(Parameter, "_"), ~ .x[2]),
         p_val = 1 - pd, 
         star = ifelse(p_val < 0.05, "\\*", "")) %>%
  select(vars, p_val, star)

sta_pvals <- bayestestR::p_direction(sta_brm) %>% 
  as.data.frame() %>%
  mutate(vars = map_chr(str_split(Parameter, "_"), ~ .x[2]),
         p_val = 1 - pd, 
         star = ifelse(p_val < 0.05, "\\*", "")) %>%
  select(vars, p_val, star)

bind_rows(
  des_test %>% 
    mutate(vars = c('TreatmentP', 'Sexm', 'TreatmentP:Sexm')) %>% 
    left_join(des_pvals %>% filter(vars != 'Intercept'), 
              by = c("vars")) %>% 
    select(Parameter, Estimate, Est.Error, CI.Lower, CI.Upper, `p` = p_val, star),
  sta_test %>% 
    mutate(vars = c('TreatmentP', 'Sexm', 'TreatmentP:Sexm')) %>% 
    left_join(sta_pvals %>% filter(vars != 'Intercept'), 
              by = c("vars")) %>% 
    select(Parameter, Estimate, Est.Error, CI.Lower, CI.Upper, `p` = p_val, star)
  ) %>% 
  mutate(p = ifelse(p > 0.001, round(p, 3), '< 0.001')) %>% 
  rename(` ` = star) %>%
  kable() %>% 
  kable_styling(full_width = FALSE) %>%
  group_rows("Desiccation", 1, 3) %>%
  group_rows("Starvation", 4, 6)
Parameter Estimate Est.Error CI.Lower CI.Upper p
Desiccation
Treatment (E) 0.054 0.085 -0.117 0.224 0.24
Sex (M) -0.167 0.032 -0.229 -0.103 < 0.001 *
Treatment (E) x Sex (M) -0.097 0.046 -0.188 -0.007 0.018 *
Starvation
Treatment (E) 0.083 0.097 -0.112 0.273 0.181
Sex (M) -0.322 0.035 -0.391 -0.256 < 0.001 *
Treatment (E) x Sex (M) -0.126 0.049 -0.222 -0.029 0.005 *

Complete output from summary.brmsfit()

The shape parameter (\(1/\)scale parameter; see here) describes the change in hazard over time where:

  • \(p\) = 1: constant hazard
  • \(p\) > 1: increasing hazard over time
  • \(p\) < 1: decreasing hazard over time
Desiccation
des_brm
 Family: weibull 
  Links: mu = log; shape = identity 
Formula: survival.time | cens(1 - EVENT) ~ Treatment * Sex + (1 | LINE) + (1 | ID) 
   Data: DesRes (Number of observations: 438) 
  Draws: 4 chains, each with iter = 5000; warmup = 2500; thin = 1;
         total post-warmup draws = 10000

Group-Level Effects: 
~ID (Number of levels: 146) 
              Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
sd(Intercept)     0.11      0.01     0.09     0.13 1.00     3552     5532

~LINE (Number of levels: 8) 
              Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
sd(Intercept)     0.11      0.04     0.06     0.20 1.00     3911     5251

Population-Level Effects: 
                Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
Intercept           3.66      0.06     3.54     3.78 1.00     4601     5308
TreatmentP          0.05      0.09    -0.12     0.22 1.00     4334     6055
Sexm               -0.17      0.03    -0.23    -0.10 1.00     5200     6875
TreatmentP:Sexm    -0.10      0.05    -0.19    -0.01 1.00     4810     6616

Family Specific Parameters: 
      Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
shape     7.56      0.36     6.89     8.28 1.00     6108     7957

Draws were sampled using sampling(NUTS). For each parameter, Bulk_ESS
and Tail_ESS are effective sample size measures, and Rhat is the potential
scale reduction factor on split chains (at convergence, Rhat = 1).
Starvation
sta_brm
 Family: weibull 
  Links: mu = log; shape = identity 
Formula: survival.time | cens(EVENT) ~ Treatment * Sex + (1 | LINE) + (1 | ID) 
   Data: StaRes %>% mutate(EVENT = if_else(EVENT == 1, 0, 1 (Number of observations: 480) 
  Draws: 4 chains, each with iter = 5000; warmup = 2500; thin = 1;
         total post-warmup draws = 10000

Group-Level Effects: 
~ID (Number of levels: 160) 
              Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
sd(Intercept)     0.12      0.01     0.09     0.14 1.00     4057     6009

~LINE (Number of levels: 8) 
              Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
sd(Intercept)     0.13      0.04     0.07     0.23 1.00     3677     5482

Population-Level Effects: 
                Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
Intercept           4.11      0.07     3.97     4.25 1.00     3511     4489
TreatmentP          0.08      0.10    -0.11     0.27 1.00     3727     4908
Sexm               -0.32      0.03    -0.39    -0.26 1.00     4942     5685
TreatmentP:Sexm    -0.13      0.05    -0.22    -0.03 1.00     4874     6607

Family Specific Parameters: 
      Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
shape     5.96      0.27     5.45     6.49 1.00     6453     7484

Draws were sampled using sampling(NUTS). For each parameter, Bulk_ESS
and Tail_ESS are effective sample size measures, and Rhat is the potential
scale reduction factor on split chains (at convergence, Rhat = 1).

Posterior effect size of treatment and sex on survival

# get posterior predictions
post_des <- posterior_samples(des_brm) %>% 
  as_tibble() %>%
  select(contains("b_"), -contains("Intercept")) %>% 
  mutate(draw = 1:n()) %>% 
  pivot_longer(-draw) %>% 
  mutate(key = str_remove_all(name, "b_"))

post_sta <- posterior_samples(sta_brm) %>% 
  as_tibble() %>%
  select(contains("b_"), -contains("Intercept")) %>% 
  mutate(draw = 1:n()) %>% 
  pivot_longer(-draw) %>% 
  mutate(key = str_remove_all(name, "b_"))

bind_rows(post_des %>% mutate(var = 'Desiccation'), 
          post_sta %>% mutate(var = 'Starvation')) %>%
  mutate(key = recode(key, TreatmentP = "Treatment (E)", Sexm = 'Sex (M)', `TreatmentP:Sexm` = 'Treatment (E) x Sex (M)')) %>% 
  ggplot(aes(x = value, y = key, fill = key)) + 
  geom_vline(xintercept = 0, linetype = 2) + 
  stat_halfeye(alpha = .8) +
  scale_fill_brewer(palette = "Spectral") +
  coord_cartesian(xlim = c(-0.4, 0.4)) +
  labs(x = "Effect size", y = "Model parameter") +
  facet_wrap(~var) +
  theme_ridges() +
  theme(legend.position = 'none',
        legend.title = element_blank()) +
  NULL

Version Author Date
21567bb MartinGarlovsky 2021-03-12
989e86f lukeholman 2020-12-18
7d4b609 Martin Garlovsky 2020-12-05

Posterior effect size of treatment on survival, for each sex

Here, we use the model to predict the mean survival coefficient in each treatment and sex (averaged across the eight replicate selection lines). We then calculate the effect size of treatment by subtracting the (sex-specific) mean for the M treatment from the mean for the E treatment. We see that there is no overall effect of treatment in males or females.

new_data_stress <- expand_grid(Sex = c("m", "f"),
                               Treatment = c("M", "P"), 
                               LINE = NA) %>%
  mutate(type = 1:4)

fitted_des <- posterior_epred(
  des_brm, newdata = new_data_stress, re_formula = NA,
  summary = FALSE) %>% 
  reshape2::melt() %>% rename(draw = Var1, type = Var2) %>% 
  as_tibble() %>%
  left_join(new_data_stress, by = "type") %>%
  select(draw, value, Sex, Treatment)

treat_diff_des <- fitted_des %>%
  spread(Treatment, value) %>%
  mutate(`Difference in means (Poly - Mono)` = P - M) 

fitted_sta <- posterior_epred(
  sta_brm, newdata = new_data_stress, re_formula = NA,
  summary = FALSE) %>% 
  reshape2::melt() %>% rename(draw = Var1, type = Var2) %>% 
  as_tibble() %>%
  left_join(new_data_stress, by = "type") %>%
  select(draw, value, Sex, Treatment)

treat_diff_sta <- fitted_sta %>%
  spread(Treatment, value) %>%
  mutate(`Difference in means (Poly - Mono)` = P - M)

Dessication resistance

treat_diff_des %>% 
  mutate(Sex = factor(ifelse(Sex == "m", "Males", "Females"))) %>% 
  ggplot(aes(x = `Difference in means (Poly - Mono)`, y = Sex, fill = Sex)) +
  geom_vline(xintercept = 0, linetype = 2) +
  stat_halfeye() + 
  scale_fill_brewer(palette = 'Pastel1', direction = 1, name = "") +
  scale_colour_brewer(palette = 'Pastel1', direction = 1, name = "") +
  labs(x = 'Difference in means between\nselection treatments (E - M)', y = 'Sex') +
  theme_bw() +
  theme(legend.position = 'none',
        strip.background = element_blank(),
        panel.grid.major.x = element_blank()) +
  NULL

Version Author Date
21567bb MartinGarlovsky 2021-03-12
989e86f lukeholman 2020-12-18
96d1188 Martin Garlovsky 2020-12-13
7d4b609 Martin Garlovsky 2020-12-05

Starvation resistance

treat_diff_sta %>% 
  mutate(Sex = factor(ifelse(Sex == "m", "Males", "Females"))) %>% 
  ggplot(aes(x = `Difference in means (Poly - Mono)`, y = Sex, fill = Sex)) +
  geom_vline(xintercept = 0, linetype = 2) +
  stat_halfeye() + 
  scale_fill_brewer(palette = 'Pastel1', direction = 1, name = "") +
  scale_colour_brewer(palette = 'Pastel1', direction = 1, name = "") +
  labs(x = 'Difference in means between\nselection treatments (E - M)', y = 'Sex') +
  theme_bw() +
  theme(legend.position = 'none',
        strip.background = element_blank(),
        panel.grid.major.x = element_blank()) +
  NULL

Version Author Date
21567bb MartinGarlovsky 2021-03-12
709456c Martin Garlovsky 2021-01-18
989e86f lukeholman 2020-12-18
96d1188 Martin Garlovsky 2020-12-13

Posterior difference in treatment effect size between sexes

This section examines the treatment \(\times\) sex interaction term, by calculating the difference in the effect size of the E/M treatment between sexes. We find evidence for a treatment \(\times\) sex interaction, i.e. the difference in survival time between the sexes was greater in the E treatment than the M treatment.

Figure

Dessication

treat_diff_des %>%
  rename(d = `Difference in means (Poly - Mono)`) %>% 
  select(draw, Sex, d) %>%
  group_by(draw) %>%
  summarise(`Difference in effect size between sexes (male - female)` = d[2] - d[1],
            .groups = "drop") %>% 
  ggplot(aes(x = `Difference in effect size between sexes (male - female)`, y = 1, fill = stat(x < 0))) +
  geom_vline(xintercept = 0, linetype = 2) +
  stat_halfeye() +
  scale_fill_brewer(palette = 'Pastel2', direction = 1, name = "") +
  theme_bw() +
  theme(legend.position = 'none',
        text = element_text(family = nice_font),
        strip.background = element_blank()) +
  ylab("Posterior density") +
  #ggsave("figures/des_interaction_plot.pdf", height=4, width=4) +
  NULL

Version Author Date
21567bb MartinGarlovsky 2021-03-12
989e86f lukeholman 2020-12-18
96d1188 Martin Garlovsky 2020-12-13

Starvation

treat_diff_sta %>%
  rename(d = `Difference in means (Poly - Mono)`) %>% 
  select(draw, Sex, d) %>%
  group_by(draw) %>%
  summarise(`Difference in effect size between sexes (male - female)` = d[2] - d[1],
            .groups = "drop") %>% 
  ggplot(aes(x = `Difference in effect size between sexes (male - female)`, y = 1, fill = stat(x < 0))) +
  geom_vline(xintercept = 0, linetype = 2) +
  stat_halfeye() +
  scale_fill_brewer(palette = 'Pastel2', direction = 1, name = "") +
  theme_bw() +
  theme(legend.position = 'none',
        text = element_text(family = nice_font),
        strip.background = element_blank()) +
  ylab("Posterior density") +
  #ggsave("figures/sta_interaction_plot.pdf", height=4, width=4) +
  NULL

Version Author Date
21567bb MartinGarlovsky 2021-03-12
709456c Martin Garlovsky 2021-01-18
989e86f lukeholman 2020-12-18
96d1188 Martin Garlovsky 2020-12-13

Table

treatsex_interaction_des <- treat_diff_des %>%
  select(draw, Sex, d =  `Difference in means (Poly - Mono)`) %>%
  arrange(draw, Sex) %>%
  group_by(draw) %>%
  summarise(`Difference in effect size between sexes (male - female)` = d[2] - d[1],
            .groups = "drop") # males - females

treatsex_interaction_sta <- treat_diff_sta %>%
  select(draw, Sex, d =  `Difference in means (Poly - Mono)`) %>%
  arrange(draw, Sex) %>%
  group_by(draw) %>%
  summarise(`Difference in effect size between sexes (male - female)` = d[2] - d[1],
            .groups = "drop") # males - females

bind_rows(treatsex_interaction_des %>% mutate(variable = 'Dessication'),
          treatsex_interaction_sta %>% mutate(variable = 'Starvation')) %>%
  rename(x = `Difference in effect size between sexes (male - female)`) %>%
  group_by(variable) %>%
  summarise(`Difference in effect size between sexes (male - female)` = median(x),
            `Lower 95% CI` = quantile(x, probs = 0.025), 
            `Upper 95% CI` = quantile(x, probs = 0.975),
            p = 1 - as.numeric(bayestestR::p_direction(x)),
            ` ` = ifelse(p < 0.05, "\\*", ""),
            .groups = "drop") %>%
  kable(digits=3) %>%
  kable_styling(full_width = FALSE)
variable Difference in effect size between sexes (male - female) Lower 95% CI Upper 95% CI p
Dessication -3.562 -7.090 -0.065 0.023 *
Starvation -7.111 -13.423 -0.573 0.016 *

sessionInfo()
R version 4.0.3 (2020-10-10)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Big Sur 10.16

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRblas.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib

locale:
[1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] showtext_0.9-4   showtextdb_3.0   sysfonts_0.8.5   knitrhooks_0.0.4
 [5] knitr_1.33       kableExtra_1.3.4 ggridges_0.5.3   tidybayes_3.0.1 
 [9] brms_2.16.1      Rcpp_1.0.7       coxme_2.2-16     bdsmatrix_1.3-4 
[13] survival_3.2-12  forcats_0.5.1    stringr_1.4.0    dplyr_1.0.7     
[17] purrr_0.3.4      readr_2.0.1      tidyr_1.1.3      tibble_3.1.3    
[21] ggplot2_3.3.5    tidyverse_1.3.1  workflowr_1.6.2 

loaded via a namespace (and not attached):
  [1] utf8_1.2.2           tidyselect_1.1.1     lme4_1.1-27.1       
  [4] htmlwidgets_1.5.3    grid_4.0.3           munsell_0.5.0       
  [7] codetools_0.2-18     DT_0.18              miniUI_0.1.1.1      
 [10] withr_2.4.2          Brobdingnag_1.2-6    colorspace_2.0-2    
 [13] highr_0.9            rstudioapi_0.13      stats4_4.0.3        
 [16] ggsignif_0.6.2       bayesplot_1.8.1      labeling_0.4.2      
 [19] git2r_0.28.0         rstan_2.21.1         KMsurv_0.1-5        
 [22] farver_2.1.0         datawizard_0.2.0     bridgesampling_1.1-2
 [25] rprojroot_2.0.2      coda_0.19-4          vctrs_0.3.8         
 [28] generics_0.1.0       xfun_0.25            R6_2.5.1            
 [31] markdown_1.1         gamm4_0.2-6          projpred_2.0.2      
 [34] assertthat_0.2.1     promises_1.2.0.1     scales_1.1.1        
 [37] gtable_0.3.0         processx_3.5.2       rlang_0.4.11        
 [40] systemfonts_1.0.2    splines_4.0.3        rstatix_0.7.0       
 [43] broom_0.7.9          checkmate_2.0.0      inline_0.3.19       
 [46] yaml_2.2.1           reshape2_1.4.4       abind_1.4-5         
 [49] modelr_0.1.8         threejs_0.3.3        crosstalk_1.1.1     
 [52] backports_1.2.1      httpuv_1.6.2         rsconnect_0.8.24    
 [55] tensorA_0.36.2       tools_4.0.3          ellipsis_0.3.2      
 [58] RColorBrewer_1.1-2   jquerylib_0.1.4      posterior_1.0.1     
 [61] plyr_1.8.6           base64enc_0.1-3      ps_1.6.0            
 [64] prettyunits_1.1.1    ggpubr_0.4.0         zoo_1.8-9           
 [67] haven_2.4.3          fs_1.5.0             magrittr_2.0.1      
 [70] data.table_1.14.0    ggdist_3.0.0         openxlsx_4.2.4      
 [73] colourpicker_1.1.0   reprex_2.0.1         survminer_0.4.9     
 [76] mvtnorm_1.1-2        whisker_0.4          matrixStats_0.60.0  
 [79] hms_1.1.0            shinyjs_2.0.0        mime_0.11           
 [82] evaluate_0.14        arrayhelpers_1.1-0   xtable_1.8-4        
 [85] shinystan_2.5.0      rio_0.5.27           readxl_1.3.1        
 [88] gridExtra_2.3        rstantools_2.1.1     compiler_4.0.3      
 [91] V8_3.4.2             crayon_1.4.1         minqa_1.2.4         
 [94] StanHeaders_2.21.0-7 htmltools_0.5.1.1    mgcv_1.8-36         
 [97] later_1.3.0          tzdb_0.1.2           RcppParallel_5.1.4  
[100] lubridate_1.7.10     DBI_1.1.1            dbplyr_2.1.1        
[103] MASS_7.3-54          boot_1.3-28          Matrix_1.3-4        
[106] car_3.0-11           cli_3.0.1            parallel_4.0.3      
[109] insight_0.14.3       igraph_1.2.6         pkgconfig_2.0.3     
[112] km.ci_0.5-2          foreign_0.8-81       xml2_1.3.2          
[115] svUnit_1.0.6         dygraphs_1.1.1.6     svglite_2.0.0       
[118] bslib_0.2.5.1        webshot_0.5.2        rvest_1.0.1         
[121] distributional_0.2.2 callr_3.7.0          digest_0.6.27       
[124] rmarkdown_2.10       cellranger_1.1.0     survMisc_0.5.5      
[127] curl_4.3.2           shiny_1.6.0          gtools_3.9.2        
[130] nloptr_1.2.2.2       lifecycle_1.0.0      nlme_3.1-152        
[133] jsonlite_1.7.2       carData_3.0-4        viridisLite_0.4.0   
[136] fansi_0.5.0          pillar_1.6.2         lattice_0.20-44     
[139] loo_2.4.1            fastmap_1.1.0        httr_1.4.2          
[142] pkgbuild_1.2.0       glue_1.4.2           xts_0.12.1          
[145] bayestestR_0.10.5    zip_2.2.0            shinythemes_1.2.0   
[148] stringi_1.7.3        sass_0.4.0