Last updated: 2020-12-18

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 5a81a83. 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:    .Rapp.history
    Ignored:    .Rproj.user/
    Ignored:    analysis/.DS_Store
    Ignored:    output/.DS_Store

Untracked files:
    Untracked:  output/brms_SEM_respiration.rds
    Untracked:  output/metabolite_interaction_plot.pdf
    Untracked:  output/metabolite_pairs_plot.pdf
    Untracked:  output/metabolite_plot.pdf
    Untracked:  output/respiration_figure.pdf
    Untracked:  output/respiration_pairs_plot.pdf
    Untracked:  post_preds_respiration.rds

Unstaged changes:
    Deleted:    analysis/about.Rmd
    Deleted:    output/Figure 2.pdf
    Deleted:    output/bayesian_R2_values.rds
    Deleted:    output/brms_SEM.rds
    Deleted:    output/pairs_plot.pdf

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 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(lme4)
library(brms)
library(tidybayes)
library(ggridges)

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

output_max_height() # a knitrhook option

options(stringsAsFactors = FALSE)

Load data

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

# 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"))

des.surv <- Surv(DesRes$survival.time, DesRes$EVENT)


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

# 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 12:00"

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

summary(StaRes)

# 5 individuals have missing survival times which we will right censor at max. survival time
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 = "") +
  labs(x = 'Survival time (hours)') +
  facet_wrap(~var, ncol = 2) +
  theme_bw() +
  NULL

Version Author Date
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.

Fit the model for desiccation/starvation resistance

Plot the survival curves and median survival times

Version Author Date
96d1188 Martin Garlovsky 2020-12-13
df61dde Martin Garlovsky 2020-12-04

Version Author Date
96d1188 Martin Garlovsky 2020-12-13
df61dde Martin Garlovsky 2020-12-04

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

# median eclosion times
survfit(Surv(survival.time, EVENT) ~ Treatment + Sex, data = DesRes)
Call: survfit(formula = Surv(survival.time, EVENT) ~ Treatment + Sex, 
    data = DesRes)

                     n events median 0.95LCL 0.95UCL
Treatment=M, Sex=f 108    108     38      38      42
Treatment=M, Sex=m 111    111     32      32      34
Treatment=P, Sex=f 114    114     40      38      42
Treatment=P, Sex=m 105    105     32      32      34
survfit(Surv(survival.time, EVENT) ~ Treatment + Sex, data = StaRes)
Call: survfit(formula = Surv(survival.time, EVENT) ~ Treatment + Sex, 
    data = StaRes)

                     n events median 0.95LCL 0.95UCL
Treatment=M, Sex=f 120    118     57      52      62
Treatment=M, Sex=m 120    120     40      38      44
Treatment=P, Sex=f 120    117     66      62      70
Treatment=P, Sex=m 120    120     42      40      42

Next we check that the proportional hazards assumption is met.

# 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",'P \u2640','P \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
96d1188 Martin Garlovsky 2020-12-13
df61dde Martin Garlovsky 2020-12-04

For both desiccation and starvation we see crossing hazards for the male survival curves. We will therefore fit accelerated failure time (AFT) models with a Weibull distribution (see this paper) and a frailty term to account for replicates within each treatment. We can define the degrees of freedom explicitly (df = 6).

Fit the Accelerated failure time models

weibull.des <- survreg(Surv(survival.time, EVENT) ~ Treatment * Sex + frailty(LINE, df = 6), 
                       data = DesRes, dist = "weibull")


weibull.sta <- survreg(Surv(survival.time, EVENT) ~ Treatment * Sex + frailty(LINE, df = 6), 
                       data = StaRes, dist = "weibull")


bind_rows(anova(weibull.des), anova(weibull.sta)) %>% 
  cbind(Parameter = c('Null', 'Treatment', 'Sex', '`frailty(LINE)`', 'Treatment x Sex')) %>% 
  mutate(across(1:5, round, 3)) %>% 
  mutate(star = ifelse(`Pr(>Chi)` < 0.05, "\\*", "")) %>% 
  select(Parameter, Df, `Resid. Df`, Deviance, `Pr(>Chi)`, star) %>% 
  filter(Parameter!='`frailty(LINE)`') %>% 
  rename(` ` = star) %>% 
  mutate(`Pr(>Chi)` = ifelse(`Pr(>Chi)` > 0.001, round(`Pr(>Chi)`, 3), '< 0.001')) %>% 
  kable() %>% 
  kable_styling() %>% 
  kable_styling(full_width = FALSE) %>%
  group_rows("Desiccation", 1, 4) %>%
  group_rows("Starvation", 5, 8)
Parameter Df Resid. Df Deviance Pr(>Chi)
Desiccation
Null NA 436.000 NA NA NA
Treatment 1.000 435.000 3.849 0.05
Sex 1.000 434.000 154.904 < 0.001 *
Treatment x Sex 1.010 429.020 8.682 0.003 *
Starvation
Null NA 478.000 NA NA NA
Treatment 1.000 477.000 2.681 0.102
Sex 1.000 476.000 219.907 < 0.001 *
Treatment x Sex 1.019 471.028 16.045 < 0.001 *

We see equivocal support for a treatment effect for desiccation resistance and no effect for starvation resistance. For both assays there is support for a sex effect and a treatment x sex interaction.

Calculate hazard ratios

We can use the following equation to translate the AFT coefficients, \(\beta\), to a hazard ratio, \(\alpha\): \[ \beta = -\alpha * p \] where \(p\) is the shape parameter (\(1/\)scale parameter) (see here). The shape parameter describes the change in hazard over time where:

  • \(p\) = 1: constant hazard
  • \(p\) > 1: increasing hazard over time
  • \(p\) < 1: decreasing hazard over time
# function to get hazard ratios and standard errors
hazR <- function(mod) {
  
  b_coef = c(coefficients(summary(mod)))
  coef = (b_coef * -1 * 1/mod$scale)
  HazardRatio = exp(coef)
  
  b_se = summary(mod)$table[, 2]
  se = (b_se * -1 * 1/mod$scale)
  HR.se = exp(se)
  
  return(data.frame(round(cbind(HazardRatio, HR.se), 3)[-c(1,5), ]))
  
}

For both desiccation and starvation resistance Polyandrous females live longer than Monogamy females (although not significantly so). Males die sooner than females, and Polyandry males die sooner than Monogamy males.

bind_rows(hazR(weibull.des), hazR(weibull.sta)) %>% as_tibble() %>% 
  cbind(Parameter = c('Treatment', 'Sex', 'Treatment x Sex')) %>% 
  select(Parameter, `Hazard ratio` = HazardRatio, `Std. Err.` = HR.se) %>% 
  kable() %>% 
  kable_styling() %>% 
  kable_styling(full_width = FALSE) %>%
  group_rows("Desiccation", 1, 3) %>%
  group_rows("Starvation", 4, 6)
Parameter Hazard ratio Std. Err.
Desiccation
Treatment 0.736 0.354
Sex 2.872 0.866
Treatment x Sex 1.834 0.815
Starvation
Treatment 0.674 0.458
Sex 4.231 0.876
Treatment x Sex 2.134 0.830

Plot the predicted curves

par(mar = c(5,5,2,1), mfrow = c(1,2))
# Desiccation plot
# M female
curve(pweibull(x, scale = exp(coef(weibull.des)[1]), shape = 1/weibull.des$scale, 
               lower.tail = FALSE), 
      from = 0, to = max(na.omit(DesRes$survival.time)), 
      col = 'pink', ylab = expression(hat(S)(t)), xlab='t', lwd = 2,
      main = "Desiccation resistance") 

# P female
curve(pweibull(x, scale = exp(coef(weibull.des)[1] + coef(weibull.des)[2]), 
               shape = 1/weibull.des$scale,
               lower.tail = FALSE), 
      from = 0, to = max(na.omit(DesRes$survival.time)), 
      add = T, lwd = 2, col = 'red')

# M male
curve(pweibull(x, scale = exp(coef(weibull.des)[1] + coef(weibull.des)[3]), 
               shape = 1/weibull.des$scale,
               lower.tail = FALSE), 
      from = 0, to = max(na.omit(DesRes$survival.time)), 
      add = T, col = 'skyblue', lty = 2, lwd = 2)

# P male
curve(pweibull(x, 
               scale = exp(coef(weibull.des)[1] + coef(weibull.des)[2] + coef(weibull.des)[3] + coef(weibull.des)[4]), 
               shape = 1/weibull.des$scale,
               lower.tail = FALSE), from = 0, to = max(na.omit(DesRes$survival.time)), 
      add=T, col = 'blue', lty = 2, lwd = 2)

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

# Starvation plot
# M female
curve(pweibull(x, scale = exp(coef(weibull.sta)[1]), shape = 1/weibull.sta$scale, 
               lower.tail = FALSE), 
      from = 0, to = max(na.omit(StaRes$survival.time)), 
      col = 'pink', ylab = expression(hat(S)(t)), xlab='t', lwd = 2,
      main = "Starvation resistance") 

# P female
curve(pweibull(x, scale = exp(coef(weibull.sta)[1] + coef(weibull.sta)[2]), 
               shape = 1/weibull.sta$scale,
               lower.tail = FALSE), 
      from = 0, to = max(na.omit(StaRes$survival.time)), 
      add = T, lwd = 2, col = 'red')

# M male
curve(pweibull(x, scale = exp(coef(weibull.sta)[1] + coef(weibull.sta)[3]), 
               shape = 1/weibull.sta$scale,
               lower.tail = FALSE), 
      from = 0, to = max(na.omit(StaRes$survival.time)), 
      add = T, col = 'skyblue', lty = 2, lwd = 2)

# P male
curve(pweibull(x, 
               scale = exp(coef(weibull.sta)[1] + coef(weibull.sta)[2] + coef(weibull.sta)[3] + coef(weibull.sta)[4]), 
               shape = 1/weibull.sta$scale,
               lower.tail = FALSE), from = 0, to = max(na.omit(StaRes$survival.time)), 
      add=T, col = 'blue', lty = 2, lwd = 2)

Version Author Date
96d1188 Martin Garlovsky 2020-12-13
7d4b609 Martin Garlovsky 2020-12-05

Figure X: Here we plot the model predicted survival functions (\(\hat{S}_{(t)}\)) for each sex and treatment for the two assays.

Fit the brms survival models for desiccation and starvation resistance

Here I have attempted to fit the analyses using brms. While the results of the models are qualitatively similar (sex and treatment x sex effects), I am not sure my calculation of hazard ratios is correct. Documentation for fitting survival analysis in brms still fairly sparse. Altogether I think using the simpler AFT models is sufficient.

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 + (1|LINE),
               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.rds")
} else {
  des_brm <- readRDS('output/des_brm.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 + (1|LINE),
               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.rds")
} else {
  sta_brm <- readRDS('output/sta_brm.rds')
}


# function to get hazard ratios and standard errors - needs adapting 
hazR <- function(mod) {
  
  a = c(fixef(mod)[, 1])
  coef = (a * -1 * 1/summary(mod)$spec_pars[1])
  HazardRatio = exp(coef)
  
  b = c(fixef(mod)[, 2])
  se = (b * -1 * 1/summary(mod)$spec_pars[1])
  HR.se = exp(se)
  
  return(data.frame(round(cbind(HazardRatio, HR.se), 3)[-c(1,5), ]))
  
}

Hypothesis testing

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('Polandry', 'Male', 'Polyandry x Male'),
         across(2:5, round, 3)) %>% 
  #select(-Hypothesis) %>% 
  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('Polandry', 'Male', 'Polyandry x Male'),
         across(2:5, round, 3)) %>% 
  #select(-Hypothesis) %>% 
  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
Polandry 0.054 0.107 -0.151 0.278 0.272
Male -0.183 0.025 -0.232 -0.134 < 0.001 *
Polyandry x Male -0.104 0.036 -0.173 -0.034 0.002 *
Starvation
Polandry 0.101 0.147 -0.147 0.352 0.182
Male -0.318 0.030 -0.377 -0.259 < 0.001 *
Polyandry x Male -0.167 0.042 -0.251 -0.085 < 0.001 *

Plot posteriors.

# 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_"))

Plotting the hazard ratio gives an estimate of the effect size, so we can plot the effect sizes from both experiments together.

bind_rows(post_des %>% mutate(var = 'Desiccation'), 
          post_sta %>% mutate(var = 'Starvation')) %>%
  mutate(HR = exp(value)) %>% 
  ggplot(aes(x = HR, y = key, fill = var)) + 
  geom_vline(xintercept = 1, linetype = 2) + 
  stat_halfeye(alpha = .8, position = position_dodge(width = .1)) +
  scale_fill_brewer(palette = "Dark2") +
  coord_cartesian(xlim = c(0.6, 1.5)) +
  labs(x = "Hazard ratio", y = "Model parameter") +
  theme_ridges() +
  theme(#legend.position = "none",
        legend.title = element_blank()) +
  NULL

Version Author Date
96d1188 Martin Garlovsky 2020-12-13

Summary of the results of the full model

bind_rows(
  fixef(des_brm) %>% data.frame() %>% rownames_to_column(), 
  fixef(sta_brm) %>% data.frame() %>% rownames_to_column()) %>% 
  as_tibble() %>% 
  select(Parameter = rowname, Estimate, Est.Error, Q2.5, Q97.5) %>% 
  mutate(Parameter = rep(c('Intercept', 'Polandry', 'Male', 'Polandry x Male'), 2),
         #across(2:5, exp), # this will convert to hazard ratio?
         across(2:5, round, 3)) %>%
  kable() %>% 
  kable_styling() %>% 
  kable_styling(full_width = FALSE) %>%
  group_rows("Desiccation", 1, 4) %>%
  group_rows("Starvation", 5, 8)
Parameter Estimate Est.Error Q2.5 Q97.5
Desiccation
Intercept 3.670 0.076 3.515 3.819
Polandry 0.054 0.107 -0.151 0.278
Male -0.183 0.025 -0.232 -0.134
Polandry x Male -0.104 0.036 -0.173 -0.034
Starvation
Intercept 4.071 0.101 3.889 4.249
Polandry 0.101 0.147 -0.147 0.352
Male -0.318 0.030 -0.377 -0.259
Polandry x Male -0.167 0.042 -0.251 -0.085

Extract posterior estimates and plot

# wrangle
des_fit <-
  fixef(des_brm) %>% 
  data.frame() %>% 
  rownames_to_column() %>% 
  mutate(param = str_remove(rowname, "m|P")) %>% 
  tidyr::expand(nesting(Estimate, Q2.5, Q97.5, param),
         survival.time = 0:100) %>% 
  mutate(m  = 1 - pexp(survival.time, rate = 1 / exp(Estimate)),
         ll = 1 - pexp(survival.time, rate = 1 / exp(Q2.5)),
         ul = 1 - pexp(survival.time, rate = 1 / exp(Q97.5)))
  
# plot!
des_fit %>% 
  ggplot(aes(x = survival.time)) +
#  geom_hline(yintercept = .5, linetype = 3, aes(color = param)) +
  geom_ribbon(aes(ymin = ll, ymax = ul, fill = param),
              alpha = 1/2) +
 # geom_line(aes(y = m, aes(color = cols))) +
  # scale_fill_manual(values = wes_palette("Moonrise2")[c(4, 1)], breaks = NULL) +
  # scale_color_manual(values = wes_palette("Moonrise2")[c(4, 1)], breaks = NULL) +
  # scale_y_continuous("proportion remaining", , breaks = c(0, .5, 1), limits = c(0, 1)) +
  labs(x = "Survival time (hours)") +
  NULL

Version Author Date
96d1188 Martin Garlovsky 2020-12-13
des_fit %>% 
  ggplot(aes(x = survival.time, y = m, colour = param)) +
  geom_line() +
  geom_ribbon(aes(ymin = ll, ymax = ul, fill = param), alpha = 1/2) +
  scale_colour_manual(values = c("pink", "red", "skyblue", "blue")) +
  scale_fill_manual(values = c("pink", "red", "skyblue", "blue")) +
  theme_bw() +
  theme() +
  NULL

Version Author Date
96d1188 Martin Garlovsky 2020-12-13

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

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_AU.UTF-8/en_AU.UTF-8/en_AU.UTF-8/C/en_AU.UTF-8/en_AU.UTF-8

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

other attached packages:
 [1] knitrhooks_0.0.4 knitr_1.30       kableExtra_1.1.0 ggridges_0.5.2  
 [5] tidybayes_2.0.3  brms_2.14.4      Rcpp_1.0.4.6     lme4_1.1-23     
 [9] Matrix_1.2-18    coxme_2.2-16     bdsmatrix_1.3-4  survival_3.2-7  
[13] forcats_0.5.0    stringr_1.4.0    dplyr_1.0.0      purrr_0.3.4     
[17] readr_1.3.1      tidyr_1.1.0      tibble_3.0.1     ggplot2_3.3.2   
[21] tidyverse_1.3.0  workflowr_1.6.2 

loaded via a namespace (and not attached):
  [1] readxl_1.3.1         backports_1.1.7      plyr_1.8.6          
  [4] igraph_1.2.5         svUnit_1.0.3         splines_4.0.3       
  [7] crosstalk_1.1.0.1    TH.data_1.0-10       rstantools_2.1.1    
 [10] inline_0.3.15        digest_0.6.25        htmltools_0.5.0     
 [13] rsconnect_0.8.16     fansi_0.4.1          magrittr_2.0.1      
 [16] openxlsx_4.1.5       modelr_0.1.8         RcppParallel_5.0.1  
 [19] matrixStats_0.56.0   xts_0.12-0           sandwich_2.5-1      
 [22] prettyunits_1.1.1    colorspace_1.4-1     blob_1.2.1          
 [25] rvest_0.3.5          haven_2.3.1          xfun_0.19           
 [28] callr_3.4.3          crayon_1.3.4         jsonlite_1.7.0      
 [31] zoo_1.8-8            glue_1.4.2           survminer_0.4.8     
 [34] gtable_0.3.0         emmeans_1.4.7        webshot_0.5.2       
 [37] V8_3.4.0             car_3.0-8            pkgbuild_1.0.8      
 [40] rstan_2.21.2         abind_1.4-5          scales_1.1.1        
 [43] mvtnorm_1.1-0        DBI_1.1.0            rstatix_0.5.0       
 [46] miniUI_0.1.1.1       viridisLite_0.3.0    xtable_1.8-4        
 [49] foreign_0.8-80       km.ci_0.5-2          stats4_4.0.3        
 [52] StanHeaders_2.21.0-3 DT_0.13              htmlwidgets_1.5.1   
 [55] httr_1.4.1           threejs_0.3.3        arrayhelpers_1.1-0  
 [58] ellipsis_0.3.1       farver_2.0.3         pkgconfig_2.0.3     
 [61] loo_2.3.1            dbplyr_1.4.4         labeling_0.3        
 [64] tidyselect_1.1.0     rlang_0.4.6          reshape2_1.4.4      
 [67] later_1.0.0          munsell_0.5.0        cellranger_1.1.0    
 [70] tools_4.0.3          cli_2.0.2            generics_0.0.2      
 [73] broom_0.5.6          evaluate_0.14        fastmap_1.0.1       
 [76] yaml_2.2.1           processx_3.4.2       fs_1.4.1            
 [79] zip_2.0.4            survMisc_0.5.5       nlme_3.1-149        
 [82] whisker_0.4          mime_0.9             projpred_2.0.2      
 [85] xml2_1.3.2           compiler_4.0.3       bayesplot_1.7.2     
 [88] shinythemes_1.1.2    rstudioapi_0.11      gamm4_0.2-6         
 [91] curl_4.3             ggsignif_0.6.0       reprex_0.3.0        
 [94] statmod_1.4.34       stringi_1.5.3        highr_0.8           
 [97] ps_1.3.3             Brobdingnag_1.2-6    lattice_0.20-41     
[100] nloptr_1.2.2.1       markdown_1.1         KMsurv_0.1-5        
[103] shinyjs_1.1          vctrs_0.3.0          pillar_1.4.4        
[106] lifecycle_0.2.0      bridgesampling_1.0-0 estimability_1.3    
[109] insight_0.8.4        data.table_1.12.8    httpuv_1.5.3.1      
[112] R6_2.4.1             promises_1.1.0       rio_0.5.16          
[115] gridExtra_2.3        codetools_0.2-16     boot_1.3-25         
[118] colourpicker_1.0     MASS_7.3-53          gtools_3.8.2        
[121] assertthat_0.2.1     rprojroot_1.3-2      withr_2.2.0         
[124] shinystan_2.5.0      multcomp_1.4-13      bayestestR_0.6.0    
[127] mgcv_1.8-33          parallel_4.0.3       hms_0.5.3           
[130] grid_4.0.3           coda_0.19-3          minqa_1.2.4         
[133] rmarkdown_2.5        carData_3.0-4        ggpubr_0.3.0        
[136] git2r_0.27.1         shiny_1.4.0.2        lubridate_1.7.8     
[139] base64enc_0.1-3      dygraphs_1.1.1.6