Last updated: 2020-10-11
Checks: 7 0
Knit directory: genes-to-foodweb-stability/
This reproducible R Markdown analysis was created with workflowr (version 1.6.0). 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 version displayed above was the version of the Git repository at the time these results were generated.
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
Untracked files:
Untracked: output/community-persistence-keystone.RData
Untracked: output/critical-transitions-keystone.RData
Untracked: output/structural-stability-keystone.RData
Unstaged changes:
Modified: output/plant-growth-no-insects.RData
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 R Markdown and HTML files. If you’ve configured a remote Git repository (see ?wflow_git_remote
), click on the hyperlinks in the table below to view them.
File | Version | Author | Date | Message |
---|---|---|---|---|
Rmd | 761af40 | mabarbour | 2020-10-11 | Refocus analysis on keystone gene result. |
html | 51fc18b | mabarbour | 2020-06-23 | Build site. |
Rmd | 86116c8 | mabarbour | 2020-06-23 | bioRxiv version of code and data. |
html | 86116c8 | mabarbour | 2020-06-23 | bioRxiv version of code and 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)
# source in ANOVA GLM for adjusted F-tests
source('code/glm-ftest.R')
An Analysis of deviance on a GLM with a gaussian error distribution is equivalent to ANOVA. However, unadjusted F-tests are inappropriate because all terms are tested against residual variation rather than the intended error level (e.g. com
for rich
). The analysis below is just to prove this equivalence. I’m doing this so I can use the same function glm.ftest.v2
for the ANOVA in the following section.
glm.ftest.v2(
model = glm(data = CageLevelBiomass,
family = gaussian(link = "identity"),
# logging improves residual distribution
formula = log(Biomass_g) ~ temp + rich + com + temp:rich + temp:com),
test.formula = list(c("temp","temp:com"),
c("rich","com"),
c("temp:rich","temp:com")))[[1]]
term df dev mean_dev F P
1 temp 1 6.002 6.002 75.51 0.0000
2 rich 1 0.038 0.038 0.48 0.4948
3 com 9 3.396 0.377 4.75 0.0003
4 temp:rich 1 0.027 0.027 0.34 0.5656
5 temp:com 9 0.826 0.092 1.15 0.3511
6 Residuals 38 3.021 0.079 NA NA
anova(aov(log(Biomass_g) ~ temp + rich + com + temp:rich + temp:com, CageLevelBiomass))
Analysis of Variance Table
Response: log(Biomass_g)
Df Sum Sq Mean Sq F value Pr(>F)
temp 1 6.0019 6.0019 75.5075 1.455e-10 ***
rich 1 0.0378 0.0378 0.4753 0.4947633
com 9 3.3961 0.3773 4.7473 0.0002907 ***
temp:rich 1 0.0267 0.0267 0.3360 0.5655796
temp:com 9 0.8256 0.0917 1.1540 0.3511397
Residuals 38 3.0205 0.0795
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# fit ANOVA
biomass_noinsects_glmf <- glm.ftest.v2(
model = glm(data = CageLevelBiomass,
family = gaussian(link = "identity"),
# logging improves residual distribution
formula = log(Biomass_g) ~ temp + rich + aop2_vs_AOP2 + mam1_vs_MAM1 + gsoh_vs_GSOH + com + temp:(rich + aop2_vs_AOP2 + mam1_vs_MAM1 + gsoh_vs_GSOH) + temp:com),
test.formula = list(c("temp","temp:com"),
c("rich","com"),
c("aop2_vs_AOP2","com"),
c("mam1_vs_MAM1","com"),
c("gsoh_vs_GSOH","com"),
c("temp:rich","temp:com"),
c("temp:aop2_vs_AOP2","temp:com"),
c("temp:mam1_vs_MAM1","temp:com"),
c("temp:gsoh_vs_GSOH","temp:com")))[[3]] %>%
# tidy table
select(Source = treatment,
`df (Source)` = num_df,
`df (Error)` = den_df,
Deviance = deviance,
`Mean Deviance` = mean_deviance,
F = F, P = P, Error = error)
# reproduce table S5 in Supplementary Materials
biomass_noinsects_glmf %>%
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"))
Source | df (Source) | df (Error) | Deviance | Mean Deviance | F | P | Error |
---|---|---|---|---|---|---|---|
temp | 1 | 6 | 6.00 | 6.00 | 53.881 | <0.001 | temp:com |
rich | 1 | 6 | 0.04 | 0.04 | 0.242 | 0.64 | com |
aop2_vs_AOP2 | 1 | 6 | 2.34 | 2.34 | 14.952 | 0.008 | com |
mam1_vs_MAM1 | 1 | 6 | 0.08 | 0.08 | 0.505 | 0.504 | com |
gsoh_vs_GSOH | 1 | 6 | 0.04 | 0.04 | 0.287 | 0.612 | com |
temp:rich | 1 | 6 | 0.03 | 0.03 | 0.240 | 0.642 | temp:com |
temp:aop2_vs_AOP2 | 1 | 6 | 0.00 | 0.00 | 0.039 | 0.849 | temp:com |
temp:mam1_vs_MAM1 | 1 | 6 | 0.06 | 0.06 | 0.582 | 0.474 | temp:com |
temp:gsoh_vs_GSOH | 1 | 6 | 0.09 | 0.09 | 0.790 | 0.408 | temp:com |
# calculate 95% confidence intervals with `com` as the cluster level
aop2_CI <- conf_int(
glm(data = CageLevelBiomass,
family = gaussian(link = "identity"),
formula = log(Biomass_g) ~ -1 + temp + I(AOP2 + AOP2.gsoh) + I(Col + gsm1)),
vcov = "CR2",
test = "naive-t",
coefs = c("I(AOP2 + AOP2.gsoh)","I(Col + gsm1)"),
cluster = CageLevelBiomass$com) %>%
data.frame() %>%
rownames_to_column(var = "term") %>%
mutate(allele = c("AOP2","aop2"))
# note that I back transform to original scale for plotting
exp(aop2_CI$beta[2])
[1] 1.169096
# get the effect of each genotype
mean_geno <- conf_int(
glm(data = CageLevelBiomass,
family = gaussian(link = "identity"),
formula = log(Biomass_g) ~ -1 + temp + AOP2 + AOP2.gsoh + Col + gsm1),
vcov = "CR2",
test = "naive-t",
cluster = CageLevelBiomass$com,
coefs = c("AOP2","AOP2.gsoh","Col","gsm1")
) %>%
data.frame() %>%
rownames_to_column(var = "term") %>%
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
ggplot(aop2_CI, aes(x = allele, y = exp(beta))) +
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(beta + SE), ymin = exp(beta - SE)), size = 1.5) +
geom_linerange(aes(ymax = exp(CI_U), ymin = exp(CI_L))) +
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)
Version | Author | Date |
---|---|---|
86116c8 | mabarbour | 2020-06-23 |
# ggsave(filename = "figures/AOP2-growth-no-insects.pdf", height = 6, width = 8, device=cairo_pdf)
Write out an .RData
file to use for creating the Supplementary Material Results.
# save.image(file = "output/plant-growth-no-insects.RData")
sessionInfo()
R version 3.6.3 (2020-02-29)
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] cowplot_1.0.0 clubSandwich_0.3.5 kableExtra_1.1.0 forcats_0.4.0
[5] stringr_1.4.0 dplyr_0.8.3 purrr_0.3.3 readr_1.3.1
[9] tidyr_1.0.2 tibble_2.1.3 ggplot2_3.2.1 tidyverse_1.3.0
loaded via a namespace (and not attached):
[1] Rcpp_1.0.2 lubridate_1.7.4 lattice_0.20-38 zoo_1.8-6
[5] assertthat_0.2.1 rprojroot_1.3-2 digest_0.6.20 R6_2.4.0
[9] cellranger_1.1.0 backports_1.1.4 reprex_0.3.0 evaluate_0.14
[13] httr_1.4.1 highr_0.8 pillar_1.4.2 rlang_0.4.4
[17] lazyeval_0.2.2 readxl_1.3.1 rstudioapi_0.10 whisker_0.3-2
[21] rmarkdown_2.0 labeling_0.3 webshot_0.5.1 munsell_0.5.0
[25] broom_0.5.2 compiler_3.6.3 httpuv_1.5.1 modelr_0.1.5
[29] xfun_0.9 pkgconfig_2.0.2 htmltools_0.3.6 tidyselect_0.2.5
[33] workflowr_1.6.0 viridisLite_0.3.0 crayon_1.3.4 dbplyr_1.4.2
[37] withr_2.1.2 later_1.0.0 grid_3.6.3 nlme_3.1-140
[41] jsonlite_1.6 gtable_0.3.0 lifecycle_0.1.0 DBI_1.0.0
[45] git2r_0.26.1 magrittr_1.5 scales_1.0.0 cli_1.1.0
[49] stringi_1.4.3 fs_1.3.1 promises_1.0.1 xml2_1.2.2
[53] generics_0.0.2 vctrs_0.2.2 sandwich_2.5-1 tools_3.6.3
[57] glue_1.3.1 hms_0.5.3 yaml_2.2.0 colorspace_1.4-1
[61] rvest_0.3.5 knitr_1.26 haven_2.2.0