aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKen Kellner <ken.kellner@gmail.com>2015-01-21 20:15:27 (GMT)
committerKen Kellner <ken.kellner@gmail.com>2015-01-21 20:15:27 (GMT)
commit746a58206b6ac4f8dde478ec854262478209bae9 (patch)
tree29526330e8a35676027b97942cd07faf1034c734
parentb9fa6834e4c508bbe5dd0974037a3a8fb1129eda (diff)
Add code for presentation figures.
-rw-r--r--analysis_id_alltaxa.R7
-rw-r--r--figures_id_presentation.R115
-rw-r--r--models/model_id_alltaxa.R20
3 files changed, 140 insertions, 2 deletions
diff --git a/analysis_id_alltaxa.R b/analysis_id_alltaxa.R
index 8f4eda8..028fd35 100644
--- a/analysis_id_alltaxa.R
+++ b/analysis_id_alltaxa.R
@@ -78,10 +78,13 @@ params = c( 'alpha','p_alpha'
,'bi_fi','bi_ma','bi_hr','bi_ins','bi_pl','fi_ma','fi_hr','fi_ins','fi_pl'
,'ma_hr','ma_ins','ma_pl','hr_ins','hr_pl','ins_pl'
,'birdmean','fishmean','mammean','herpmean','insmean','plantmean','pmean'
+ ,'mean.byyr'
+ ,'bird.allyrs','fish.allyrs','mam.allyrs','herp.allyrs','ins.allyrs','plant.allyrs'
+ ,'pop.allyrs','cm.allyrs','loc.allyrs','land.allyrs'
)
#Model file location
-modelFilename = "models/model_id_logistic.R"
+modelFilename = "models/model_id_alltaxa.R"
#Inits
inits <- function(){
@@ -96,6 +99,6 @@ inits <- function(){
library(jagsUI)
id.out = jags(data=jags.data, inits=inits,parameters.to.save=params, model.file=modelFilename,
- n.chains=3, n.iter=2000, n.burnin=1000, n.thin=2)
+ n.chains=3, n.iter=3000, n.burnin=2000, n.thin=2,parallel=TRUE)
save(id.out,file="output/output_id_alltaxa.Rda")
diff --git a/figures_id_presentation.R b/figures_id_presentation.R
new file mode 100644
index 0000000..b45f974
--- /dev/null
+++ b/figures_id_presentation.R
@@ -0,0 +1,115 @@
+##################################################################
+##Figures for Presentation ###
+##################################################################
+
+#Line graph showing change over time
+
+#Load in analysis output for figure
+load("output/output_id_alltaxa.Rda")
+
+data = id.out$sims.list$mean.byyr
+
+lineplot.input = t(colMeans(data))
+
+#Load in required package for error bars
+#https://github.com/kenkellner/heeparse
+library(heeparse)
+
+#Draw plot
+library(plotrix)
+plot(c('1971','1981','1991','2001','2011'),lineplot.input, ylim=c(0.15,0.55),
+ ylab=italic(p)~"ID", xlab="Year", type="o",yaxt="n",lwd=5,cex=1,
+ col=rgb(red=255,green=129,blue=0, maxColorValue=255),xaxt="n")
+axis(2,at=c(0.15,0.20,0.25,0.30,0.35,0.40,0.45,0.50),
+ labels=c(0,"0.20",0.25,"0.30",0.35,"0.40",0.45,"0.50"))
+axis.break(2,0.175,style="zigzag")
+axis(1,at=c(1971,1981,1991,2001,2011))
+
+#Draw error bars on plot
+structure = c(1971,1981,1991,2001,2011)
+lab = c('A','A','AB','BC','C')
+for (i in 1:5){
+ error.bars(data=data[,i],structure=structure[i],
+ quantiles=c(0.025,0.975),cex=0,
+ col=rgb(red=255,green=129,blue=0, maxColorValue=255))
+
+ text(structure[i],quantile(data[,i],0.975)+0.02,lab[i])
+ }
+
+#Bar graph showing taxa across years
+
+data = array(data=NA,dim=c(1500,6))
+data[,1] = id.out$sims.list$fish.allyrs
+data[,2] = id.out$sims.list$herp.allyrs
+data[,3] = id.out$sims.list$mam.allyrs
+data[,4] = id.out$sims.list$bird.allyrs
+data[,5] = id.out$sims.list$ins.allyrs
+data[,6] = id.out$sims.list$plant.allyrs
+
+barplot.input = t(colMeans(data))
+
+cols <- colorRampPalette(colors=c("#00c0ffff","#b9f2ffff"))
+
+barplot(barplot.input, beside=T, ylim=c(0,0.77), names=c('Fish','Herps','Mammals','Birds','Invertebrates','Plants'),
+ ylab=italic(p)~"ID", xlab="Taxon",
+ col=cols(6))
+
+structure = c(1.5,3.5,5.5,7.5,9.5,11.5)
+lab = c('A','A','A','A','B','B')
+for (i in 1:6){
+ error.bars(data=data[,i],structure=structure[i],
+ quantiles=c(0.025,0.975),cex=0,
+ col="black")
+
+ text(structure[i],quantile(data[,i],0.975)+0.04,lab[i])
+}
+
+#Figures - spatial scale
+
+data = array(data=NA,dim=c(1500,2))
+data[,1] = id.out$sims.list$loc.allyrs
+data[,2] = id.out$sims.list$land.allyrs
+
+barplot.input = t(colMeans(data))
+
+cols <- colorRampPalette(colors=c("#ff8100ff","#f9cb9cff"))
+#cols <- colorRampPalette(colors=c("#00c0ffff","#b9f2ffff"))
+
+barplot(barplot.input, beside=T, ylim=c(0,0.55), names=c('Local','Landscape'),
+ ylab=italic(p)~"ID", xlab="Spatial Scale",
+ col=cols(2))
+
+structure = c(1.5,3.5)
+lab = c('A','A')
+for (i in 1:2){
+ error.bars(data=data[,i],structure=structure[i],
+ quantiles=c(0.025,0.975),cex=0,
+ col="black")
+
+ text(structure[i],quantile(data[,i],0.975)+0.02,lab[i])
+}
+
+#Figures - organization
+
+data = array(data=NA,dim=c(1500,2))
+data[,1] = id.out$sims.list$pop.allyrs
+data[,2] = id.out$sims.list$cm.allyrs
+
+barplot.input = t(colMeans(data))
+
+#cols <- colorRampPalette(colors=c("#f9cb9cff","#ff8100ff"))
+cols <- colorRampPalette(colors=c("#00c0ffff","#b9f2ffff"))
+
+barplot(barplot.input, beside=T, ylim=c(0,0.55), names=c('Population','Community'),
+ ylab=italic(p)~"ID", xlab="Biological Organization Level",
+ col=cols(2))
+
+structure = c(1.5,3.5)
+lab = c('A','B')
+for (i in 1:2){
+ error.bars(data=data[,i],structure=structure[i],
+ quantiles=c(0.025,0.975),cex=0,
+ col="black")
+
+ text(structure[i],quantile(data[,i],0.975)+0.02,lab[i])
+} \ No newline at end of file
diff --git a/models/model_id_alltaxa.R b/models/model_id_alltaxa.R
index df6a9c9..7f09313 100644
--- a/models/model_id_alltaxa.R
+++ b/models/model_id_alltaxa.R
@@ -92,5 +92,25 @@ model {
herpmean[i] <- sum(z[]*hr[]*yrindex[,i])/sum(hr[]*yrindex[,i])
insmean[i] <- sum(z[]*ins[]*yrindex[,i])/sum(ins[]*yrindex[,i])
plantmean[i] <- sum(z[]*pl[]*yrindex[,i])/sum(pl[]*yrindex[,i])
+
+ #Across all taxa
+ mean.byyr[i] <- sum(z[]*yrindex[,i])/sum(yrindex[,i])
}
+
+ #By taxa, across years
+
+ bird.allyrs <- sum(z[]*bi[])/sum(bi[])
+ fish.allyrs <- sum(z[]*fi[])/sum(fi[])
+ mam.allyrs <- sum(z[]*ma[])/sum(ma[])
+ herp.allyrs <- sum(z[]*hr[])/sum(hr[])
+ ins.allyrs <- sum(z[]*ins[])/sum(ins[])
+ plant.allyrs <- sum(z[]*pl[])/sum(pl[])
+
+ #By scale, across years
+
+ loc.allyrs <- sum(z[]*(1-land[]))/sum(1-land[])
+ land.allyrs <- sum(z[]*land[])/sum(land[])
+ pop.allyrs <- sum(z[]*(1-cm[]))/sum(1-cm[])
+ cm.allyrs <- sum(z[]*cm[])/sum(cm[])
+
}