aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKen Kellner <ken@kenkellner.com>2019-05-28 19:11:50 (GMT)
committerKen Kellner <ken@kenkellner.com>2019-05-28 19:11:50 (GMT)
commit8ff68d7ba602648e6b1f5fa6234ad989fb0a7bf6 (patch)
tree41e23c8122b81df3aff4679f9225d90cc5215d98
parentac87b4ad2645739ca3d63d29a5fe89ee19d6ca95 (diff)
Clean up supplements
-rw-r--r--supplements/appendixS1.Rmd32
-rw-r--r--supplements/appendixS2.Rmd134
-rw-r--r--supplements/codeS1_models.Rmd52
-rw-r--r--supplements/figS1_phylogeny.Rmd55
-rw-r--r--supplements/figS2_detection.Rmd169
-rw-r--r--supplements/make_supplements.R33
-rw-r--r--supplements/makefile9
-rw-r--r--supplements/tableS1_counts.R28
-rw-r--r--supplements/tableS2_lvl1output.R58
-rw-r--r--supplements/tableS3_lvl2output.R49
-rw-r--r--uwep_lvl1_bird.R4
11 files changed, 132 insertions, 491 deletions
diff --git a/supplements/appendixS1.Rmd b/supplements/appendixS1.Rmd
index 4e849ea..f44fd70 100644
--- a/supplements/appendixS1.Rmd
+++ b/supplements/appendixS1.Rmd
@@ -5,11 +5,25 @@ output: pdf_document
Supplemental information for:
-Kellner, K. F., Duchamp, J. E., & Swihart R. K. Niche breadth and vertebrate sensitivity to habitat modification: signals from multiple taxa across replicated landscapes. Diversity & Distributions.
+Kellner, K. F., Duchamp, J. E., & Swihart R. K. Niche breadth and vertebrate sensitivity to habitat modification: signals from multiple taxa across replicated landscapes. Biodiversity and Conservation. DOI: 10.1007/s10531-019-01785-w.
```{r, echo=FALSE, warning=FALSE, message=FALSE}
-setwd('..')
-source('.Rprofile')
+if(!file.exists('filepath.R')){
+ require(tcltk)
+ cat('Set data directory\n')
+ data.dir <- tk_choose.dir(caption="Select data directory")
+ cat('Set output directory\n')
+ out.dir <- tk_choose.dir(caption="Select output directory")
+ out.string <- paste("data.dir <- \"",data.dir,"/\"\nout.dir <- \"",out.dir,"/\"",sep="")
+ cat(out.string,file="filepath.R",sep="\n")
+ rm(out.string)
+}
+
+source('filepath.R')
+
+datapath <- function(x){paste(data.dir,x,sep="")}
+
+outpath <- function(x){paste(out.dir,x,sep="")}
```
# Species Included
@@ -33,10 +47,14 @@ taxa <- c(rep('small_mammal',length(mam.counts$codes)),
rep('bat',length(bat.counts$code)),
rep('bird',length(bird.counts$code)),
rep('turtle',length(turtle.counts$code)))
-niche <- c(mam.niche,bat.niche,bird.niche,turtle.niche)
+niche <- round(c(mam.niche,bat.niche,bird.niche,turtle.niche),3)
counts <- c(mam.counts$counts,bat.counts$count,bird.counts$count,turtle.counts$count)
+spname <- gsub('_',' ',spname)
+spname <- paste0('*',spname,'*')
+taxa <- gsub('_',' ',taxa)
out <- data.frame(code=codes,scientific_name=spname,taxa=taxa,niche_breadth_z=niche,observations=counts)
+names(out) <- c('Code','Scientific Name','Taxa','Niche Breadth','Observations')
knitr::kable(out)
```
@@ -107,7 +125,7 @@ plot(turtle.nolength)
line.col <- 'black'
```
-**Figure S1.5**. Effects of habitat type (relative to the forest baseline) on detection probability for mammals, from occupancy models. Error bars represent 95% credible intervals. Species codes can be found in Table S1.
+**Figure S1.5**. Effects of habitat type (relative to the forest baseline) on detection probability for mammals, from occupancy models. Error bars represent 95% credible intervals. Only effects with 95% credible intervals that did not overlap 0 are included in the figure. Species codes can be found in Table S1.
```{r, echo=FALSE}
load(outpath('out_mam_lvl1.Rdata'))
@@ -154,7 +172,7 @@ mtext('Species',1,3.6)
\pagebreak
-**Figure S1.6**. Effects of habitat type (relative to the forest baseline) on detection probability for bats, from occupancy models. Error bars represent 95% credible intervals. Species codes can be found in Table S1.
+**Figure S1.6**. Effects of habitat type (relative to the forest baseline) on detection probability for bats, from occupancy models. Error bars represent 95% credible intervals. Only effects with 95% credible intervals that did not overlap 0 are included in the figure. Species codes can be found in Table S1.
```{r, echo=FALSE}
load(outpath('out_bat_lvl1.Rdata'))
@@ -205,7 +223,7 @@ mtext('Species',1,3.6)
\pagebreak
-**Figure S1.7**. Effects of habitat type (relative to the forest baseline) on detection probability for birds, from occupancy models. Error bars represent 95% credible intervals. Species codes can be found in Table S1.
+**Figure S1.7**. Effects of habitat type (relative to the forest baseline) on detection probability for birds, from occupancy models. Error bars represent 95% credible intervals. Only effects with 95% credible intervals that did not overlap 0 are included in the figure. Species codes can be found in Table S1.
```{r, echo=FALSE}
load(outpath('out_bird_lvl1.Rdata'))
diff --git a/supplements/appendixS2.Rmd b/supplements/appendixS2.Rmd
index 25fd931..8d28080 100644
--- a/supplements/appendixS2.Rmd
+++ b/supplements/appendixS2.Rmd
@@ -5,29 +5,62 @@ output: pdf_document
Supplemental information for:
-Kellner, K. F., Duchamp, J. E., & Swihart R. K. Niche breadth and vertebrate sensitivity to habitat modification: signals from multiple taxa across replicated landscapes. Diversity & Distributions.
+Kellner, K. F., Duchamp, J. E., & Swihart R. K. Niche breadth and vertebrate sensitivity to habitat modification: signals from multiple taxa across replicated landscapes. Biodiversity and Conservation. DOI: 10.1007/s10531-019-01785-w.
```{r, echo=FALSE, warning=FALSE, message=FALSE}
-setwd('..')
-source('.Rprofile')
+if(!file.exists('filepath.R')){
+ require(tcltk)
+ cat('Set data directory\n')
+ data.dir <- tk_choose.dir(caption="Select data directory")
+ cat('Set output directory\n')
+ out.dir <- tk_choose.dir(caption="Select output directory")
+ out.string <- paste("data.dir <- \"",data.dir,"/\"\nout.dir <- \"",out.dir,"/\"",sep="")
+ cat(out.string,file="filepath.R",sep="\n")
+ rm(out.string)
+}
+
+source('filepath.R')
+
+datapath <- function(x){paste(data.dir,x,sep="")}
+outpath <- function(x){paste(out.dir,x,sep="")}
+
+load(outpath('out_mam_lvl1.Rdata'))
+load(outpath('out_bird_lvl1.Rdata'))
+load(outpath('out_bat_lvl1.Rdata'))
+load(outpath('out_turtle_lvl1.Rdata'))
+load(outpath('out_mam_lvl2.Rdata'))
+load(outpath('out_bird_lvl2.Rdata'))
+load(outpath('out_bat_lvl2.Rdata'))
+load(outpath('out_turtle_lvl2.Rdata'))
```
# Species Index
+```{r,echo=F,message=F,warning=F}
+get_index_table <- function(taxa){
+ codes <- colnames(eval(parse(text=paste(taxa,'.cellocc',sep=""))))
+ if(taxa=='mam'){codes[codes=='X13GR'] <- '13GR'}
+
+ ind <- 1:length(codes)
+ spname <- colnames(eval(parse(text=paste(taxa,'.phylo',sep=""))))
+
+ spname <- gsub('_', ' ', spname)
+ spname <- paste0('*',spname,'*')
+ data.frame(Index=ind,Code=codes,`Species Name`=spname,check.names=F)
+}
+```
+
+
**Table S2.2**. Mammal species included in analyses and matching index values.
```{r,echo=F}
-mam.sp <- read.csv(outpath('tableS2_lvl1/mam_species.csv'),header=T)
-names(mam.sp) <- c('Index','Code','Species Name')
-knitr::kable(mam.sp)
+knitr::kable(get_index_table('mam'))
```
**Table S2.3**. Bat species included in analyses and matching index values.
```{r,echo=F}
-bats.sp <- read.csv(outpath('tableS2_lvl1/bat_species.csv'),header=T)
-names(bats.sp) <- c('Index','Code','Species Name')
-knitr::kable(bats.sp)
+knitr::kable(get_index_table('bat'))
```
\pagebreak
@@ -35,9 +68,7 @@ knitr::kable(bats.sp)
**Table S2.4**. Bird species included in analyses and matching index values.
```{r,echo=F}
-bird.sp <- read.csv(outpath('tableS2_lvl1/bird_species.csv'),header=T)
-names(bird.sp) <- c('Index','Code','Species Name')
-knitr::kable(bird.sp)
+knitr::kable(get_index_table('bird'))
```
\pagebreak
@@ -45,21 +76,44 @@ knitr::kable(bird.sp)
**Table S2.5**. Aquatic turtle species included in analyses and matching index values.
```{r,echo=F}
-turtle.sp <- read.csv(outpath('tableS2_lvl1/turtle_species.csv'),header=T)
-names(turtle.sp) <- c('Index','Code','Species Name')
-knitr::kable(turtle.sp)
+knitr::kable(get_index_table('turtle'))
```
# Level-1 Analysis Output (Individual Plot Scale)
```{r,echo=F}
suppressMessages(library(tidyverse))
+get_lvl1_table <- function(taxa){
+ hold <- eval(parse(text=paste('out.',taxa,'.lvl1',sep="")))
+ sv <- hold$summary[,c(-4,-6,-8,-9,-10)]
+
+ if(taxa%in%c('mam','bird')){
+
+ if(taxa=='mam'){ind=2 ; rng <- c(3,12)}
+ if(taxa=='bird'){ind=9; rng <- c(10,40)}
+
+ sv <- sv[-grep(paste('[',ind,']',sep=""),row.names(sv),fixed=T),]
+ tmp <- row.names(sv)
+
+ tmp.fix <- tmp
+ for (j in rng[1]:rng[2]){
+ st <- paste('[',j,']',sep="")
+ st.new <- paste('[',(j-1),']',sep="")
+ tmp.fix <- gsub(st,st.new,tmp.fix,fixed=T)
+ }
+
+ row.names(sv) <- tmp.fix
+ }
+ out <- data.frame(param=row.names(sv),sv)
+ row.names(out) <- NULL
+ out
+}
```
**Table S2.6**. Output from multi-species plot-level occupancy model for small mammals. Species indices are in brackets (see Table S2.2).
```{r,echo=F}
-inp <- read.csv(outpath('tableS2_lvl1/mam_lvl1.csv'),header=T)
+inp <- get_lvl1_table('mam')
inp <- cbind(inp[,1],round(inp[,c(2,4,6,7)],2))
names(inp) <- c('Parameter','Mean','2.5%','97.5%','f')
@@ -84,7 +138,7 @@ knitr::kable(inp_out)
**Table S2.7**. Output from multi-species plot-level occupancy model for bats. Species indices are in brackets (see Table S2.3).
```{r,echo=F}
-inp <- read.csv(outpath('tableS2_lvl1/bat_lvl1.csv'),header=T)
+inp <- get_lvl1_table('bat')
inp <- cbind(inp[,1],round(inp[,c(2,4,6,7)],2))
names(inp) <- c('Parameter','Mean','2.5%','97.5%','f')
@@ -109,7 +163,7 @@ knitr::kable(inp_out)
**Table S2.8**. Output from multi-species plot-level abundance model for birds. Species indices are in brackets (see Table S2.4).
```{r,echo=F}
-inp <- read.csv(outpath('tableS2_lvl1/bird_lvl1.csv'),header=T)
+inp <- get_lvl1_table('bird')
inp <- cbind(inp[,1],round(inp[,c(2,4,6,7)],2))
names(inp) <- c('Parameter','Mean','2.5%','97.5%','f')
@@ -136,7 +190,7 @@ knitr::kable(inp_out)
**Table S2.9**. Output from multi-species plot-level occupancy model for turtles. Species indices are in brackets (see Table S2.5).
```{r,echo=F}
-inp <- read.csv(outpath('tableS2_lvl1/turtle_lvl1.csv'),header=T)
+inp <- get_lvl1_table('turtle')
inp <- cbind(inp[,1],round(inp[,c(2,4,6,7)],2))
names(inp) <- c('Parameter','Mean','2.5%','97.5%','f')
@@ -160,8 +214,12 @@ knitr::kable(inp_out)
```{r,echo=F,message=F,warning=F}
-format_lvl2 <- function(file,nspecies){
- inp <- read.csv(outpath(paste('tableS3_lvl2/',file,sep='')),header=T)
+format_lvl2 <- function(taxa,mod,nspecies){
+
+ hold <- eval(parse(text=paste(taxa,'.',mod,sep="")))
+ inp <- hold$summary[,c(-4,-6,-8,-9,-10)]
+ inp <- data.frame(param=row.names(inp),inp)
+ row.names(inp) <- NULL
inp <- cbind(inp[,1],round(inp[,c(2,4,6,7)],2))
names(inp) <- c('Parameter','Mean','2.5%','97.5%','f')
@@ -178,7 +236,7 @@ format_lvl2 <- function(file,nspecies){
param_names[4:(length(pn_raw)-1)] <- paste(pn_raw[4:(length(pn_raw)-1)],'[',
1:nspecies,']',sep='')
- if(str_detect(file,'P')){
+ if(str_detect(mod,'P')){
pn_raw <- c(pn_raw,"Response to modification: Pagel's lambda")
param_names <- c(param_names,"Response to modification: Pagel's lambda")
indices <- c(indices,1)
@@ -201,25 +259,25 @@ format_lvl2 <- function(file,nspecies){
**Table S2.10**. Output from model NN (no imperfect detection, no phylogenetic relationships) for small mammals. See Table S2.2 for species indices.
```{r,echo=F}
-format_lvl2('mam_NN.csv',11)
+format_lvl2('mam','NN',11)
```
**Table S2.11**. Output from model IN (imperfect detection, no phylogenetic relationships) for small mammals. See Table S2.2 for species indices.
```{r,echo=F}
-format_lvl2('mam_IN.csv',11)
+format_lvl2('mam','IN',11)
```
**Table S2.12**. Output from model NP (no imperfect detection, phylogenetic relationships) for small mammals. See Table S2.2 for species indices.
```{r,echo=F}
-format_lvl2('mam_NP.csv',11)
+format_lvl2('mam','NP',11)
```
**Table S2.13**. Output from model IP (imperfect detection, phylogenetic relationships) for small mammals. See Table S2.2 for species indices.
```{r,echo=F}
-format_lvl2('mam_IP.csv',11)
+format_lvl2('mam','IP',11)
```
## Bats
@@ -227,25 +285,25 @@ format_lvl2('mam_IP.csv',11)
**Table S2.14**. Output from model NN (no imperfect detection, no phylogenetic relationships) for bats. See Table S2.3 for species indices.
```{r,echo=F}
-format_lvl2('bat_NN.csv',7)
+format_lvl2('bat','NN',7)
```
**Table S2.15**. Output from model IN (imperfect detection, no phylogenetic relationships) for bats. See Table S2.3 for species indices.
```{r,echo=F}
-format_lvl2('bat_IN.csv',7)
+format_lvl2('bat','IN',7)
```
**Table S2.16**. Output from model NP (no imperfect detection, phylogenetic relationships) for bats. See Table S2.3 for species indices.
```{r,echo=F}
-format_lvl2('bat_NP.csv',7)
+format_lvl2('bat','NP',7)
```
**Table S2.17**. Output from model IP (imperfect detection, phylogenetic relationships) for bats. See Table S2.3 for species indices.
```{r,echo=F}
-format_lvl2('bat_IP.csv',7)
+format_lvl2('bat','IP',7)
```
## Birds
@@ -253,25 +311,25 @@ format_lvl2('bat_IP.csv',7)
**Table S2.18**. Output from model NN (no imperfect detection, no phylogenetic relationships) for birds. See Table S2.4 for species indices.
```{r,echo=F}
-format_lvl2('bird_NN.csv',39)
+format_lvl2('bird','NN',39)
```
**Table S2.19**. Output from model IN (imperfect detection, no phylogenetic relationships) for birds. See Table S2.4 for species indices.
```{r,echo=F}
-format_lvl2('bird_IN.csv',39)
+format_lvl2('bird','IN',39)
```
**Table S2.20**. Output from model NP (no imperfect detection, phylogenetic relationships) for birds. See Table S2.4 for species indices.
```{r,echo=F}
-format_lvl2('bird_NP.csv',39)
+format_lvl2('bird','NP',39)
```
**Table S2.21**. Output from model IP (imperfect detection, phylogenetic relationships) for birds. See Table S2.4 for species indices.
```{r,echo=F}
-format_lvl2('bird_IP.csv',39)
+format_lvl2('bird','IP',39)
```
## Aquatic Turtles
@@ -279,23 +337,23 @@ format_lvl2('bird_IP.csv',39)
**Table S2.22**. Output from model NN (no imperfect detection, no phylogenetic relationships) for turtles. See Table S2.5 for species indices.
```{r,echo=F}
-format_lvl2('turtle_NN.csv',8)
+format_lvl2('turtle','NN',8)
```
**Table S2.23**. Output from model IN (imperfect detection, no phylogenetic relationships) for turtles. See Table S2.5 for species indices.
```{r,echo=F}
-format_lvl2('turtle_IN.csv',8)
+format_lvl2('turtle','IN',8)
```
**Table S2.24**. Output from model NP (no imperfect detection, phylogenetic relationships) for turtles. See Table S2.5 for species indices.
```{r,echo=F}
-format_lvl2('turtle_NP.csv',8)
+format_lvl2('turtle','NP',8)
```
**Table S2.25**. Output from model IP (imperfect detection, phylogenetic relationships) for turtles. See Table S2.5 for species indices.
```{r,echo=F}
-format_lvl2('turtle_IP.csv',8)
+format_lvl2('turtle','IP',8)
```
diff --git a/supplements/codeS1_models.Rmd b/supplements/codeS1_models.Rmd
deleted file mode 100644
index 08355ee..0000000
--- a/supplements/codeS1_models.Rmd
+++ /dev/null
@@ -1,52 +0,0 @@
----
-title: "Code S1"
-output: pdf_document
----
-
-JAGS model code for the four different model scenarios.
-
-```{r, echo=FALSE, warning=FALSE, error=FALSE, message=FALSE}
-library(knitr)
-read_chunk('../models/model_lvl2_NN.R')
-read_chunk('../models/model_lvl2_IN.R')
-read_chunk('../models/model_lvl2_NP.R')
-read_chunk('../models/model_lvl2_IP.R')
-```
-
-# Model NN
-
-No imperfect detection, no phylogenetic effect in fragmentation response
-
-```{r, eval=FALSE}
-<<model.nn>>
-```
-
-\pagebreak
-
-# Model IN
-
-Imperfect detection, no phylogenetic effect in fragmentation response
-
-```{r, eval=FALSE}
-<<model.in>>
-```
-
-\pagebreak
-
-# Model NP
-
-No imperfect detection, phylogenetic effect in fragmentation response
-
-```{r, eval=FALSE}
-<<model.np>>
-```
-
-\pagebreak
-
-# Model IP
-
-Imperfect detection, phylogenetic effect in fragmentation response
-
-```{r, eval=FALSE}
-<<model.ip>>
-```
diff --git a/supplements/figS1_phylogeny.Rmd b/supplements/figS1_phylogeny.Rmd
deleted file mode 100644
index ff4768e..0000000
--- a/supplements/figS1_phylogeny.Rmd
+++ /dev/null
@@ -1,55 +0,0 @@
----
-title: "Figure S1"
-output: pdf_document
----
-
-Phylogenetic trees used to generate correlation matrices in R package `ape` for models NP and IP.
-
-```{r, echo=FALSE, warning=FALSE, message=FALSE}
-setwd('..')
-source('.Rprofile')
-library(ape)
-par(mar = c(4,4.5,1.5,2) + 0.1)
-```
-
-# Mammals
-
-```{r, echo=FALSE}
-mam.length <- read.tree(datapath('smammals_lengths.phylo'))
-
-mam.pruned <- drop.tip(mam.length,mam.length$tip.label[3])
-
-plot(mam.pruned)
-```
-
-# Bats
-
-```{r, echo=FALSE}
-load(outpath('out_bat_lvl1.Rdata'))
-
-bats.length <- read.tree(datapath('bats_lengths.phylo'))
-
-bats.pruned <- drop.tip(bats.length,bats.length$tip.label[bats.length$tip.label%in%c('Nycticeius_humeralis')])
-
-plot(bats.pruned)
-```
-
-# Birds
-
-```{r, echo=FALSE, fig.height=10}
-load(outpath('out_bird_lvl1.Rdata'))
-
-birds.nolength <- read.tree(datapath('birds_nolengths.phylo'))
-
-birds.pruned <- drop.tip(birds.nolength,birds.nolength$tip.label[!birds.nolength$tip.label%in%colnames(bird.phylo)])
-
-plot(birds.pruned)
-````
-
-# Turtles
-
-```{r, echo=FALSE}
-turtle.nolength <- read.tree(datapath('turtles_nolengths.phylo'))
-
-plot(turtle.nolength)
-````
diff --git a/supplements/figS2_detection.Rmd b/supplements/figS2_detection.Rmd
deleted file mode 100644
index be24acf..0000000
--- a/supplements/figS2_detection.Rmd
+++ /dev/null
@@ -1,169 +0,0 @@
----
-title: "Figure S2"
-output: pdf_document
----
-
-Effects of habitat type (relative to the forest baseline) on detection probability by taxonomic group, from occupancy models. Error bars represent 95% credible intervals. Species codes can be found in Table S1.
-
-```{r, echo=FALSE,warning=FALSE,message=FALSE}
-setwd('..')
-source('.Rprofile')
-line.col <- 'black'
-```
-
-# Mammals
-
-```{r, echo=FALSE}
-load(outpath('out_mam_lvl1.Rdata'))
-
-mam.codes <- c(colnames(mam.cellocc)[1],'NA',colnames(mam.cellocc)[2:11])
-mam.codes[1] <- '13GR'
-
-## Effects
-agvals <- c(out.mam.lvl1$mean$beta.pag[!out.mam.lvl1$overlap0$beta.pag&out.mam.lvl1$Rhat$beta.pag<=1.1])
-agupper <- c(out.mam.lvl1$q97.5$beta.pag[!out.mam.lvl1$overlap0$beta.pag&out.mam.lvl1$Rhat$beta.pag<=1.1])
-aglower <- c(out.mam.lvl1$q2.5$beta.pag[!out.mam.lvl1$overlap0$beta.pag&out.mam.lvl1$Rhat$beta.pag<=1.1])
-agcodes <- c(mam.codes[!out.mam.lvl1$overlap0$beta.pag&out.mam.lvl1$Rhat$beta.pag<=1.1])
-
-grassvals <- c(out.mam.lvl1$mean$beta.pgrass[!out.mam.lvl1$overlap0$beta.pgrass&out.mam.lvl1$Rhat$beta.pgrass<=1.1])
-grassupper <- c(out.mam.lvl1$q97.5$beta.pgrass[!out.mam.lvl1$overlap0$beta.pgrass&out.mam.lvl1$Rhat$beta.pgrass<=1.1])
-grasslower <- c(out.mam.lvl1$q2.5$beta.pgrass[!out.mam.lvl1$overlap0$beta.pgrass&out.mam.lvl1$Rhat$beta.pgrass<=1.1])
-grasscodes <- c(mam.codes[!out.mam.lvl1$overlap0$beta.pgrass&out.mam.lvl1$Rhat$beta.pgrass<=1.1])
-
-##Figure
-structure <- c(1:6)
-comb.vals <- c(agvals,grassvals)
-comb.upper <- c(agupper,grassupper)
-comb.lower <- c(aglower,grasslower)
-comb.codes <- c(agcodes,grasscodes)
-
-par(mar = c(4.5,4.5,0.5,1) + 0.1, oma=c(0,0,0,0),mgp=c(2.5,1,0))
-
-plot(structure,comb.vals,xaxt='n',xlab="",ylim=c(-3.5,6.2),ylab="",
- pch=19)
-axis(1,at=structure,labels=comb.codes,las=2)
-
-text(1.5,5.7,"Agriculture",cex=1.3)
-text(4.5,5.7,"Grassland",cex=1.3)
-
-abline(v=2.5)
-abline(h=0,col=line.col,lty=2)
-
-segments(structure,comb.lower,structure,comb.upper)
-
-mtext('Detection effect',2,3.5)
-mtext('(relative to forest)',2,2.5)
-mtext('Species',1,3.6)
-```
-
-# Bats
-
-```{r, echo=FALSE}
-load(outpath('out_bat_lvl1.Rdata'))
-
-bat.codes <- colnames(bat.cellocc)
-
-## Effects
-agvals <- c(out.bat.lvl1$mean$beta.pag[!out.bat.lvl1$overlap0$beta.pag&out.bat.lvl1$Rhat$beta.pag<=1.1])
-agupper <- c(out.bat.lvl1$q97.5$beta.pag[!out.bat.lvl1$overlap0$beta.pag&out.bat.lvl1$Rhat$beta.pag<=1.1])
-aglower <- c(out.bat.lvl1$q2.5$beta.pag[!out.bat.lvl1$overlap0$beta.pag&out.bat.lvl1$Rhat$beta.pag<=1.1])
-agcodes <- c(bat.codes[!out.bat.lvl1$overlap0$beta.pag&out.bat.lvl1$Rhat$beta.pag<=1.1])
-
-grassvals <- c(out.bat.lvl1$mean$beta.pgrass[!out.bat.lvl1$overlap0$beta.pgrass&out.bat.lvl1$Rhat$beta.pgrass<=1.1])
-grassupper <- c(out.bat.lvl1$q97.5$beta.pgrass[!out.bat.lvl1$overlap0$beta.pgrass&out.bat.lvl1$Rhat$beta.pgrass<=1.1])
-grasslower <- c(out.bat.lvl1$q2.5$beta.pgrass[!out.bat.lvl1$overlap0$beta.pgrass&out.bat.lvl1$Rhat$beta.pgrass<=1.1])
-grasscodes <- c(bat.codes[!out.bat.lvl1$overlap0$beta.pgrass&out.bat.lvl1$Rhat$beta.pgrass<=1.1])
-
-wetvals <- c(out.bat.lvl1$mean$beta.pwet[!out.bat.lvl1$overlap0$beta.pwet&out.bat.lvl1$Rhat$beta.pwet<=1.1])
-wetupper <- c(out.bat.lvl1$q97.5$beta.pwet[!out.bat.lvl1$overlap0$beta.pwet&out.bat.lvl1$Rhat$beta.pwet<=1.1])
-wetlower <- c(out.bat.lvl1$q2.5$beta.pwet[!out.bat.lvl1$overlap0$beta.pwet&out.bat.lvl1$Rhat$beta.pwet<=1.1])
-wetcodes <- c(bat.codes[!out.bat.lvl1$overlap0$beta.pwet&out.bat.lvl1$Rhat$beta.pwet<=1.1])
-
-##Figure
-structure <- c(1:2)
-comb.vals <- c(grassvals,wetvals)
-comb.upper <- c(grassupper,wetupper)
-comb.lower <- c(grasslower,wetlower)
-comb.codes <- c(grasscodes,wetcodes)
-
-par(mar = c(4.5,4.5,0.5,1) + 0.1, oma=c(0,0,0,0),mgp=c(2.5,1,0))
-
-plot(structure,comb.vals,xaxt='n',xlim=c(0.5,2.5),xlab="",ylim=c(-1.6,0.5),ylab="",
- pch=19)
-axis(1,at=structure,labels=comb.codes,las=2)
-
-text(1,0.3,"Grassland",cex=1.3)
-text(2,0.3,"Wetland",cex=1.3)
-
-abline(v=1.5)
-abline(h=0,col=line.col,lty=2)
-
-segments(structure,comb.lower,structure,comb.upper)
-
-mtext('Detection effect',2,3.5)
-mtext('(relative to forest)',2,2.5)
-mtext('Species',1,3.6)
-```
-
-# Birds
-
-```{r, echo=FALSE}
-load(outpath('out_bird_lvl1.Rdata'))
-
-bird.codes <- colnames(bird.cellocc)
-
-## Effects
-agvals <- c(out.bird.lvl1$mean$beta.pag[!out.bird.lvl1$overlap0$beta.pag&out.bird.lvl1$Rhat$beta.pag<=1.1])
-agupper <- c(out.bird.lvl1$q97.5$beta.pag[!out.bird.lvl1$overlap0$beta.pag&out.bird.lvl1$Rhat$beta.pag<=1.1])
-aglower <- c(out.bird.lvl1$q2.5$beta.pag[!out.bird.lvl1$overlap0$beta.pag&out.bird.lvl1$Rhat$beta.pag<=1.1])
-agcodes <- c(bird.codes[!out.bird.lvl1$overlap0$beta.pag&out.bird.lvl1$Rhat$beta.pag<=1.1])
-
-grassvals <- c(out.bird.lvl1$mean$beta.pgrass[!out.bird.lvl1$overlap0$beta.pgrass&out.bird.lvl1$Rhat$beta.pgrass<=1.1])
-grassupper <- c(out.bird.lvl1$q97.5$beta.pgrass[!out.bird.lvl1$overlap0$beta.pgrass&out.bird.lvl1$Rhat$beta.pgrass<=1.1])
-grasslower <- c(out.bird.lvl1$q2.5$beta.pgrass[!out.bird.lvl1$overlap0$beta.pgrass&out.bird.lvl1$Rhat$beta.pgrass<=1.1])
-grasscodes <- c(bird.codes[!out.bird.lvl1$overlap0$beta.pgrass&out.bird.lvl1$Rhat$beta.pgrass<=1.1])
-
-wetvals <- c(out.bird.lvl1$mean$beta.pwet[!out.bird.lvl1$overlap0$beta.pwet&out.bird.lvl1$Rhat$beta.pwet<=1.1])
-wetupper <- c(out.bird.lvl1$q97.5$beta.pwet[!out.bird.lvl1$overlap0$beta.pwet&out.bird.lvl1$Rhat$beta.pwet<=1.1])
-wetlower <- c(out.bird.lvl1$q2.5$beta.pwet[!out.bird.lvl1$overlap0$beta.pwet&out.bird.lvl1$Rhat$beta.pwet<=1.1])
-wetcodes <- c(bird.codes[!out.bird.lvl1$overlap0$beta.pwet&out.bird.lvl1$Rhat$beta.pwet<=1.1])
-
-urbanvals <- c(out.bird.lvl1$mean$beta.purban[!out.bird.lvl1$overlap0$beta.purban&out.bird.lvl1$Rhat$beta.purban<=1.1])
-urbanupper <- c(out.bird.lvl1$q97.5$beta.purban[!out.bird.lvl1$overlap0$beta.purban&out.bird.lvl1$Rhat$beta.purban<=1.1])
-urbanlower <- c(out.bird.lvl1$q2.5$beta.purban[!out.bird.lvl1$overlap0$beta.purban&out.bird.lvl1$Rhat$beta.purban<=1.1])
-urbancodes <- c(bird.codes[!out.bird.lvl1$overlap0$beta.purban&out.bird.lvl1$Rhat$beta.purban<=1.1])
-
-## Figure
-structure <- c(1:10)
-comb.vals <- c(agvals,grassvals,wetvals,urbanvals)
-comb.upper <- c(agupper,grassupper,wetupper,urbanupper)
-comb.lower <- c(aglower,grasslower,wetlower,urbanlower)
-comb.codes <- c(agcodes,grasscodes,wetcodes,urbancodes)
-
-par(mar = c(4.5,4.5,0.5,1) + 0.1, oma=c(0,0,0,0),mgp=c(2.5,1,0))
-
-plot(structure,comb.vals,xaxt='n',xlab="",ylim=c(-3.4,8.5),ylab="",
- pch=19)
-axis(1,at=structure,labels=comb.codes,las=2)
-
-text(1.5,8.2,"Agriculture",cex=1.2)
-text(4,8.2,"Grassland",cex=1.2)
-text(6.5,8.2,"Wetland",cex=1.2)
-text(9,8.2,"Urban",cex=1.2)
-
-abline(v=2.5)
-abline(v=5.5)
-abline(v=7.5)
-abline(h=0,col=line.col,lty=2)
-
-segments(structure,comb.lower,structure,comb.upper)
-
-mtext('Detection effect',2,3.5)
-mtext('(relative to forest)',2,2.5)
-mtext('Species',1,3.6)
-
-````
-
-# Turtles
-
-Turtles were observed in only one habitat type (wetland/lake/stream), so there were no habitat effects on detection.
diff --git a/supplements/make_supplements.R b/supplements/make_supplements.R
deleted file mode 100644
index 9624608..0000000
--- a/supplements/make_supplements.R
+++ /dev/null
@@ -1,33 +0,0 @@
-# Code to build Rmd supplements and move them
-
-source('.Rprofile')
-setwd('supplements')
-require(rmarkdown)
-
-#Supplement S1 Code
-render('codeS1_models.Rmd')
-
-#Figure S1 phylogeny
-render('figS1_phylogeny.Rmd')
-
-#Figure S2 detection
-render('figS2_detection.Rmd')
-
-#Move pdfs to output directory
-setwd('..')
-pdfs <- list.files('supplements',pattern='.pdf')
-mv.pdfs <- paste('supplements/',pdfs,sep="")
-
-file.copy(mv.pdfs,outpath(pdfs))
-file.remove(mv.pdfs)
-
-########################################
-
-#Table S1 Species Codes/Obs counts
-source('supplements/tableS1_counts.R')
-
-#Table S2 Model output lvl 1
-source('supplements/tableS2_lvl1output.R')
-
-#Table S3 Model output lvl 2
-source('supplements/tableS3_lvl2output.R')
diff --git a/supplements/makefile b/supplements/makefile
new file mode 100644
index 0000000..30128fa
--- /dev/null
+++ b/supplements/makefile
@@ -0,0 +1,9 @@
+all: appendixS1.pdf appendixS2.pdf
+
+appendixS1.pdf: appendixS1.Rmd
+ Rscript -e 'rmarkdown::render("appendixS1.Rmd")'
+ rm -rf appendixS1_files
+
+appendixS2.pdf: appendixS2.Rmd
+ Rscript -e 'rmarkdown::render("appendixS2.Rmd")'
+ rm -rf appendixS2_files
diff --git a/supplements/tableS1_counts.R b/supplements/tableS1_counts.R
deleted file mode 100644
index a11c959..0000000
--- a/supplements/tableS1_counts.R
+++ /dev/null
@@ -1,28 +0,0 @@
-#################################
-## Table S1 Observation Counts ##
-#################################
-
-source('.Rprofile')
-
-mam.counts <- read.csv(datapath('mam_counts.csv'),header=T,stringsAsFactors=F)
-bat.counts <- read.csv(datapath('bat_counts.csv'),header=T,stringsAsFactors=F)
-bird.counts <- read.csv(datapath('bird_counts.csv'),header=T,stringsAsFactors=F)
-turtle.counts <- read.csv(datapath('turtle_counts.csv'),header=T,stringsAsFactors=F)
-
-load(outpath('out_mam_lvl1.Rdata'))
-load(outpath('out_bird_lvl1.Rdata'))
-load(outpath('out_bat_lvl1.Rdata'))
-load(outpath('out_turtle_lvl1.Rdata'))
-
-codes <- c(mam.counts$codes,bat.counts$code,bird.counts$code,turtle.counts$code)
-spname <- c(names(mam.phylo),names(bat.phylo),names(bird.phylo),names(turtle.phylo))
-taxa <- c(rep('small_mammal',length(mam.counts$codes)),
- rep('bat',length(bat.counts$code)),
- rep('bird',length(bird.counts$code)),
- rep('turtle',length(turtle.counts$code)))
-niche <- c(mam.niche,bat.niche,bird.niche,turtle.niche)
-counts <- c(mam.counts$counts,bat.counts$count,bird.counts$count,turtle.counts$count)
-
-out <- data.frame(code=codes,scientific_name=spname,taxa=taxa,niche_breadth_z=niche,observations=counts)
-
-write.csv(out,outpath('tableS1_counts.csv'),row.names=F)
diff --git a/supplements/tableS2_lvl1output.R b/supplements/tableS2_lvl1output.R
deleted file mode 100644
index 8dafd7d..0000000
--- a/supplements/tableS2_lvl1output.R
+++ /dev/null
@@ -1,58 +0,0 @@
-
-source('.Rprofile')
-
-load(outpath('out_mam_lvl1.Rdata'))
-load(outpath('out_bird_lvl1.Rdata'))
-load(outpath('out_bat_lvl1.Rdata'))
-load(outpath('out_turtle_lvl1.Rdata'))
-
-taxa <- c('mam','bat','bird','turtle')
-mod <- c('NN','IN','NP','IP')
-
-sup.name <- 'tableS2_lvl1'
-
-dir.create(sup.name)
-
-for (i in 1:length(taxa)){
-
- codes <- colnames(eval(parse(text=paste(taxa[i],'.cellocc',sep=""))))
-
- if(taxa[i]=='mam'){codes[codes=='X13GR'] <- '13GR'}
-
- ind <- 1:length(codes)
- spname <- colnames(eval(parse(text=paste(taxa[i],'.phylo',sep=""))))
- sp.out <- data.frame(index=ind,code=codes,species.name=spname)
- sp.fn <- paste(sup.name,'/',taxa[i],'_species.csv',sep="")
- write.csv(sp.out,file=sp.fn,row.names=FALSE)
-
- ##
-
- hold <- eval(parse(text=paste('out.',taxa[i],'.lvl1',sep="")))
- sv <- hold$summary[,c(-4,-6,-8,-9,-10)]
-
- if(taxa[i]%in%c('mam','bird')){
-
- if(taxa[i]=='mam'){ind=2 ; rng <- c(3,12)}
- if(taxa[i]=='bird'){ind=9; rng <- c(10,40)}
-
- sv <- sv[-grep(paste('[',ind,']',sep=""),row.names(sv),fixed=T),]
- tmp <- row.names(sv)
-
- tmp.fix <- tmp
- for (j in rng[1]:rng[2]){
- st <- paste('[',j,']',sep="")
- st.new <- paste('[',(j-1),']',sep="")
- tmp.fix <- gsub(st,st.new,tmp.fix,fixed=T)
- }
-
- row.names(sv) <- tmp.fix
- }
-
-
- fn <- paste(sup.name,'/',taxa[i],'_lvl1.csv',sep="")
- write.csv(as.data.frame(sv), file = fn,row.names = TRUE)
-}
-
-zip(zipfile=outpath(paste(sup.name,'.zip',sep="")),files=paste(sup.name,'/',list.files(sup.name),sep=""))
-
-unlink(sup.name,recursive=TRUE)
diff --git a/supplements/tableS3_lvl2output.R b/supplements/tableS3_lvl2output.R
deleted file mode 100644
index e4c8ad1..0000000
--- a/supplements/tableS3_lvl2output.R
+++ /dev/null
@@ -1,49 +0,0 @@
-
-source('.Rprofile')
-
-load(outpath('out_mam_lvl1.Rdata'))
-load(outpath('out_mam_lvl2.Rdata'))
-load(outpath('out_bird_lvl1.Rdata'))
-load(outpath('out_bird_lvl2.Rdata'))
-load(outpath('out_bat_lvl1.Rdata'))
-load(outpath('out_bat_lvl2.Rdata'))
-load(outpath('out_turtle_lvl1.Rdata'))
-load(outpath('out_turtle_lvl2.Rdata'))
-
-taxa <- c('mam','bat','bird','turtle')
-mod <- c('NN','IN','NP','IP')
-
-sup.name <- 'tableS3_lvl2'
-
-dir.create(sup.name)
-
-for (i in 1:length(taxa)){
-
- codes <- colnames(eval(parse(text=paste(taxa[i],'.cellocc',sep=""))))
-
- if(taxa[i]=='mam'){codes[codes=='X13GR'] <- '13GR'}
-
- ind <- 1:length(codes)
- spname <- colnames(eval(parse(text=paste(taxa[i],'.phylo',sep=""))))
-
- sp.out <- data.frame(index=ind,code=codes,species.name=spname)
-
- sp.fn <- paste(sup.name,'/',taxa[i],'_species.csv',sep="")
-
- write.csv(sp.out,file=sp.fn,row.names=FALSE)
-
- for (j in 1:length(mod)){
-
- hold <- eval(parse(text=paste(taxa[i],'.',mod[j],sep="")))
- sv <- hold$summary[,c(-4,-6,-8,-9,-10)]
-
- fn <- paste(sup.name,'/',taxa[i],'_',mod[j],'.csv',sep="")
-
- write.csv(as.data.frame(sv), file = fn,row.names = TRUE)
-
- }
-}
-
-zip(zipfile=outpath(paste(sup.name,'.zip',sep="")),files=paste(sup.name,'/',list.files(sup.name),sep=""))
-
-unlink(sup.name,recursive=TRUE)
diff --git a/uwep_lvl1_bird.R b/uwep_lvl1_bird.R
index e41a9c4..e8fe3c8 100644
--- a/uwep_lvl1_bird.R
+++ b/uwep_lvl1_bird.R
@@ -2,7 +2,7 @@
## Read in Data ##
##################
-source('file_directory.R')
+source('filepath.R')
#Format raw data first if necessary
#source(script_birds_data.R)
@@ -198,7 +198,7 @@ bird.cellsd.st[which(is.na(bird.cellsd.st))] <- 1
bird.niche <- bird.species$hb.all.z[keep][keep2]
#Read in phylogenetic data and generate correlation matrix
-bird.phylo <- read.csv(datapath('uwep_birds_phylo.csv'),header=T)[,-1][keep2,keep2]
+bird.phylo <- read.csv(datapath('uwep_birds_phylo.csv'),header=T)[,-1][keep,keep][keep2,keep2]
#Save output
save(out.bird.lvl1,bird.cellocc,bird.cellocc.naive,bird.cellsd,bird.cellsd.st,bird.niche,bird.phylo,