Skip to content

Commit

Permalink
Tidy for release
Browse files Browse the repository at this point in the history
- more in readme
- remove redundant code
- add simple analysis.R script
  • Loading branch information
dfalster committed Mar 25, 2021
1 parent 2ad05ef commit c6370be
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 161 deletions.
150 changes: 0 additions & 150 deletions R/ms.R

This file was deleted.

7 changes: 0 additions & 7 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,3 @@ label_panel <- function(i, ...) {
label(sprintf("%s)", letters[i]), ...)
}

render_pdf <- function(filename) {
owd <- setwd(dirname(filename))
on.exit(setwd(owd))
filename <- basename(filename)
dest <- paste0(sub("\\.md", "", filename), ".pdf")
call_system(Sys_which("pandoc"), c(filename, "-o", dest))
}
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
# Competition kernels
# Emergent shapes of trait-based competition functions from resource-based models

Code for the competition kernels.
This repository contains all the code used in the manuscript:

Falster DS, Kunstler G, FitzJohn RG, Westoby M (2021) "Emergent shapes of trait-based competition functions from resource-based models: A Gaussian is not normal in plant communities." *The American Naturalist*

Abstract: In community ecology, it is widely assumed that organisms with similar traits compete more intensely with one another for resources. This assumption is often encoded into theory and empirical tests, via a unimodal competition function, which predicts that per capita competitive effect declines with separation in traits. Yet, it remains unknown how well this function represents the true effect of traits on competitive outcomes, especially for long-lived plant communities where lifetime fitness is difficult to estimate. Here we evaluate the shape of competition functions embedded in two resource-based (RB) models, wherein plants compete for shared, essential resources. In the first RB model, individuals compete for two essential nutrients, and in the second they compete for light in a size-based successional setting. We compared the shapes of the competition functions that emerged from interactions within these RB models to the unimodal function and others shapes commonly applied. In few instances did the trait-based competition function emerging from the RB model even vaguely resemble any of the shapes previously used. The mismatch between these two approaches suggests that theory derived using fixed competition functions based on trait separation may not apply well to plant systems where individuals compete for shared resources. The more promising path will be to model depletion of resources by populations in relation to their traits, with its consequences for fitness landscapes and competitive exclusion.

Additional accessory files are also including:

- `DECRIPTION`: A machine-readable [compendium]() file containing key metadata and dependencies
- `DECRIPTION`: A machine-readable compendium file containing key metadata and dependencies
- `LICENSE`: License for the materials
- `Dockerfile` & `.binder/Dockerfile`: files used to generate docker containers for long-term reproducibility

Expand All @@ -14,7 +17,7 @@ Additional accessory files are also including:
All analyses were done in `R`, and the paper is written in LaTeX. All code needed to reproduce the submitted products is included in this repository. To reproduce this paper, run the code contained in the `analysis.R` file. Figures will be output to a directory called `output` and the paper and supplementary materials in the folder `ms`.


The paper was written in 2016 using a version of R available at the time. With some minor updates, the code has been updated and was last seen running wild and free on R 3.6.1. You can try running it on your current version and it may work.
The paper was written in 2016 using a version of R available at the time. With some minor updates, the code has been updated and was last seen running wild and free on R 4.0. You can try running it on your current version and it may work.

To ensure [computational reproducibility](https://www.britishecologicalsociety.org/wp-content/uploads/2017/12/guide-to-reproducible-code.pdf) into the future, we have also generated [Docker](http://dockerhub.com) and [Binder](https://mybinder.org) containers, enabling you to launch a compute environment built off R 3.6.1 with all the dependencies included.

Expand Down Expand Up @@ -71,3 +74,4 @@ Contributors
Daniel Falster
Rich FitzJohn
Georges Kunstler
Saras Windecker (docker)
104 changes: 104 additions & 0 deletions analysis.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
library("rootSolve")
library("rmarkdown")
library("tinytex")
library("nleqslv")
library("numDeriv")
library("deSolve")
library("plant")
source("R/competition.R")
source("R/dd99.R")
source("R/figures.R")
source("R/plant_competition.R")
source("R/plant_figure.R")
source("R/rstar_figure.R")
source("R/rstar_model.R")
source("R/rstar_plot.R")
source("R/rstar_support.R")
source("R/shapes.R")
source("R/utils.R")
dir.create("ms/figures", FALSE, TRUE)
dir.create("ms/figures/shape", FALSE, TRUE)

pdf("ms/figures/kernel.pdf", height = 3.5, width = 5.5, pointsize = 10L)
fig_kernel()
dev.off()

pdf("ms/figures/components.pdf", height = 4L, width = 8L)
fig_components()
dev.off()

pdf("ms/figures/rstar_components_U_1.pdf", height = 4L, width = 8L)
fig_rstar_components(1)
dev.off()

pdf("ms/figures/rstar_components_U_2.pdf", height = 4L, width = 8L)
fig_rstar_components(2)
dev.off()

pdf("ms/figures/rstar_components_UC_1.pdf", height = 4L, width = 8L)
fig_rstar_components(3)
dev.off()

pdf("ms/figures/rstar_components_UC_2.pdf", height = 4L, width = 8L)
fig_rstar_components(4)
dev.off()

pdf("ms/figures/shape/constant.pdf", height = 1.3, width = 2L)
shape_constant()
dev.off()

pdf("ms/figures/shape/gaussian.pdf", height = 1.3, width = 2L)
shape_gaussian()
dev.off()

pdf("ms/figures/shape/platykurtic.pdf", height = 1.3, width = 2L)
shape_platykurtic()
dev.off()

pdf("ms/figures/shape/logistic.pdf", height = 1.3, width = 2L)
shape_logistic()
dev.off()

pdf("ms/figures/shape/gaussian_offset.pdf", height = 1.3, width = 2L)
shape_gaussian_offset()
dev.off()

pdf("ms/figures/shape/exponential.pdf", height = 1.3, width = 2L)
shape_exponential()
dev.off()

pdf("ms/figures/shape/gaussian_with_hat.pdf", height = 1.3, width = 2L)
shape_gaussian_with_hat()
dev.off()

pdf("ms/figures/shape/laplacian.pdf", height = 1.3, width = 2L)
shape_laplacian()
dev.off()

pdf("ms/figures/shape/gaussian_with_spike.pdf", height = 1.3,
width = 2L)
shape_gaussian_with_spike()
dev.off()

pdf("ms/figures/shape/step_asymmetric.pdf", height = 1.3, width = 2L)
shape_step_asymmetric()
dev.off()

plant_lma_shared <- plant_competition_prepare("lma", parallel = TRUE)
plant_hmat_shared <- plant_competition_prepare("hmat", parallel = TRUE)

plant_lma_1 <- plant_competition(0.17, plant_lma_shared)
plant_lma_2 <- plant_competition(0.07, plant_lma_shared)
plant_hmat_1 <- plant_competition(5, plant_hmat_shared)
plant_hmat_2 <- plant_competition(15.5, plant_hmat_shared)

pdf("ms/figures/plant_lma_components.pdf", height = 4L, width = 8L)
fig_plant_components(plant_lma_1, plant_lma_2)
dev.off()

pdf("ms/figures/plant_hmat_components.pdf", height = 4L, width = 8L)
fig_plant_components(plant_hmat_1, plant_hmat_2)
dev.off()

pdflatex("ms/competition-kernels.tex")
pdflatex("ms/competition-kernels-sm.tex")

0 comments on commit c6370be

Please sign in to comment.