| title | High sparrow body length decreases survival | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| author | Brad Duthie | ||||||||||
| date | Biological and Environmental Sciences, University of Stirling, Stirling, UK, FK9 4LA | ||||||||||
| output |
|
||||||||||
| header-includes |
|
||||||||||
| linestretch | 2 | ||||||||||
| link-citations | true | ||||||||||
| linkcolor | blue | ||||||||||
| csl | evolution.csl | ||||||||||
| subtitle | A demonstration of Rmarkdown using Herman Bumpus' data | ||||||||||
| bibliography | refs.bib |
Writing documents in Rmarkdown using Rstudio can make scientific workflow more efficient, and here I demonstrate how a scientific manuscript can be written using a classical data set first published by Herman Bumpus. I integrate Bumpus' data with Rmarkdown to produce a sample manuscript, testing whether or not sparrow body length decreases survival following a storm in southern New England. Using a t-test, I show that surviving birds have lower body length than birds that do not survive. All analyses of data are incorporated into the underlying Rmarkdown document, including figures and a table. References are incorporated using BibTeX. The underlying code for this manuscript is publicly available on GitHub as part of the Stirling Coding Club organisation.
In the late 1800s, there was a particularly severe snowstorm in Providence, Rhode Island. <!--- BD: I think this sentence needs some adjustment ---> At the time, Herman Bumpus was a professor of comparative zoology at Brown University. Bumpus noticed that the storm had a particularly negative effect on the local sparrow population (Passer domesticus) and decided to use the event to test Charle's Darwin's theory of natural selection [@Darwin1859]. Bumpus collected 136 sparrows; some of these sparrows survived the storm, while others perished. @Bumpus1898 published a paper and all of the data that he had collected. These data are now a classic data set in biology, and have been analysed multiple times [e.g., @Johnston1972]. Here I will use Bumpus' data to demonstrate how to write a scientific manuscript in Rmarkdown.
The focus of this manuscript is therefore not on Bumpus' data or survival of sparrows per se, but the process of scientific writing using Rmarkdown. I have chosen the Bumpus data set because it provides a useful tool for working through most key features of Rmarkdown that scientists might want to use when writing a manuscript. The example question that I will address through this data set and R analysis in Rmarkdown is whether or not increasing sparrow body length is associated with decreased survival following a storm.
Bumpus focused his study on the House Sparrow (Passer domesticus; see Figure 1), which has a very wide global distribution. It is native to Europe and Asia, but not the Americas where Bumpus collected his original study [@Bumpus1898]. In addition to measuring total length and survival for 136 sparrows, Bumpus measured sparrow sex, wingspan, and mass, and also the length of each sparrow's head, humerus, tibiotarsus, skull, and sternum. While modern ornithologists believe that the total body length measurement that I will use today is subject to high observational error [@Johnston1972], it will be more than sufficient for demonstrating Rmarkdown.
I performed an independent two-sample student's t-test on sparrow total body length to test whether or not sparrows that died in the 1898 storm were larger than sparrows that survived. I assume that both groups of sparrows (dead and living) have equal variances, so the test statistic
In the above, $\bar{X}{1}$ and $\bar{X}{2}$ are the mean of the samples of sparrows that died and lived, respectively. Similarly,
In the above, the $s^{2}{X{1}}$ and $s^{2}{X{2}}$ are the sample standard deviations for sparrows that died and lived, respectively. I conducted the two sample t-test using the t.test function in R [@R2018].
dat <- read.csv(file = "data/Bumpus_data.csv");
res <- t.test(formula = dat$totlen ~ dat$surv, alternative = "less",
var.equal = TRUE); # Two sample t-test results
tval <- as.numeric(res$statistic); # Get the t-test statistic
pval <- res$p.value; # Get the p value from the t-test results
live <- as.numeric(res$estimate[1]); # Get mean length of living sparrows
dead <- as.numeric(res$estimate[2]); # Get mean length of dying sparrows
Bumpus' data included r sum(dat$surv == "alive") sparrows that lived and r sum(dat$surv == "dead") sparrows that died. The mean total length of living sparrows was r round(live, digits = 2) mm, and the mean total length of dead sparrows was r round(dead, digits = 2) mm. The two sample t-test revealed a t-statistic of r round(tval, digits = 2), which corresponds to a p-value of r round(pval, digits = 5).
total_len_alive <- dat$totlen[dat$surv == "alive"];
total_len_dead <- dat$totlen[dat$surv == "dead"];
summary_alive <- summary(total_len_alive);
summary_dead <- summary(total_len_dead);
Figure 2 shows the difference between total length in sparrows that survived versus sparrows that died. Overall, dead sparrows were r round(dead - live, digits = 2) mm longer than living sparrows, and ranged between r as.numeric(summary_dead[1]) and r as.numeric(summary_dead[5]) mm. Living sparrows ranged between r as.numeric(summary_alive[1]) and r as.numeric(summary_alive[5]) mm (Figure 2).
par(mar = c(5, 5, 1, 1));
plot(x = as.factor(dat$surv), y = dat$totlen, cex.axis = 1.5, lwd = 2,
ylab = "Total Sparrow Length (mm)", cex.lab = 1.5,
xlab = "Sparrow status");
I have analysed data collected by Herman Bumpus [@Bumpus1898] on the relationship between sparrow (Passer domesticus) total length and surival following an unusually severe storm. I found that sparrows that died in the storm were longer than sparrows that survived, which suggests that higher sparrow body length decreased survival. Of course, it is not possible to definitively conclude a causal relationship between any aspect of body size and sparrow survival <!--- BD Note: maybe explain this better --->, and even the available data collected by Bumpus would permit a more thoughtful analysis than that conducted in this study (see Appendix Table 1).
Overall, this document demonstrates how high quality, professional looking documents can be written using Rmarkdown. The underlying code for this manuscript is publicly available, along with accompanying notes to understand how it was written. By using Rmarkdown to write manuscripts, authors can more easily use version control (e.g., git) throughout the writing process. The ability to easily integrate citations though BibTeX, LaTeX tools, and dynamic R code can also make writing much more efficient and more enjoyable. Further, obtaining the benefits of using Rmarkdown does not need to come with the cost of isolating colleagues who prefer to work with Word or LaTeX because Rmarkdown can easily be converted to these formats (in the case of Word, with the push of a button). By learning all of the tools used in this manuscript, readers should have all of the necessary knowledge to get started writing and collaborating in Rmarkdown.
An example table is shown below, which includes all of the variables collected by @Bumpus1898 for the first 10 measured sparrows. The full data set can be found online in GitHub.
library(knitr);
kable(x = dat[1:10,], caption = "First ten rows of the original data set collected by Hermon Bumpus");
