#This script runs all of the analyses in part 1 of the manuscript and creates the figures #Ordering of analyses is as they are presented in the manuscript #Data are .csv files created for the individual tabs in the accompanying Excel dataset provided as ESM, and named as those tabs are named #RNG seeds are extracted after fitting map2stan models. These allow the model to be repeated, but sampling from it is not then exactly repeatable. An .RData file containing the models in the paper is available on request. #PREPARATION OF FIGURE 1 SHOWING REFLECTANCE SPECTRA #Creating a plot of fabric spectra using the same line colours and styles as elsewhere in this analysis #Read data s<-read.table("MeanFabricSpectra.csv", sep=",",header=TRUE) #These are mean spectra, averaged across the two reflectance probe azimuth angles for each fabric #Prepare plot space with 2 panels par(mfrow=c(3,2)) par(mar=c(3,3,3,3), mgp=c(2,0.5,0)) #Panel1: Blues plot(s$WL, s$VestZF,type="n",xlab="Wavelength (nm)", ylab="Reflectance (%)",xlim=c(300,700),ylim=c(0,60)) lines(s$WL,s$VestZF, col="dodgerblue3", lty="solid") lines(s$WL,s$VestSP23, col="dodgerblue4", lty="dotted") lines(s$WL,s$TypBlue, col="dodgerblue", lty="dashed") legend( 525,60, legend=c("Typical blue", "Vest. ZF", "Vest. SP23 (P)"), #'P' indicates prototype col=c("dodgerblue","dodgerblue3","dodgerblue4"), lty=c("dashed","solid","dotted"), cex=0.8) title("A. Blue fabrics",adj=0.05,line=-2) #Blank plot.new() #Panel 2: Violets plot(s$WL, s$VestZF,type="n",xlab="Wavelength (nm)", ylab="Reflectance (%)",xlim=c(300,700),ylim=c(0,40)) lines(s$WL,s$Violet4.5pc, col="darkorchid1", lty="twodash") lines(s$WL,s$Violet9pc, col="darkorchid4", lty="dashed") lines(s$WL,s$Violet7pc, col="darkorchid", lty="dotted") lines(s$WL,s$Violet, col="darkorchid4", lty="solid") legend( 525,40, legend=c("Violet", "Violet 9% (P)", "Violet 7% (P)", "Violet 4.5% (P)"), col=c("darkorchid4","darkorchid4","darkorchid","darkorchid1"), lty=c("solid","dashed","dotted","twodash" ), cex=0.8) title("B. Violet fabrics",adj=0.05,line=-2) #STATISTICAL ANALYSIS OF EACH NEW EXPERIMENT INDIVIDUALLY, WITHOUT INFORMATIVE PRIORS #Load packages #The rethinking package interfaces with Stan, which must also be installed #Full installation instructions can be found in McElreath, R (2016) Statistical Rethinking: A Bayesian Course with Examples in R and Stan. CRC Press, Boca Raton. library(rethinking) library(glmmTMB) library(emmeans) library(bbmle) #ANALYSIS OF EXPT 1 #Read experiment 1 data from csv file d<-read.table("Expt1Kenya.csv", sep=",",header=TRUE) d$flies<-d$total #Specify response variable (done to allow easy modification for analysis of subsets) #Subset catches for use in boxplot TBdata<-d[d$fabric=="TypBlue",] SP23data<-d[d$fabric=="VestSP23",] ZFdata<-d[d$fabric=="VestZF",] Vdata<-d[d$fabric=="Violet",] #An over-dispersed Poisson model using a non-centred parameterisation (this was necessary for efficient model fitting). #The RNG seed for the reported version is extracted below. e1.nc<-map2stan( alist( flies ~ dpois(lambda), log(lambda) <- a + za_rep[rep]*sigma_rep + za_day[day]*sigma_day + za_site[site]*sigma_site + bTB*TypBlue + bVSP*VestSP23 + bViol*Violet, a ~ dnorm(0,10), bTB ~ dnorm(0,10), bVSP ~ dnorm(0,10), bViol ~ dnorm(0,10), za_rep[rep] ~ dnorm(0,1), za_day[day] ~ dnorm(0,1), za_site[site] ~ dnorm(0,1), sigma_rep ~ dnorm(0,1), sigma_day ~ dnorm(0,1), sigma_site ~ dnorm(0,1) ), data=d, constraints=list(sigma_rep="lower=0",sigma_day="lower=0",sigma_site="lower=0"), control=list(max_treedepth=15, adapt_delta=0.99),warmup=1000,iter=10000,chains=3, cores=3) #This running has no divergent transitions. #Model summary precis(e1.nc) get_seed(e1.nc@stanfit) #93682 #View chains plot(e1.nc) #Posterior distributions for coefficients post.e1.nc <-extract.samples(e1.nc) sum(post.e1.nc$bTB>0)/length(post.e1.nc$bTB)#0% positive sum(post.e1.nc$bVSP>0)/length(post.e1.nc$bVSP)#26% positive sum(post.e1.nc$bViol>0)/length(post.e1.nc$bViol)#36% positive #Calculating predictions based upon model e1.nc using link() #Simulated data d.pred<-list( Violet =c(1,0,0,0), TypBlue=c(0,1,0,0), VestSP23=c(0,0,1,0), rep=c(1,2,3,4), #Means the replicates compared have unique random draws from the z scores. day=rep(1,4), site=rep(1,4) ) #Expected catches, given variability across observations #Simulated z-scores to make predictions for new days, sites, and observations beyond those that were observed #By deinition, these have mean of zero and SD of 1 #Simulations of za_rep to model overdispersion set.seed(591884) #To allow duplication za_rep_sims.e1<-rnorm(640000,0,1) za_rep_sims.e1<-matrix(za_rep_sims.e1,10000,64) #Simulations of za_day to model new days za_day_sims.e1<-rnorm(160000,0,1) za_day_sims.e1<-matrix(za_day_sims.e1,10000,16) #Simulations of za_site to model new sites za_site_sims.e1<-rnorm(40000,0,1) za_site_sims.e1<-matrix(za_site_sims.e1,10000,4) pred.all.e1.sims<-link(e1.nc,n=1e4,data=d.pred, replace=list(za_rep=za_rep_sims.e1, za_day=za_day_sims.e1,za_site=za_site_sims.e1)) pred.violet.e1.sims<-pred.all.e1.sims[,1] pred.vestZF.e1.sims<-pred.all.e1.sims[,4] pred.typBlue.e1.sims<-pred.all.e1.sims[,2] pred.vestSP23.e1.sims<-pred.all.e1.sims[,3] #Median expected catches median(pred.violet.e1.sims) #28.5 median(pred.vestZF.e1.sims) #29.7 median(pred.typBlue.e1.sims) #19.7 median(pred.vestSP23.e1.sims) #27.5 #Data for comparison table #Plausibility that violet target exceeds... #Typical blue sum(pred.violet.e1.sims>pred.typBlue.e1.sims)/length(pred.violet.e1.sims) #82% #VestZF sum(pred.violet.e1.sims>pred.vestZF.e1.sims)/length(pred.violet.e1.sims) #46% #VestSP23 sum(pred.violet.e1.sims>pred.vestSP23.e1.sims)/length(pred.violet.e1.sims) #54% #Plausibility that vestZF target exceeds... #Typical blue sum(pred.vestZF.e1.sims>pred.typBlue.e1.sims)/length(pred.vestZF.e1.sims) #84% #Violet sum(pred.vestZF.e1.sims>pred.violet.e1.sims)/length(pred.vestZF.e1.sims) #54% #VestSP23 sum(pred.vestZF.e1.sims>pred.vestSP23.e1.sims)/length(pred.vestZF.e1.sims) #58% #Plausibility that typBlue target exceeds... #VestZF sum(pred.typBlue.e1.sims>pred.vestZF.e1.sims)/length(pred.typBlue.e1.sims) #16% #Violet sum(pred.typBlue.e1.sims>pred.violet.e1.sims)/length(pred.typBlue.e1.sims) #18% #VestSP23 sum(pred.typBlue.e1.sims>pred.vestSP23.e1.sims)/length(pred.typBlue.e1.sims) #21% #Plausibility that vestSP23 target exceeds... #Typical blue sum(pred.vestSP23.e1.sims>pred.typBlue.e1.sims)/length(pred.vestSP23.e1.sims) #79% #Violet sum(pred.vestSP23.e1.sims>pred.violet.e1.sims)/length(pred.vestSP23.e1.sims) #46% #VestZF sum(pred.vestSP23.e1.sims>pred.vestZF.e1.sims)/length(pred.vestSP23.e1.sims) #42% #Expected catches for the average catch observation (i.e. ignoring the overdispersion of catches to look at average only) #Here, z-scores for replicate are replaced with zeroes so predictions are for the average observation za_rep_zeroes.e1<-rep(0,640000) za_rep_zeroes.e1<-matrix(za_rep_zeroes.e1,10000,64) pred.all.e1.col<-link(e1.nc,n=1e4,data=d.pred, replace=list(za_rep=za_rep_zeroes.e1, za_day=za_day_sims.e1,za_site=za_site_sims.e1)) pred.violet.e1.col<-pred.all.e1.col[,1] pred.vestZF.e1.col<-pred.all.e1.col[,4] pred.typBlue.e1.col<-pred.all.e1.col[,2] pred.vestSP23.e1.col<-pred.all.e1.col[,3] #Medians median(pred.violet.e1.col) #28.6 median(pred.vestZF.e1.col) #29.8 median(pred.typBlue.e1.col) #19.6 median(pred.vestSP23.e1.col) #27.7 #Prediction data for comparison table #Plausibility that violet target exceeds... #Typical blue sum(pred.violet.e1.col>pred.typBlue.e1.col)/length(pred.violet.e1.col) #100% #VestZF sum(pred.violet.e1.col>pred.vestZF.e1.col)/length(pred.violet.e1.col) #36% #VestSP23 sum(pred.violet.e1.col>pred.vestSP23.e1.col)/length(pred.violet.e1.col) #61% #Plausibility that vestZF target exceeds... #Typical blue sum(pred.vestZF.e1.col>pred.typBlue.e1.col)/length(pred.vestZF.e1.col) #100% #Violet sum(pred.vestZF.e1.col>pred.violet.e1.col)/length(pred.vestZF.e1.col) #64% #VestSP23 sum(pred.vestZF.e1.col>pred.vestSP23.e1.col)/length(pred.vestZF.e1.col) #73% #Plausibility that typBlue target exceeds... #VestZF sum(pred.typBlue.e1.col>pred.vestZF.e1.col)/length(pred.typBlue.e1.col) #0% #Violet sum(pred.typBlue.e1.col>pred.violet.e1.col)/length(pred.typBlue.e1.col) #0% #VestSP23 sum(pred.typBlue.e1.col>pred.vestSP23.e1.col)/length(pred.typBlue.e1.col) #0% #Plausibility that vestSP23 target exceeds... #Typical blue sum(pred.vestSP23.e1.col>pred.typBlue.e1.col)/length(pred.vestSP23.e1.col) #100% #Violet sum(pred.vestSP23.e1.col>pred.violet.e1.col)/length(pred.vestSP23.e1.col) #39% #VestZF sum(pred.vestSP23.e1.col>pred.vestZF.e1.col)/length(pred.vestSP23.e1.col) #27% #ANALYSIS OF EXPT 2 #Read experiment 2 data from csv file d2<-read.table("Expt2Kenya.csv", sep=",",header=TRUE) d2$flies<-d2$total #Specify response variable (to allow easy analysis of subsets) #Subset catches for use in boxplot ZFdata2<-d2[d2$fabric=="VestZF",] V4data2<-d2[d2$fabric=="Violet4.5%",] V7data2<-d2[d2$fabric=="Violet7%",] V9data2<-d2[d2$fabric=="Violet9%",] #An over-dispersed Poisson model using a non-centred parameterisation. #The RNG seed for the reported version is extracted below. e2.nc<-map2stan( alist( flies ~ dpois(lambda), log(lambda) <- a + za_rep[rep]*sigma_rep + za_day[day]*sigma_day + za_site[site]*sigma_site + bViol*VioletMid + bVLt*VioletLt + bVDk*VioletDk, a ~ dnorm(0,10), bVLt ~ dnorm(0,10), #Regularising priors bViol ~ dnorm(0,10), bVDk ~ dnorm(0,10), za_day[day] ~ dnorm(0,1), za_rep[rep] ~ dnorm(0, 1), za_site[site] ~ dnorm(0,1), sigma_rep ~ dnorm(0,1), sigma_day ~ dnorm(0,1), sigma_site ~ dnorm(0,1) ), data=d2, constraints=list(sigma_rep="lower=0",sigma_day="lower=0",sigma_site="lower=0"), control=list(max_treedepth=15,adapt_delta=0.99),warmup=1000,iter=10000,chains=3, cores=3) #No warnings precis(e2.nc) get_seed(e2.nc@stanfit) #97965 #Posterior distributions of coefficients post.e2.nc <-extract.samples(e2.nc) sum(post.e2.nc$bVLt>0)/length(post.e2.nc$bVLt)#77% positive sum(post.e2.nc$bViol>0)/length(post.e2.nc$bViol)#97% positive sum(post.e2.nc$bVDk>0)/length(post.e2.nc$bVDk)#94% positive #Calculating predictions based upon model e2.nc using link() d2.pred<-list( VioletMid =c(1,0,0,0), VioletDk=c(0,1,0,0), VioletLt=c(0,0,1,0), rep=c(1,2,3,4), #Means the replicates compared have unique random draws from the z scores. day=rep(1,4), site=rep(1,4) ) #Predictions of expected catches, accounting for variability across observations #New z-scores for day, site, and rep #Simulations of za_rep to model overdispersion set.seed(61217) za_rep_sims.e2<-rnorm(640000,0,1) za_rep_sims.e2<-matrix(za_rep_sims.e2,10000,64) #Simulations of a_day to replace 16 days za_day_sims.e2<-rnorm(160000,0,1) za_day_sims.e2<-matrix(za_day_sims.e2,10000,16) #Simulations of a_site to replace 8 sites za_site_sims.e2<-rnorm(80000,0,1) za_site_sims.e2<-matrix(za_site_sims.e2,10000,8) #Predictions using link pred.all.e2.sims<-link(e2.nc,n=10000,data=d2.pred, replace=list(za_day=za_day_sims.e2, za_site=za_site_sims.e2, za_rep=za_rep_sims.e2)) pred.violet.e2.sims<-pred.all.e2.sims[,1] pred.violetDk.e2.sims<-pred.all.e2.sims[,2] pred.violetLt.e2.sims<-pred.all.e2.sims[,3] pred.vestZF.e2.sims<-pred.all.e2.sims[,4] #Medians median(pred.violet.e2.sims) #22.9 median(pred.vestZF.e2.sims) #17.9 median(pred.violetDk.e2.sims) #22.0 median(pred.violetLt.e2.sims) #19.7 #Prediction data for comparison table #Plausibility that violet (mid) target exceeds... #VestZF sum(pred.violet.e2.sims>pred.vestZF.e2.sims)/length(pred.violet.e2.sims)#71% #VioletDk sum(pred.violet.e2.sims>pred.violetDk.e2.sims)/length(pred.violet.e2.sims)#54% #VioletLt sum(pred.violet.e2.sims>pred.violetLt.e2.sims)/length(pred.violet.e2.sims)#64% #Plausibility that violetDk target exceeds... #VestZF sum(pred.violetDk.e2.sims>pred.vestZF.e2.sims)/length(pred.violetDk.e2.sims)#68% #Violet(mid) sum(pred.violetDk.e2.sims>pred.violet.e2.sims)/length(pred.violetDk.e2.sims)#46% #VioletLt sum(pred.violetDk.e2.sims>pred.violetLt.e2.sims)/length(pred.violetDk.e2.sims)#60% #Plausibility that violetLt target exceeds... #VestZF sum(pred.violetLt.e2.sims>pred.vestZF.e2.sims)/length(pred.violetLt.e2.sims)#59% #Violet (mid) sum(pred.violetLt.e2.sims>pred.violet.e2.sims)/length(pred.violetLt.e2.sims)#36% #VioletDk sum(pred.violetLt.e2.sims>pred.violetDk.e2.sims)/length(pred.violetLt.e2.sims)#40% #Plausibility that vestZF target exceeds... #VioletLt sum(pred.vestZF.e2.sims>pred.violetLt.e2.sims)/length(pred.vestZF.e2.sims)#41% #Violet (mid) sum(pred.vestZF.e2.sims>pred.violet.e2.sims)/length(pred.vestZF.e2.sims)#29% #VioletDk sum(pred.vestZF.e2.sims>pred.violetDk.e2.sims)/length(pred.vestZF.e2.sims)#32% #Predictions for the average catch observation, excluding variability in catches #za_rep set to zero to remove overdispersion za_rep_zeroes.e2<-rep(0,640000) za_rep_zeroes.e2<-matrix(za_rep_zeroes.e2,10000,64) #Predictions using link pred.all.e2.col<-link(e2.nc,n=10000,data=d2.pred, replace=list(za_day=za_day_sims.e2, za_site=za_site_sims.e2, za_rep=za_rep_zeroes.e2)) pred.violet.e2.col<-pred.all.e2.col[,1] pred.violetDk.e2.col<-pred.all.e2.col[,2] pred.violetLt.e2.col<-pred.all.e2.col[,3] pred.vestZF.e2.col<-pred.all.e2.col[,4] #Medians median(pred.violet.e2.col) #22.9 median(pred.vestZF.e2.col) #17.8 median(pred.violetDk.e2.col) #21.9 median(pred.violetLt.e2.col) #19.7 #Prediction data for comparison table #Plausibility that violet (mid) target exceeds... #VestZF sum(pred.violet.e2.col>pred.vestZF.e2.col)/length(pred.violet.e2.col)#97% #VioletDk sum(pred.violet.e2.col>pred.violetDk.e2.col)/length(pred.violet.e2.col)#62% #VioletLt sum(pred.violet.e2.col>pred.violetLt.e2.col)/length(pred.violet.e2.col)#87% #Plausibility that violetDk target exceeds... #VestZF sum(pred.violetDk.e2.col>pred.vestZF.e2.col)/length(pred.violetDk.e2.col)#93% #Violet(mid) sum(pred.violetDk.e2.col>pred.violet.e2.col)/length(pred.violetDk.e2.col)#38% #VioletLt sum(pred.violetDk.e2.col>pred.violetLt.e2.col)/length(pred.violetDk.e2.col)#79% #Plausibility that violetLt target exceeds... #VestZF sum(pred.violetLt.e2.col>pred.vestZF.e2.col)/length(pred.violetLt.e2.col)#77% #Violet (mid) sum(pred.violetLt.e2.col>pred.violet.e2.col)/length(pred.violetLt.e2.col)#13% #VioletDk sum(pred.violetLt.e2.col>pred.violetDk.e2.col)/length(pred.violetLt.e2.col)#21% #Plausibility that vestZF target exceeds... #VioletLt sum(pred.vestZF.e2.col>pred.violetLt.e2.col)/length(pred.vestZF.e2.col)#23% #Violet (mid) sum(pred.vestZF.e2.col>pred.violet.e2.col)/length(pred.vestZF.e2.col)#3% #VioletDk sum(pred.vestZF.e2.col>pred.violetDk.e2.col)/length(pred.vestZF.e2.col)#7% #PREPARATION OF FIGURE 2 TO SUMMARISE DATA FROM KENYA EXPERIMENTS #Prepare plot space with 4 panels par(mfrow=c(2,2)) par(mar=c(3,3,3,3), mgp=c(2,0.5,0)) #Panel 1: Boxplot of expt 1 data boxplot(TBdata$flies,ZFdata$flies,SP23data$flies,Vdata$flies, at=c(1,2,3,4), names=c("Typ.blue","Vest.ZF","Vest.\nSP23 (P)","Violet"), ylab="Total catch", ylim=c(0,90), las=2 ) title("A.",adj=0.05,line=-2) #Panel 2: Boxplot of expt 2 data boxplot(ZFdata2$flies,V4data2$flies,V7data2$flies,V9data2$flies, at=c(1,2,3,4), names=c("Vest. ZF","Violet\n4.5% (P)","Violet\n7% (P)","Violet\n9% (P)"), ylab="Total catch", ylim=c(0,85), las=2 ) title("C.",adj=0.05,line=-2) #Panel 3: Predictions based on expt 1 dens(pred.violet.e1.sims,col="darkorchid4", xlab="Expected catch",xlim=c(0,100),ylim=c(0,0.15)) dens(pred.vestZF.e1.sims,col="dodgerblue3", add=TRUE) dens(pred.typBlue.e1.sims,col="dodgerblue", lty="dashed",add=TRUE) dens(pred.vestSP23.e1.sims,col="dodgerblue4", lty="dotted",add=TRUE) title("B.", adj=0.05,line=-2) legend( 45,0.15, legend=c("Typical blue", "Vest. ZF", "Vest. SP23 (P)", "Violet"), col=c("dodgerblue","dodgerblue3","dodgerblue4","darkorchid4"), lty=c("dashed","solid","dotted","solid" ), cex=0.8) #Panel 4: Predictions based on expt 2 dens(pred.violet.e2.sims,col="darkorchid", lty="dotted",xlab="Expected catch",xlim=c(0,60),ylim=c(0,0.05)) dens(pred.vestZF.e2.sims,col="dodgerblue3", add=TRUE) dens(pred.violetDk.e2.sims,col="darkorchid4", lty="dashed",add=TRUE) dens(pred.violetLt.e2.sims,col="darkorchid1", lty="twodash",add=TRUE) title("D.", adj=0.05,line=-2) legend( 25,0.05, legend=c("Vest. ZF", "Violet 4.5% (P)", "Violet 7% (P)", "Violet 9% (P)"), col=c("dodgerblue3","darkorchid1","darkorchid","darkorchid4"), lty=c("solid","twodash","dotted","dashed" ), cex=0.8) #ANALYSIS OF EXPT 3 #Read experiment 3 data from csv file d3<-read.table("Expt3Uganda.csv", sep=",",header=TRUE) d3$flies<-d3$total #Specify response variable (to allow easy analysis of subsets) #Subset catches for later use in boxplot ZFdata3<-d3[d3$fabric=="VestZF",] TBdata3<-d3[d3$fabric=="TypBlue",] Vdata3<-d3[d3$fabric=="Violet",] #A zero-inflated, over-dispersed Poisson model using a non-centred parameterisation. #The RNG seed for the reported version is extracted below. e3.1nc<-map2stan( alist( flies ~ dzipois(p,lambda), logit(p) <- ap, log(lambda) <- a + za_rep[rep]*sigma_rep + za_day[day]*sigma_day + za_site[site]*sigma_site + bViol*Violet + bTB*TypBlue, ap ~ dnorm(0,1), a ~ dnorm(0,10), bViol ~ dnorm(0,10), bTB ~ dnorm(0,10), za_rep[rep] ~ dnorm(0,1), za_day[day] ~ dnorm(0,1), za_site[site] ~ dnorm(0,1), sigma_rep ~ dnorm(0,1), sigma_day ~ dnorm(0,1), sigma_site ~ dnorm(0,1) ), data=d3, constraints=list(sigma_rep="lower=0",sigma_day="lower=0",sigma_site="lower=0"), control=list(max_treedepth=15, adapt_delta=0.99), warmup=1000,iter=10000,chains=3, cores=3) #No warnings precis(e3.1nc) get_seed(e3.1nc@stanfit) #19827 #Calculating predictions based upon model e3.1nc using link() d3.pred<-list( Violet =c(1,0,0), TypBlue=c(0,1,0), rep=c(1,2,3), day=rep(1,3), site=rep(1,3) ) #Predictions including catch variability across observations #New z-scores to simulate new days, sites, and observations #By deinition, they have mean of zero and SD of 1 #Simulations of za_rep to model overdispersion set.seed(311698) #Replace varying intercept samples with simulations for 17 new days and 4 new sites and 50 new replicates za_day_sims.e3<-rnorm(170000,0,1) za_day_sims.e3<-matrix(za_day_sims.e3,10000,17) za_site_sims.e3<-rnorm(30000,0,1) za_site_sims.e3<-matrix(za_site_sims.e3,10000,3) za_rep_sims.e3<-rnorm(500000,0,1) za_rep_sims.e3<-matrix(za_rep_sims.e3,10000,50) pred.all.e3.sims<-link(e3.1nc,n=10000,data=d3.pred, replace=list(za_day=za_day_sims.e3, za_site=za_site_sims.e3, za_rep=za_rep_sims.e3)) #Because this is a zero-inflated Poisson distribution, link() outputs both p and lambda. #Mean prediction for the binary logistic process sum(pred.all.e3.sims$p[,1])/length(pred.all.e3.sims$p[,1]) #22% sum(pred.all.e3.sims$p [,2])/length(pred.all.e3.sims$p[,2]) #22% sum(pred.all.e3.sims$p[,3])/length(pred.all.e3.sims$p[,3]) #22% #Poisson process... pred.violet.e3.sims<-pred.all.e3.sims$lambda[,1] pred.typBlue.e3.sims<-pred.all.e3.sims$lambda[,2] pred.vestZF.e3.sims<-pred.all.e3.sims$lambda[,3] #Medians median(pred.violet.e3.sims) #2.0 median(pred.vestZF.e3.sims) #1.6 median(pred.typBlue.e3.sims) #1.4 #Data for comparison table #Plausibility that violet target exceeds... #VestZF sum(pred.violet.e3.sims>pred.vestZF.e3.sims)/length(pred.violet.e3.sims) #64% #typ blue sum(pred.violet.e3.sims>pred.typBlue.e3.sims)/length(pred.violet.e3.sims) #70% #Plausibility that vest ZF target exceeds... #violet sum(pred.vestZF.e3.sims>pred.violet.e3.sims)/length(pred.vestZF.e3.sims) #36% #typ blue sum(pred.vestZF.e3.sims>pred.typBlue.e3.sims)/length(pred.vestZF.e3.sims) #59% #Plausibility that typ blue target exceeds... #violet sum(pred.typBlue.e3.sims>pred.violet.e3.sims)/length(pred.typBlue.e3.sims) #30% #vest ZF sum(pred.typBlue.e3.sims>pred.vestZF.e3.sims)/length(pred.typBlue.e3.sims) #41% #Predictions for average catch observation #za_rep set to zero to remove overdispersion za_rep_zeroes.e3<-rep(0,500000) za_rep_zeroes.e3<-matrix(za_rep_zeroes.e3,10000,50) pred.all.e3.col<-link(e3.1nc,n=10000,data=d3.pred, replace=list(za_day=za_day_sims.e3, za_site=za_site_sims.e3, za_rep=za_rep_zeroes.e3)) pred.violet.e3.col<-pred.all.e3.col$lambda[,1] pred.typBlue.e3.col<-pred.all.e3.col$lambda[,2] pred.vestZF.e3.col<-pred.all.e3.col$lambda[,3] #Medians median(pred.violet.e3.col) #1.9 median(pred.vestZF.e3.col) #1.6 median(pred.typBlue.e3.col) #1.4 #Data for comparison table #Plausibility that violet target exceeds... #VestZF sum(pred.violet.e3.col>pred.vestZF.e3.col)/length(pred.violet.e3.col) #75% #typ blue sum(pred.violet.e3.col>pred.typBlue.e3.col)/length(pred.violet.e3.col) #81% #Plausibility that vest ZF target exceeds... #violet sum(pred.vestZF.e3.col>pred.violet.e3.col)/length(pred.vestZF.e3.col) #25% #typ blue sum(pred.vestZF.e3.col>pred.typBlue.e3.col)/length(pred.vestZF.e3.col) #64% #Plausibility that typ blue target exceeds... #violet sum(pred.typBlue.e3.col>pred.violet.e3.col)/length(pred.typBlue.e3.col) #19% #vest ZF sum(pred.typBlue.e3.col>pred.vestZF.e3.col)/length(pred.typBlue.e3.col) #36% #A non-zero-inflated, over-dispersed Poisson model using a non-centred parameterisation. #The RNG seed for the reported version is extracted below. e3.2nc.nzi<-map2stan( alist( flies ~ dpois(lambda), log(lambda) <- a + za_rep[rep]*sigma_rep + za_day[day]*sigma_day + za_site[site]*sigma_site + bViol*Violet + bTB*TypBlue, a ~ dnorm(0,10), bViol ~ dnorm(0,10), bTB ~ dnorm(0,10), za_rep[rep] ~ dnorm(0,1), za_day[day] ~ dnorm(0,1), za_site[site] ~ dnorm(0,1), sigma_rep ~ dnorm(0,1), sigma_day ~ dnorm(0,1), sigma_site ~ dnorm(0,1) ), data=d3, constraints=list(sigma_rep="lower=0",sigma_day="lower=0",sigma_site="lower=0"), control=list(max_treedepth=15, adapt_delta=0.99), warmup=1000,iter=10000,chains=3, cores=3, rng_seed=23610) #This running has no divergent transitions. get_seed(e3.2nc.nzi@stanfit) #23610 #Comparison of these models based upon AIC. compare(e3.1nc, e3.2nc.nzi) #dWAIC 6.9, dSE 3.11 e3.models <- compare(e3.1nc, e3.2nc.nzi) plot(e3.models, SE=TRUE, dSE=TRUE) precis(e3.2nc.nzi) #Repeating the catch predictions based upon the non-zero-inflated model (e3.nc.nzi) pred.all.e3.sims.nzi<-link(e3.2nc.nzi,n=10000,data=d3.pred, replace=list(za_day=za_day_sims.e3, za_site=za_site_sims.e3, za_rep=za_rep_sims.e3)) #Poisson process... pred.violet.e3.sims.nzi<-pred.all.e3.sims.nzi[,1] pred.typBlue.e3.sims.nzi<-pred.all.e3.sims.nzi[,2] pred.vestZF.e3.sims.nzi<-pred.all.e3.sims.nzi[,3] #Medians median(pred.violet.e3.sims.nzi) #1.3 median(pred.vestZF.e3.sims.nzi) #1.2 median(pred.typBlue.e3.sims.nzi) #0.8 #Data for comparison table #Plausibility that violet target exceeds... #VestZF sum(pred.violet.e3.sims.nzi>pred.vestZF.e3.sims.nzi)/length(pred.violet.e3.sims.nzi) #52% #typ blue sum(pred.violet.e3.sims.nzi>pred.typBlue.e3.sims.nzi)/length(pred.violet.e3.sims.nzi) #70% #Plausibility that vest ZF target exceeds... #violet sum(pred.vestZF.e3.sims.nzi>pred.violet.e3.sims.nzi)/length(pred.vestZF.e3.sims.nzi) #48% #typ blue sum(pred.vestZF.e3.sims.nzi>pred.typBlue.e3.sims.nzi)/length(pred.vestZF.e3.sims.nzi) #69% #Plausibility that typ blue target exceeds... #violet sum(pred.typBlue.e3.sims.nzi>pred.violet.e3.sims.nzi)/length(pred.typBlue.e3.sims.nzi) #30% #vest ZF sum(pred.typBlue.e3.sims.nzi>pred.vestZF.e3.sims.nzi)/length(pred.typBlue.e3.sims.nzi) #31% #Predictions for average catch observation pred.all.e3.col.nzi<-link(e3.2nc.nzi,n=10000,data=d3.pred, replace=list(za_day=za_day_sims.e3, za_site=za_site_sims.e3, za_rep=za_rep_zeroes.e3)) pred.violet.e3.col.nzi<-pred.all.e3.col.nzi[,1] pred.typBlue.e3.col.nzi<-pred.all.e3.col.nzi[,2] pred.vestZF.e3.col.nzi<-pred.all.e3.col.nzi[,3] #Medians median(pred.violet.e3.col.nzi) #1.3 median(pred.vestZF.e3.col.nzi) #1.2 median(pred.typBlue.e3.col.nzi) #0.8 #Data for comparison table #Plausibility that violet target exceeds... #VestZF sum(pred.violet.e3.col.nzi>pred.vestZF.e3.col.nzi)/length(pred.violet.e3.col.nzi) #57% #typ blue sum(pred.violet.e3.col.nzi>pred.typBlue.e3.col.nzi)/length(pred.violet.e3.col.nzi) #90% #Plausibility that vest ZF target exceeds... #violet sum(pred.vestZF.e3.col.nzi>pred.violet.e3.col.nzi)/length(pred.vestZF.e3.col.nzi) #43% #typ blue sum(pred.vestZF.e3.col.nzi>pred.typBlue.e3.col.nzi)/length(pred.vestZF.e3.col.nzi) #86% #Plausibility that typ blue target exceeds... #violet sum(pred.typBlue.e3.col.nzi>pred.violet.e3.col.nzi)/length(pred.typBlue.e3.col.nzi) #10% #vest ZF sum(pred.typBlue.e3.col.nzi>pred.vestZF.e3.col.nzi)/length(pred.typBlue.e3.col.nzi) #14% #PREPARATION OF FIGURE 3: SUMMARY OF UGANDA EXPERIMENT #Prepare plot space with 4 panels (but only plot in two) par(mfrow=c(2,2)) par(mar=c(3,3,3,3), mgp=c(2,0.5,0)) #Panel 1: Boxplot of data boxplot(TBdata3$flies,ZFdata3$flies,Vdata3$flies, at=c(1,2,3), names=c("Typ. blue","Vest. ZF","Violet"), ylab="Total catch", ylim=c(0,8), las=2 ) title("A.",adj=0.05, line=-2) #Blank plot.new() #Panel 2: Predictions with variability (using ZI model) dens(pred.violet.e3.sims,col="darkorchid4", xlab="Expected catch",xlim=c(0,10),ylim=c(0,1.5)) dens(pred.vestZF.e3.sims,col="dodgerblue3", add=TRUE) dens(pred.typBlue.e3.sims,col="dodgerblue", lty="dashed",add=TRUE) title("B.", adj=0.05, line=-2) legend( 6,1.5, legend=c("Typ. blue", "Vest. ZF", "Violet"), col=c("dodgerblue","dodgerblue3","darkorchid4"), lty=c("dashed","solid","solid"), cex=0.8) #POSTERIOR PREDICTIVE CHECKS FOR ESM #Prepare plot space with 4 panels par(mfrow=c(4,1)) par(mar=c(3,3,3,3), mgp=c(2,0.5,0)) #Posterior predictive check for 64 observations from experiment 1 postcheck(e1.nc, window = 64) title("A. Experiment 1",adj=0.95,line=-1) #Posterior predictive check for 64 observations from experiment 2 postcheck(e2.nc, window = 64) title("B. Experiment 2",adj=0.95,line=-1) #Posterior predictive check for 50 observations from experiment 3 (both models) postcheck(e3.2nc.nzi, window = 50) title("C. Experiment 3 (no ZI)",adj=0.95,line=-1) postcheck(e3.1nc, window = 50) title("D. Experiment 3 (ZI)",adj=0.95,line=-1) #Interpretation: blue dots are observed data. Circles are posterior means and lines 89% percentile interval; + are 89% interval of predicted counts. #Additional plot of predictions using non-ZI model par(mfrow=c(2,2)) par(mar=c(3,3,3,3), mgp=c(2,0.5,0)) dens(pred.violet.e3.sims.nzi,col="darkorchid4", xlab="Expected catch", xlim=c(0,50), ylim=c(0,4)) dens(pred.vestZF.e3.sims.nzi,col="dodgerblue3", add=TRUE) dens(pred.typBlue.e3.sims.nzi,col="dodgerblue", lty="dashed",add=TRUE) # NEGATIVE BINOMIAL MODELS FOR COMPARISON IN ESM #Experiment 1 #A negative binomial model using a non-centred parameterisation. #The RNG seed for the reported version is extracted below. e1.nc.nb<-map2stan( alist( flies ~ dgampois(mu, scale), log(mu) <- a + za_day[day]*sigma_day + za_site[site]*sigma_site + bTB*TypBlue + bVSP*VestSP23 + bViol*Violet, a ~ dnorm(0,10), bTB ~ dnorm(0,10), bVSP ~ dnorm(0,10), bViol ~ dnorm(0,10), za_day[day] ~ dnorm(0,1), za_site[site] ~ dnorm(0,1), sigma_day ~ dnorm(0,1), sigma_site ~ dnorm(0,1), scale ~ dnorm(0,10) ), data=d, constraints=list(sigma_day="lower=0",sigma_site="lower=0",scale="lower=0"), control=list(max_treedepth=15, adapt_delta=0.99),warmup=1000,iter=10000,chains=3, cores=3) #This running has no divergent transitions. get_seed(e1.nc.nb@stanfit) #49419 #Model summary (and comparison to Poisson model) precis(e1.nc)#Poisson precis(e1.nc.nb)#neg bin #Coefficients very similar #Comparison of postcheck plots #Prepare plot space with 2 panels par(mfrow=c(3,1)) par(mar=c(3,3,3,3), mgp=c(2,0.5,0)) #Poisson model postcheck(e1.nc, window = 64) title("A. Poisson",adj=0.95,line=-2) #Neg bin model postcheck(e1.nc.nb, window = 64) title("B. Neg bin",adj=0.95,line=-2) #Blank plot.new() #Predictions for comparison to those for AVERAGE OBSERVATION (overdispersion is in the distribution, not the expected catches) #Uses random z scores as were generated above pred.all.e1.nb<-link(e1.nc.nb,n=1e4,data=d.pred, replace=list(za_day=za_day_sims.e1,za_site=za_site_sims.e1)) pred.violet.e1.nb<-pred.all.e1.nb[,1] pred.vestZF.e1.nb<-pred.all.e1.nb[,4] pred.typBlue.e1.nb<-pred.all.e1.nb[,2] pred.vestSP23.e1.nb<-pred.all.e1.nb[,3] #Medians median(pred.violet.e1.nb) #29.9 vs 28.6 for over-dispersed Poisson median(pred.vestZF.e1.nb) #30.9 vs 29.8 median(pred.typBlue.e1.nb) #20.5 vs 19.6 median(pred.vestSP23.e1.nb) #28.9 vs 27.7 #Prediction data for comparison table #Plausibility that violet target exceeds... #Typical blue sum(pred.violet.e1.nb>pred.typBlue.e1.nb)/length(pred.violet.e1.nb) #100 vs 100% #VestZF sum(pred.violet.e1.nb>pred.vestZF.e1.nb)/length(pred.violet.e1.nb) #37 vs 36% #VestSP23 sum(pred.violet.e1.nb>pred.vestSP23.e1.nb)/length(pred.violet.e1.nb) #61 vs 61% #Plausibility that vestZF target exceeds... #Typical blue sum(pred.vestZF.e1.nb>pred.typBlue.e1.nb)/length(pred.vestZF.e1.nb) #100 vs 100% #Violet sum(pred.vestZF.e1.nb>pred.violet.e1.nb)/length(pred.vestZF.e1.nb) #63 vs 64% #VestSP23 sum(pred.vestZF.e1.nb>pred.vestSP23.e1.nb)/length(pred.vestZF.e1.nb) #73 vs 73% #Plausibility that typBlue target exceeds... #VestZF sum(pred.typBlue.e1.nb>pred.vestZF.e1.nb)/length(pred.typBlue.e1.nb) #0 vs 0% #Violet sum(pred.typBlue.e1.nb>pred.violet.e1.nb)/length(pred.typBlue.e1.nb) #0 vs 0% #VestSP23 sum(pred.typBlue.e1.nb>pred.vestSP23.e1.nb)/length(pred.typBlue.e1.nb) #0 vs 0% #Plausibility that vestSP23 target exceeds... #Typical blue sum(pred.vestSP23.e1.nb>pred.typBlue.e1.nb)/length(pred.vestSP23.e1.nb) #100 vs 100% #Violet sum(pred.vestSP23.e1.nb>pred.violet.e1.nb)/length(pred.vestSP23.e1.nb) #39 vs 39% #VestZF sum(pred.vestSP23.e1.nb>pred.vestZF.e1.nb)/length(pred.vestSP23.e1.nb) #27 vs 27% #Experiment 2 #A negative binomial model using a non-centred parameterisation. #The RNG seed for the reported version is extracted below. e2.nc.nb<-map2stan( alist( flies ~ dgampois(mu, scale), log(mu) <- a + za_day[day]*sigma_day + za_site[site]*sigma_site + bViol*VioletMid + bVLt*VioletLt + bVDk*VioletDk, a ~ dnorm(0,10), bVLt ~ dnorm(0,10), #Regularising priors bViol ~ dnorm(0,10), bVDk ~ dnorm(0,10), za_day[day] ~ dnorm(0,1), za_site[site] ~ dnorm(0,1), sigma_day ~ dnorm(0,1), sigma_site ~ dnorm(0,1), scale ~ dnorm(0,10) ), data=d2, constraints=list(scale="lower=0",sigma_day="lower=0",sigma_site="lower=0"), control=list(max_treedepth=15,adapt_delta=0.99),warmup=1000,iter=10000,chains=3, cores=3) #This running has no divergent transitions. get_seed(e2.nc.nb@stanfit) #66248 #Model summary (and comparison to Poisson model) precis(e2.nc)#Poisson precis(e2.nc.nb)#neg bin #Coefficients again very similar #Comparison of postcheck plots #Prepare plot space with 2 panels par(mfrow=c(3,1)) par(mar=c(3,3,3,3), mgp=c(2,0.5,0)) #Poisson model postcheck(e2.nc, window = 64) title("A. Poisson",adj=0.95,line=-2) #Neg bin model postcheck(e2.nc.nb, window = 64) title("B. Neg bin",adj=0.95,line=-2) #Blank plot.new() #Predictions for comparison to those for AVERAGE OBSERVATION (overdispersion is in the distribution, not the expected catches) #Uses random z scores as were generated above pred.all.e2.nb<-link(e2.nc.nb,n=10000,data=d2.pred, replace=list(za_day=za_day_sims.e2, za_site=za_site_sims.e2)) pred.violet.e2.nb<-pred.all.e2.nb[,1] pred.violetDk.e2.nb<-pred.all.e2.nb[,2] pred.violetLt.e2.nb<-pred.all.e2.nb[,3] pred.vestZF.e2.nb<-pred.all.e2.nb[,4] #Medians median(pred.violet.e2.nb) #24.4 vs 22.9 for over-dispersed Poisson model median(pred.vestZF.e2.nb) #19.1 vs 17.8 median(pred.violetDk.e2.nb) #23.0 vs 21.9 median(pred.violetLt.e2.nb) #20.6 vs 19.7 #Prediction data for comparison table #Plausibility that violet (mid) target exceeds... #VestZF sum(pred.violet.e2.nb>pred.vestZF.e2.nb)/length(pred.violet.e2.nb)#97 vs 97% #VioletDk sum(pred.violet.e2.nb>pred.violetDk.e2.nb)/length(pred.violet.e2.nb)#67 vs 62% #VioletLt sum(pred.violet.e2.nb>pred.violetLt.e2.nb)/length(pred.violet.e2.nb)#90 vs 87% #Plausibility that violetDk target exceeds... #VestZF sum(pred.violetDk.e2.nb>pred.vestZF.e2.nb)/length(pred.violetDk.e2.nb)#92 vs 93% #Violet(mid) sum(pred.violetDk.e2.nb>pred.violet.e2.nb)/length(pred.violetDk.e2.nb)#33 vs 38% #VioletLt sum(pred.violetDk.e2.nb>pred.violetLt.e2.nb)/length(pred.violetDk.e2.nb)#80 vs 79% #Plausibility that violetLt target exceeds... #VestZF sum(pred.violetLt.e2.nb>pred.vestZF.e2.nb)/length(pred.violetLt.e2.nb)#71 vs 77% #Violet (mid) sum(pred.violetLt.e2.nb>pred.violet.e2.nb)/length(pred.violetLt.e2.nb)#10 vs 13% #VioletDk sum(pred.violetLt.e2.nb>pred.violetDk.e2.nb)/length(pred.violetLt.e2.nb)#20 vs 21% #Plausibility that vestZF target exceeds... #VioletLt sum(pred.vestZF.e2.nb>pred.violetLt.e2.nb)/length(pred.vestZF.e2.nb)#29 vs 23% #Violet (mid) sum(pred.vestZF.e2.nb>pred.violet.e2.nb)/length(pred.vestZF.e2.nb)#3 vs 3% #VioletDk sum(pred.vestZF.e2.nb>pred.violetDk.e2.nb)/length(pred.vestZF.e2.nb)#8 vs 7% #Experiment 3 #Unfortunately there is not a zero-inflated negative binomial function in the 'Rethinking' package #Therefore, a non-zero inflated negative binomial model using a non-centred parameterisation for comparison to non-zero-inflated over-dispersed Poisson. #The RNG seed for the reported version is extracted below. e3.2nc.nzi.nb<-map2stan( alist( flies ~ dgampois(mu,scale), log(mu) <- a + za_day[day]*sigma_day + za_site[site]*sigma_site + bViol*Violet + bTB*TypBlue, a ~ dnorm(0,10), bViol ~ dnorm(0,10), bTB ~ dnorm(0,10), za_day[day] ~ dnorm(0,1), za_site[site] ~ dnorm(0,1), sigma_day ~ dnorm(0,1), sigma_site ~ dnorm(0,1), scale ~ dnorm(0,10) ), data=d3, constraints=list(scale="lower=0",sigma_day="lower=0",sigma_site="lower=0"), control=list(max_treedepth=15, adapt_delta=0.99), warmup=1000,iter=10000,chains=3, cores=3) #This running has no divergent transitions. get_seed(e3.2nc.nzi.nb@stanfit) #70878 #Model summaries for comparsion precis(e3.1nc)#ZI Poisson precis(e3.2nc.nzi)#Poisson precis(e3.2nc.nzi.nb)#neg bin plot(precis(e3.1nc, depth = 2)) plot(precis(e3.2nc.nzi, depth = 2)) #Comparison of postcheck plots #Prepare plot space with 3 panels par(mfrow=c(3,1)) par(mar=c(3,3,3,3), mgp=c(2,0.5,0)) #ZI Poisson model postcheck(e3.1nc, window = 50) title("A. ZI Poisson",adj=0.95,line=-2) #Poisson model postcheck(e3.2nc.nzi, window = 50) title("B. Poisson (no ZI)",adj=0.95,line=-2) #Neg bin model postcheck(e3.2nc.nzi.nb, window = 50) title("C. Negative binomial (no ZI)",adj=0.95,line=-2) #Predictions for comparison to those for AVERAGE OBSERVATION in non-ZI model (overdispersion is in the distribution, not the expected catches) #Uses random z scores as were generated above pred.all.e3.nb<-link(e3.2nc.nzi.nb,n=10000,data=d3.pred, replace=list(za_day=za_day_sims.e3, za_site=za_site_sims.e3)) pred.violet.e3.nb<-pred.all.e3.nb[,1] pred.typBlue.e3.nb<-pred.all.e3.nb[,2] pred.vestZF.e3.nb<-pred.all.e3.nb[,3] #Medians median(pred.violet.e3.nb) #1.6 vs 1.3 in non-ZI over-dispersed Poisson model median(pred.vestZF.e3.nb) #1.5 vs 1.2 median(pred.typBlue.e3.nb) #1.0 vs 0.8 #Data for comparison table #Plausibility that violet target exceeds... #VestZF sum(pred.violet.e3.nb>pred.vestZF.e3.nb)/length(pred.violet.e3.nb) #60 vs 57% #typ blue sum(pred.violet.e3.nb>pred.typBlue.e3.nb)/length(pred.violet.e3.nb) #90 vs 90% #Plausibility that vest ZF target exceeds... #violet sum(pred.vestZF.e3.nb>pred.violet.e3.nb)/length(pred.vestZF.e3.nb) #40 vs 43% #typ blue sum(pred.vestZF.e3.nb>pred.typBlue.e3.nb)/length(pred.vestZF.e3.nb) #86 vs 86% #Plausibility that typ blue target exceeds... #violet sum(pred.typBlue.e3.nb>pred.violet.e3.nb)/length(pred.typBlue.e3.nb) #10 vs 10% #vest ZF sum(pred.typBlue.e3.nb>pred.vestZF.e3.nb)/length(pred.typBlue.e3.nb) #14 vs 14% #GLMM ANALYSES FOR ESM FILE #EXPT 1 e1.glmm<-glmmTMB(flies~fabric+(1|day)+(1|site), data=d, family=nbinom2) summary(e1.glmm) glmmTMB:::Anova.glmmTMB(e1.glmm,3) table<-emmeans(e1.glmm,"fabric") pairs(table,adjust="none") #Typical blue is significantly different to the others. #Zero-inflated model e1.glmm.zi<-glmmTMB(flies~fabric+(1|day)+(1|site), zi=~1,data=d, family=nbinom2) summary(e1.glmm.zi) glmmTMB:::Anova.glmmTMB(e1.glmm.zi,3) table<-emmeans(e1.glmm.zi,"fabric") pairs(table,adjust="none") #Typical blue is significantly different to the others. #Attempted over-dispersed Poisson e1.glmm.odp<-glmmTMB(flies~fabric+(1|day)+(1|site)+(1|rep), data=d, family=poisson) summary(e1.glmm.odp) glmmTMB:::Anova.glmmTMB(e1.glmm.odp,3) table<-emmeans(e1.glmm.odp,"fabric") pairs(table,adjust="none") #Same outcome: Typical Blue is different to everything else. #Model is very similar. AICtab(e1.glmm, e1.glmm.zi,e3.glmm.odp) #Over-dispersed Poisson is best fit; ZI is worst. #EXPT 2 e2.glmm<-glmmTMB(flies~fabric+(1|day)+(1|site), data=d2, family=nbinom2) summary(e2.glmm) glmmTMB:::Anova.glmmTMB(e2.glmm,3) #No significant effects e2.glmm.zi<-glmmTMB(flies~fabric+(1|day)+(1|site), zi=~1,data=d2, family=nbinom2) summary(e2.glmm.zi) glmmTMB:::Anova.glmmTMB(e2.glmm.zi,3) #No significant effects. Adding zero-inflation doesn't change anything. #Over-dispersed Poisson model e2.glmm.odp<-glmmTMB(flies~fabric+(1|day)+(1|site)+(1|rep), data=d2, family=poisson) summary(e2.glmm.odp) glmmTMB:::Anova.glmmTMB(e2.glmm.odp,3) #No significant effects AICtab(e2.glmm, e2.glmm.zi,e2.glmm.odp) #Over-dispersed Poisson and neg bin similar; ZI is worst. But all models similar. #EXPT 3 #With zero inflation... e3.glmm<-glmmTMB(flies~fabric+(1|day)+(1|site), ziformula=~1,data=d3, family=nbinom2) summary(e3.glmm) glmmTMB:::Anova.glmmTMB(e3.glmm,3) #No significant effects #Without zero inflation... e3.glmm.2<-glmmTMB(flies~fabric+(1|day)+(1|site), data=d3, family=nbinom2) summary(e3.glmm.2) glmmTMB:::Anova.glmmTMB(e3.glmm.2,3) #No significant effects #Zero-inflated over-dispersed Poisson e3.glmm.odp<-glmmTMB(flies~fabric+(1|day)+(1|site)+(1|rep), ziformula=~1,data=d3, family=poisson) summary(e3.glmm.odp) glmmTMB:::Anova.glmmTMB(e3.glmm.odp,3) #No significant effects #Zero-inflated Poisson (no ZI) e3.glmm.odp.nzi<-glmmTMB(flies~fabric+(1|day)+(1|site)+(1|rep), data=d3, family=poisson) summary(e3.glmm.odp) glmmTMB:::Anova.glmmTMB(e3.glmm.odp,3) #No significant effects AICtab(e3.glmm, e3.glmm.2,e3.glmm.odp, e3.glmm.odp.nzi) #All models are similar by AIC.