Last updated: 2022-01-24

Checks: 7 0

Knit directory: genes-to-foodweb-stability/

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(20200205) 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 18d1722. 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:    .Rhistory
    Ignored:    .Rproj.user/
    Ignored:    code/.Rhistory
    Ignored:    output/.Rapp.history

Untracked files:
    Untracked:  output/all.mar1.brm.adj.rds
    Untracked:  output/all.mar1.brm.unadj.ar2.lag.rds
    Untracked:  output/all.mar1.brm.unadj.noBRBRonLYER.rds
    Untracked:  output/all.mar1.brm.unadj.rds
    Untracked:  output/all.mar1.brm.unadj.xAOP2.rds
    Untracked:  output/initial.mar1.brm.adj.rds
    Untracked:  output/initial.mar1.brm.unadj.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/plant-growth-no-insects-lme.Rmd) and HTML (docs/plant-growth-no-insects-lme.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 18d1722 mabarbour 2022-01-24 Add mark-recapture and omnibus tests, fix data point error, update analyses, and edit readme
html c802852 mabarbour 2021-06-24 Build website
Rmd a054471 mabarbour 2021-06-24 Update location of .rds files to Release v2.1
Rmd f467085 mabarbour 2021-06-24 Revise analysis to address reviewer’s comments

Wrangle data

# load data
ChamberNoInsectsDF <- read_csv("data/PreExperimentNoInsectsPlantBiomass.csv") %>%
  mutate(Cage = as.character(Cage),
         Pot = as.character(Pot))

# conduct analyses at cage level
CageLevelBiomass <- ChamberNoInsectsDF %>%
  # sum biomass across both pots
  group_by(Cage, Temperature, Richness, Composition, Col, gsm1, AOP2, AOP2.gsoh) %>%
  summarise_at(vars(Biomass_g), list(sum)) %>%
  # tidy data
  ungroup() %>%
  select(cage = Cage, temp = Temperature, rich = Richness, com = Composition, Col, gsm1, AOP2, AOP2.gsoh, Biomass_g) %>%
  # adjust temp and rich so effect of +1 C is comparable to +1 genotype
  mutate(temp = ifelse(temp == "20 C", 0, 3),
         rich = rich - 1,
         # define orthogonal constrasts to test for above-average allele effects.
        # aop2_vs_AOP2 must be included first
        aop2_vs_AOP2 = Col + gsm1 - AOP2 - AOP2.gsoh,
        mam1_vs_MAM1 = gsm1 - Col, # aop2_vs_AOP2 must be included in model
        gsoh_vs_GSOH = AOP2.gsoh - AOP2)

Reproduce Table S5

# fit model
log_biomass_lmer <- lmer(log(Biomass_g) ~ temp*(rich + aop2_vs_AOP2 + mam1_vs_MAM1 + gsoh_vs_GSOH) + (1|com/temp), 
                        data = CageLevelBiomass)

# reproduce table S5
anova(log_biomass_lmer, type = "1", ddf = "Kenward-Roger") %>%
  kable(., caption = "Analysis of variance for plant biomass (log transformed) in the absence of insects.", booktabs = T) %>%
  kable_styling(latex_options = c("striped", "hold_position"))
Analysis of variance for plant biomass (log transformed) in the absence of insects.
Sum Sq Mean Sq NumDF DenDF F value Pr(>F)
temp 4.2342063 4.2342063 1 5.220228 52.8748142 0.0006393
rich 0.0110385 0.0110385 1 4.951544 0.1378439 0.7257894
aop2_vs_AOP2 1.2616246 1.2616246 1 5.791912 15.7545862 0.0079189
mam1_vs_MAM1 0.0410509 0.0410509 1 5.791912 0.5126251 0.5018356
gsoh_vs_GSOH 0.0148935 0.0148935 1 5.791912 0.1859833 0.6818684
temp:rich 0.0097817 0.0097817 1 4.427930 0.1221488 0.7427133
temp:aop2_vs_AOP2 0.0035946 0.0035946 1 5.647776 0.0448871 0.8396490
temp:mam1_vs_MAM1 0.0541709 0.0541709 1 5.647776 0.6764608 0.4441364
temp:gsoh_vs_GSOH 0.0669588 0.0669588 1 5.647776 0.8361506 0.3978575
# omnibus test compared to null (reported in Notes section)
log_biomass_null <- lmer(log(Biomass_g) ~ 1 + (1|com/temp), data = CageLevelBiomass)
KRmodcomp(log_biomass_lmer, log_biomass_null)
large : log(Biomass_g) ~ temp * (rich + aop2_vs_AOP2 + mam1_vs_MAM1 + 
    gsoh_vs_GSOH) + (1 | com/temp)
small : log(Biomass_g) ~ 1 + (1 | com/temp)
        stat    ndf    ddf F.scaling p.value  
Ftest 7.4483 9.0000 5.9911    0.9438 0.01197 *
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# omnibust test main vs null
log_biomass_main <- lmer(log(Biomass_g) ~ temp + rich + aop2_vs_AOP2 + mam1_vs_MAM1 + gsoh_vs_GSOH + (1|com/temp), data = CageLevelBiomass)
KRmodcomp(log_biomass_main, log_biomass_null)
large : log(Biomass_g) ~ temp + rich + aop2_vs_AOP2 + mam1_vs_MAM1 + 
    gsoh_vs_GSOH + (1 | com/temp)
small : log(Biomass_g) ~ 1 + (1 | com/temp)
         stat     ndf     ddf F.scaling  p.value   
Ftest 17.0402  5.0000  6.6068   0.95932 0.001122 **
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
KRmodcomp(log_biomass_lmer, log_biomass_main)
large : log(Biomass_g) ~ temp * (rich + aop2_vs_AOP2 + mam1_vs_MAM1 + 
    gsoh_vs_GSOH) + (1 | com/temp)
small : log(Biomass_g) ~ temp + rich + aop2_vs_AOP2 + mam1_vs_MAM1 + 
    gsoh_vs_GSOH + (1 | com/temp)
        stat    ndf    ddf F.scaling p.value
Ftest 0.4197 4.0000 5.2877   0.99955  0.7897

Reproduce Fig. S10

# calculate 95% confidence intervals, but first remove higher-order statistical interactions
summary(lme4::lmer(log(Biomass_g) ~ temp + rich + aop2_vs_AOP2 + (1|com), data = CageLevelBiomass)) # dropped com:temp, because it was singular, it also doesn't matter for estimating confidence intervals for genetic effect, it would matter if we were trying to estimate temp, which we are only controlling for here.
Linear mixed model fit by REML ['lmerMod']
Formula: log(Biomass_g) ~ temp + rich + aop2_vs_AOP2 + (1 | com)
   Data: CageLevelBiomass

REML criterion at convergence: 39.1

Scaled residuals: 
    Min      1Q  Median      3Q     Max 
-2.7409 -0.4813  0.1360  0.5751  2.4735 

Random effects:
 Groups   Name        Variance Std.Dev.
 com      (Intercept) 0.009476 0.09735 
 Residual             0.081126 0.28483 
Number of obs: 60, groups:  com, 11

Fixed effects:
             Estimate Std. Error t value
(Intercept)  -0.05210    0.07843  -0.664
temp         -0.21085    0.02451  -8.601
rich         -0.02374    0.05456  -0.435
aop2_vs_AOP2  0.19691    0.04554   4.324

Correlation of Fixed Effects:
            (Intr) temp   rich  
temp        -0.469              
rich        -0.645  0.000       
ap2_vs_AOP2  0.000  0.000  0.000
aop2_CI <- tidy(lmer(log(Biomass_g) ~ -1 + temp + I(AOP2 + AOP2.gsoh) + I(Col + gsm1) + (1|com), 
                     data = CageLevelBiomass), 
                conf.int = T, conf.level = 0.95) %>%
  filter(term %in% c("I(AOP2 + AOP2.gsoh)","I(Col + gsm1)")) %>%
  mutate(allele = c("AOP2","aop2"))
# note that I back transform to original scale for plotting
exp(aop2_CI$estimate[2])
[1] 1.17452
# get the effect of each genotype
mean_geno <- tidy(lmer(log(Biomass_g) ~ -1 + temp + AOP2 + AOP2.gsoh + Col + gsm1 + (1|com), 
                     data = CageLevelBiomass), 
                conf.int = T, conf.level = 0.95) %>%
  filter(term %in% c("AOP2","AOP2.gsoh","Col","gsm1")) %>%
  mutate(allele = c("AOP2","AOP2","aop2","aop2"),
         term = factor(term, levels = c("Col","gsm1","AOP2","AOP2.gsoh"), labels = c("Col","gsm1","AOP2","AOP2/gsoh")))

# plot on original scale
# adding a genotype with an aop2 allele to the population doubles the likelihood of species persistence
plot_AOP2_growth_no_insects <- ggplot(aop2_CI, aes(x = allele, y = exp(estimate))) +
  geom_point(size = 5) +
  geom_point(data = mean_geno, aes(color = term), size = 5, position = position_dodge(width = 0.3)) +
  geom_linerange(aes(ymax = exp(estimate + std.error), ymin = exp(estimate - std.error)), size = 1.5) +
  geom_linerange(aes(ymax = exp(conf.high), ymin = exp(conf.low))) +
  scale_x_discrete(labels = c("AOP2\u2013","AOP2+")) +
  scale_y_continuous("Plant biomass (g)") +
  xlab("Allele") + 
  scale_color_manual(values = c("darkgreen","steelblue","darkorange","firebrick1"), name = "") + 
  theme_cowplot(font_size = 18, line_size = 1)

x11(); plot_AOP2_growth_no_insects

ggsave(plot = plot_AOP2_growth_no_insects, filename = "figures/AOP2-growth-no-insects.pdf", height = 6, width = 8, device=cairo_pdf)

Version Author Date
c802852 mabarbour 2021-06-24

sessionInfo()
R version 4.1.2 (2021-11-01)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 16.04.7 LTS

Matrix products: default
BLAS:   /usr/lib/libblas/libblas.so.3.6.0
LAPACK: /usr/lib/lapack/liblapack.so.3.6.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

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

other attached packages:
 [1] pbkrtest_0.5.1    broom.mixed_0.2.6 lmerTest_3.1-3    lme4_1.1-27.1    
 [5] Matrix_1.4-0      cowplot_1.1.1     kableExtra_1.3.4  forcats_0.5.1    
 [9] stringr_1.4.0     dplyr_1.0.7       purrr_0.3.4       readr_2.1.1      
[13] tidyr_1.1.4       tibble_3.1.6      ggplot2_3.3.5     tidyverse_1.3.1  
[17] workflowr_1.6.2  

loaded via a namespace (and not attached):
 [1] nlme_3.1-152        fs_1.5.2            bit64_4.0.5        
 [4] lubridate_1.8.0     webshot_0.5.2       httr_1.4.2         
 [7] rprojroot_2.0.2     numDeriv_2016.8-1.1 TMB_1.7.22         
[10] tools_4.1.2         backports_1.4.1     bslib_0.3.1        
[13] utf8_1.2.2          R6_2.5.1            DBI_1.1.2          
[16] colorspace_2.0-2    withr_2.4.3         tidyselect_1.1.1   
[19] bit_4.0.4           compiler_4.1.2      git2r_0.28.0       
[22] cli_3.1.0           rvest_1.0.2         xml2_1.3.3         
[25] labeling_0.4.2      sass_0.4.0          scales_1.1.1       
[28] systemfonts_1.0.3   digest_0.6.29       minqa_1.2.4        
[31] rmarkdown_2.11      svglite_1.2.3.2     pkgconfig_2.0.3    
[34] htmltools_0.5.2     highr_0.9           dbplyr_2.1.1       
[37] fastmap_1.1.0       rlang_0.4.12        readxl_1.3.1       
[40] rstudioapi_0.13     farver_2.1.0        jquerylib_0.1.4    
[43] generics_0.1.1      jsonlite_1.7.2      vroom_1.5.7        
[46] magrittr_2.0.1      Rcpp_1.0.7          munsell_0.5.0      
[49] fansi_1.0.0         gdtools_0.2.3       lifecycle_1.0.1    
[52] stringi_1.7.3       whisker_0.4         yaml_2.2.1         
[55] MASS_7.3-54         plyr_1.8.6          grid_4.1.2         
[58] parallel_4.1.2      promises_1.2.0.1    crayon_1.4.2       
[61] lattice_0.20-45     haven_2.4.3         splines_4.1.2      
[64] hms_1.1.1           knitr_1.37          pillar_1.6.4       
[67] boot_1.3-28         reshape2_1.4.4      reprex_2.0.1       
[70] glue_1.6.0          evaluate_0.14       modelr_0.1.8       
[73] vctrs_0.3.8         nloptr_1.2.2.3      tzdb_0.2.0         
[76] httpuv_1.6.5        cellranger_1.1.0    gtable_0.3.0       
[79] assertthat_0.2.1    xfun_0.29           broom_0.7.11       
[82] coda_0.19-4         later_1.3.0         viridisLite_0.4.0  
[85] ellipsis_0.3.2