labs(x="Degree day accumulation", y="Partial residual captures")+
theme_classic()+ theme(legend.position = "none")
withinyear.dd
withinyear.rain<-visreg(gam_lb, "rain.days", "SPID", partial=FALSE, rug=FALSE,
overlay=TRUE, scale="response", gg=TRUE, line=list(lty=1))+
scale_fill_manual(values=alpha(c("darkred", "darkorange"), 0.4), labels=c("C7", "HA"), name="Species")+
scale_color_manual(values=c("darkred", "darkorange"), labels=c("C7", "HA"), name="Species")+
labs(x="Rainy days per week", y="Partial residual captures")+
theme_classic()+ theme(legend.position = "none")
withinyear.rain
withinyear.habitat<-visreg(gam_lb, "HABITAT","SPID", partial=FALSE, rug=FALSE,
overlay=TRUE, scale="response", gg=TRUE,
line=list(lty=1))+
scale_fill_manual(values=alpha(c("darkred", "darkorange"), 0.4), labels=c("C7", "HA"), name="Species")+
scale_color_manual(values=c("darkred", "darkorange"), labels=c("C7", "HA"), name="Species")+
labs(x="Habitat", y="Partial residual captures")+
theme_classic()+ theme(legend.position = "none", axis.text.x=element_text(angle=90))
withinyear.habitat
withinyear.yearly<-visreg(gam_lb, "year", "SPID", partial=FALSE, rug=FALSE,
overlay=TRUE, scale="response", gg=TRUE,
line=list(lty=1))+
scale_fill_manual(values=alpha(c("darkred", "darkorange"), 0.4), labels=c("C7", "HA"), name="Species")+
scale_color_manual(values=c("darkred", "darkorange"), labels=c("C7", "HA"), name="Species")+
labs(x="Year\n\n\n", y="Partial residual captures")+
theme_classic()
withinyear.yearly
#plot the withinyear model all together:
withinyear.modelplot<-plot_grid(withinyear.dd, withinyear.rain, withinyear.habitat, withinyear.yearly,
ncol=2, rel_widths=c(1, 1), labels=c('A', 'B', 'C', 'D'))
withinyear.modelplot
withinyear.dd<-visreg(gam_lb, "yearly.dd.accum", by="SPID", partial=FALSE, rug=FALSE,
overlay=TRUE, scale="response", gg=TRUE,
line=list(lty=1))+
scale_fill_manual(values=alpha(c("darkred", "darkorange"), 0.4), labels=c("C7", "HA"), name="Species")+
scale_color_manual(values=c("darkred", "darkorange"), labels=c("C7", "HA"), name="Species")+
labs(x="Degree day accumulation", y="Partial residual captures")+
theme_classic()+ theme(legend.position = "none")
withinyear.dd
withinyear.rain<-visreg(gam_lb, "rain.days", "SPID", partial=FALSE, rug=FALSE,
overlay=TRUE, scale="response", gg=TRUE, line=list(lty=1))+
scale_fill_manual(values=alpha(c("darkred", "darkorange"), 0.4), labels=c("C7", "HA"), name="Species")+
scale_color_manual(values=c("darkred", "darkorange"), labels=c("C7", "HA"), name="Species")+
labs(x="Rainy days per week", y="Partial residual captures")+
theme_classic()+ theme(legend.position = "none")
withinyear.rain
withinyear.habitat<-visreg(gam_lb, "HABITAT","SPID", partial=FALSE, rug=FALSE,
overlay=TRUE, scale="response", gg=TRUE,
line=list(lty=1))+
scale_fill_manual(values=alpha(c("darkred", "darkorange"), 0.4), labels=c("C7", "HA"), name="Species")+
scale_color_manual(values=c("darkred", "darkorange"), labels=c("C7", "HA"), name="Species")+
labs(x="Habitat", y="Partial residual captures")+
theme_classic()+ theme(legend.position = "none", axis.text.x=element_text(angle=90), hjust=0)
withinyear.habitat
withinyear.yearly<-visreg(gam_lb, "year", "SPID", partial=FALSE, rug=FALSE,
overlay=TRUE, scale="response", gg=TRUE,
line=list(lty=1))+
scale_fill_manual(values=alpha(c("darkred", "darkorange"), 0.4), labels=c("C7", "HA"), name="Species")+
scale_color_manual(values=c("darkred", "darkorange"), labels=c("C7", "HA"), name="Species")+
labs(x="Year\n\n\n", y="Partial residual captures")+
theme_classic()
withinyear.yearly
#plot the withinyear model all together:
withinyear.modelplot<-plot_grid(withinyear.dd, withinyear.rain, withinyear.habitat, withinyear.yearly,
ncol=2, rel_widths=c(1, 1), labels=c('A', 'B', 'C', 'D'))
withinyear.modelplot
withinyear.habitat<-visreg(gam_lb, "HABITAT","SPID", partial=FALSE, rug=FALSE,
overlay=TRUE, scale="response", gg=TRUE,
line=list(lty=1))+
scale_fill_manual(values=alpha(c("darkred", "darkorange"), 0.4), labels=c("C7", "HA"), name="Species")+
scale_color_manual(values=c("darkred", "darkorange"), labels=c("C7", "HA"), name="Species")+
labs(x="Habitat", y="Partial residual captures")+
theme_classic()+ theme(legend.position = "none", axis.text.x=element_text(angle=90), hjust=1)
withinyear.habitat
withinyear.habitat<-visreg(gam_lb, "HABITAT","SPID", partial=FALSE, rug=FALSE,
overlay=TRUE, scale="response", gg=TRUE,
line=list(lty=1))+
scale_fill_manual(values=alpha(c("darkred", "darkorange"), 0.4), labels=c("C7", "HA"), name="Species")+
scale_color_manual(values=c("darkred", "darkorange"), labels=c("C7", "HA"), name="Species")+
labs(x="Habitat", y="Partial residual captures")+
theme_classic()+ theme(legend.position = "none", axis.text.x=element_text(angle=90, hjust=1))
withinyear.habitat
withinyear.habitat<-visreg(gam_lb, "HABITAT","SPID", partial=FALSE, rug=FALSE,
overlay=TRUE, scale="response", gg=TRUE,
line=list(lty=1))+
scale_fill_manual(values=alpha(c("darkred", "darkorange"), 0.4), labels=c("C7", "HA"), name="Species")+
scale_color_manual(values=c("darkred", "darkorange"), labels=c("C7", "HA"), name="Species")+
labs(x="Habitat", y="Partial residual captures")+
theme_classic()+ theme(legend.position = "none", axis.text.x=element_text(angle=90, hjust=0))
withinyear.habitat
withinyear.habitat<-visreg(gam_lb, "HABITAT","SPID", partial=FALSE, rug=FALSE,
overlay=TRUE, scale="response", gg=TRUE,
line=list(lty=1))+
scale_fill_manual(values=alpha(c("darkred", "darkorange"), 0.4), labels=c("C7", "HA"), name="Species")+
scale_color_manual(values=c("darkred", "darkorange"), labels=c("C7", "HA"), name="Species")+
labs(x="Habitat", y="Partial residual captures")+
theme_classic()+ theme(legend.position = "none", axis.text.x=element_text(angle=90, vjust=0))
withinyear.habitat
withinyear.habitat<-visreg(gam_lb, "HABITAT","SPID", partial=FALSE, rug=FALSE,
overlay=TRUE, scale="response", gg=TRUE,
line=list(lty=1))+
scale_fill_manual(values=alpha(c("darkred", "darkorange"), 0.4), labels=c("C7", "HA"), name="Species")+
scale_color_manual(values=c("darkred", "darkorange"), labels=c("C7", "HA"), name="Species")+
labs(x="Habitat", y="Partial residual captures")+
theme_classic()+ theme(legend.position = "none", axis.text.x=element_text(angle=90, vjust=0.5))
withinyear.habitat
withinyear.habitat<-visreg(gam_lb, "HABITAT","SPID", partial=FALSE, rug=FALSE,
overlay=TRUE, scale="response", gg=TRUE,
line=list(lty=1))+
scale_fill_manual(values=alpha(c("darkred", "darkorange"), 0.4), labels=c("C7", "HA"), name="Species")+
scale_color_manual(values=c("darkred", "darkorange"), labels=c("C7", "HA"), name="Species")+
labs(x="Habitat", y="Partial residual captures")+
theme_classic()+ theme(legend.position = "none", axis.text.x=element_text(angle=90, vjust=0.5, hjust=0))
withinyear.habitat
withinyear.habitat<-visreg(gam_lb, "HABITAT","SPID", partial=FALSE, rug=FALSE,
overlay=TRUE, scale="response", gg=TRUE,
line=list(lty=1))+
scale_fill_manual(values=alpha(c("darkred", "darkorange"), 0.4), labels=c("C7", "HA"), name="Species")+
scale_color_manual(values=c("darkred", "darkorange"), labels=c("C7", "HA"), name="Species")+
labs(x="Habitat", y="Partial residual captures")+
theme_classic()+ theme(legend.position = "none", axis.text.x=element_text(angle=90, vjust=0.5, hjust=1))
withinyear.habitat
withinyear.dd<-visreg(gam_lb, "yearly.dd.accum", by="SPID", partial=FALSE, rug=FALSE,
overlay=TRUE, scale="response", gg=TRUE,
line=list(lty=1))+
scale_fill_manual(values=alpha(c("darkred", "darkorange"), 0.4), labels=c("C7", "HA"), name="Species")+
scale_color_manual(values=c("darkred", "darkorange"), labels=c("C7", "HA"), name="Species")+
labs(x="Degree day accumulation", y="Partial residual captures")+
theme_classic()+ theme(legend.position = "none")
withinyear.dd
withinyear.rain<-visreg(gam_lb, "rain.days", "SPID", partial=FALSE, rug=FALSE,
overlay=TRUE, scale="response", gg=TRUE, line=list(lty=1))+
scale_fill_manual(values=alpha(c("darkred", "darkorange"), 0.4), labels=c("C7", "HA"), name="Species")+
scale_color_manual(values=c("darkred", "darkorange"), labels=c("C7", "HA"), name="Species")+
labs(x="Rainy days per week", y="Partial residual captures")+
theme_classic()+ theme(legend.position = "none")
withinyear.rain
withinyear.habitat<-visreg(gam_lb, "HABITAT","SPID", partial=FALSE, rug=FALSE,
overlay=TRUE, scale="response", gg=TRUE,
line=list(lty=1))+
scale_fill_manual(values=alpha(c("darkred", "darkorange"), 0.4), labels=c("C7", "HA"), name="Species")+
scale_color_manual(values=c("darkred", "darkorange"), labels=c("C7", "HA"), name="Species")+
labs(x="Habitat", y="Partial residual captures")+
theme_classic()+ theme(legend.position = "none", axis.text.x=element_text(angle=90, vjust=0.5, hjust=1))
withinyear.habitat
withinyear.yearly<-visreg(gam_lb, "year", "SPID", partial=FALSE, rug=FALSE,
overlay=TRUE, scale="response", gg=TRUE,
line=list(lty=1))+
scale_fill_manual(values=alpha(c("darkred", "darkorange"), 0.4), labels=c("C7", "HA"), name="Species")+
scale_color_manual(values=c("darkred", "darkorange"), labels=c("C7", "HA"), name="Species")+
labs(x="Year\n\n\n", y="Partial residual captures")+
theme_classic()
withinyear.yearly
#plot the withinyear model all together:
withinyear.modelplot<-plot_grid(withinyear.dd, withinyear.rain, withinyear.habitat, withinyear.yearly,
ncol=2, rel_widths=c(1, 1), labels=c('A', 'B', 'C', 'D'))
withinyear.modelplot
withinyear.plot<-plot_grid(partresid, withinyear.modelplot, ncol=2, rel_widths = c(1,8))
withinyear.plot
partresid<-text_grob(paste("Partial residual captures"), color="black", size=11, rot=90)
withinyear.dd<-visreg(gam_lb, "yearly.dd.accum", by="SPID", partial=FALSE, rug=FALSE,
overlay=TRUE, scale="response", gg=TRUE,
line=list(lty=1))+
scale_fill_manual(values=alpha(c("darkred", "darkorange"), 0.4), labels=c("C7", "HA"), name="Species")+
scale_color_manual(values=c("darkred", "darkorange"), labels=c("C7", "HA"), name="Species")+
labs(x="Degree day accumulation", y=NULL)+
theme_classic()+ theme(legend.position = "none")
withinyear.dd
withinyear.rain<-visreg(gam_lb, "rain.days", "SPID", partial=FALSE, rug=FALSE,
overlay=TRUE, scale="response", gg=TRUE, line=list(lty=1))+
scale_fill_manual(values=alpha(c("darkred", "darkorange"), 0.4), labels=c("C7", "HA"), name="Species")+
scale_color_manual(values=c("darkred", "darkorange"), labels=c("C7", "HA"), name="Species")+
labs(x="Rainy days per week", y=NULL)+
theme_classic()+ theme(legend.position = "none")
withinyear.rain
withinyear.habitat<-visreg(gam_lb, "HABITAT","SPID", partial=FALSE, rug=FALSE,
overlay=TRUE, scale="response", gg=TRUE,
line=list(lty=1))+
scale_fill_manual(values=alpha(c("darkred", "darkorange"), 0.4), labels=c("C7", "HA"), name="Species")+
scale_color_manual(values=c("darkred", "darkorange"), labels=c("C7", "HA"), name="Species")+
labs(x="Habitat", y=NULL)+
theme_classic()+ theme(legend.position = "none", axis.text.x=element_text(angle=90, vjust=0.5, hjust=1))
withinyear.habitat
withinyear.yearly<-visreg(gam_lb, "year", "SPID", partial=FALSE, rug=FALSE,
overlay=TRUE, scale="response", gg=TRUE,
line=list(lty=1))+
scale_fill_manual(values=alpha(c("darkred", "darkorange"), 0.4), labels=c("C7", "HA"), name="Species")+
scale_color_manual(values=c("darkred", "darkorange"), labels=c("C7", "HA"), name="Species")+
labs(x="Year\n\n\n", y=NULL)+
theme_classic()
withinyear.yearly
#plot the withinyear model all together:
withinyear.modelplot<-plot_grid(withinyear.dd, withinyear.rain, withinyear.habitat, withinyear.yearly,
ncol=2, rel_widths=c(1, 1), labels=c('A', 'B', 'C', 'D'))
withinyear.modelplot
#create overall y axis label
partresid<-text_grob(paste("Partial residual captures"), color="black", size=11, rot=90)
#now replot with grob label
withinyear.plot<-plot_grid(partresid, withinyear.modelplot, ncol=2, rel_widths = c(1,8))
withinyear.plot
library(ggpubr)
partresid<-text_grob(paste("Partial residual captures"), color="black", size=11, rot=90)
withinyear.plot<-plot_grid(partresid, withinyear.modelplot, ncol=2, rel_widths = c(1,8))
withinyear.plot
withinyear.modelplot<-plot_grid(withinyear.dd, withinyear.rain, withinyear.habitat, withinyear.yearly,
ncol=2, rel_widths=c(1, 1), rel_heights = (0.9, 1), labels=c('A', 'B', 'C', 'D'))
withinyear.modelplot
#create overall y axis label
partresid<-text_grob(paste("Partial residual captures"), color="black", size=11, rot=90)
#now replot with grob label
withinyear.plot<-plot_grid(partresid, withinyear.modelplot, ncol=2, rel_widths = c(1,8))
withinyear.plot
withinyear.modelplot<-plot_grid(withinyear.dd, withinyear.rain, withinyear.habitat, withinyear.yearly,
ncol=2, rel_widths=c(1, 1), rel_heights = c(0.9, 1), labels=c('A', 'B', 'C', 'D'))
withinyear.modelplot
withinyear.modelplot<-plot_grid(withinyear.dd, withinyear.rain, withinyear.habitat, withinyear.yearly,
ncol=2, rel_widths=c(1, 1), rel_heights = c(0.85, 1), labels=c('A', 'B', 'C', 'D'))
withinyear.modelplot
#create overall y axis label
partresid<-text_grob(paste("Partial residual captures"), color="black", size=11, rot=90)
#now replot with grob label
withinyear.plot<-plot_grid(partresid, withinyear.modelplot, ncol=2, rel_widths = c(1,8))
withinyear.plot
#create overall y axis label
partresid<-text_grob(paste("     Partial residual captures"), color="black", size=12, rot=90)
#now replot with grob label
withinyear.plot<-plot_grid(partresid, withinyear.modelplot, ncol=2, rel_widths = c(1,9))
withinyear.plot
pdf("plots/figurewithinyear.gam.pdf", height=6, width=8)
withinyear.plot
dev.off()
pdf("plots/figurewithinyear.gam.pdf", height=7, width=8)
withinyear.plot
dev.off()
#let's visualize this!
withinyear.dd<-visreg(gam_lb, "yearly.dd.accum", by="SPID", partial=FALSE, rug=FALSE,
overlay=TRUE, scale="response", gg=TRUE,
line=list(lty=1))+
scale_fill_manual(values=alpha(c("darkred", "darkorange"), 0.4), labels=c("C7", "HA"), name="Species")+
scale_color_manual(values=c("darkred", "darkorange"), labels=c("C7", "HA"), name="Species")+
labs(x="Degree day accumulation", y="")+
theme_classic()+ theme(legend.position = "none")
withinyear.dd
withinyear.rain<-visreg(gam_lb, "rain.days", "SPID", partial=FALSE, rug=FALSE,
overlay=TRUE, scale="response", gg=TRUE, line=list(lty=1))+
scale_fill_manual(values=alpha(c("darkred", "darkorange"), 0.4), labels=c("C7", "HA"), name="Species")+
scale_color_manual(values=c("darkred", "darkorange"), labels=c("C7", "HA"), name="Species")+
labs(x="Rainy days per week", y="")+
theme_classic()+ theme(legend.position = "none")
withinyear.rain
withinyear.habitat<-visreg(gam_lb, "HABITAT","SPID", partial=FALSE, rug=FALSE,
overlay=TRUE, scale="response", gg=TRUE,
line=list(lty=1))+
scale_fill_manual(values=alpha(c("darkred", "darkorange"), 0.4), labels=c("C7", "HA"), name="Species")+
scale_color_manual(values=c("darkred", "darkorange"), labels=c("C7", "HA"), name="Species")+
labs(x="Habitat", y="")+
theme_classic()+ theme(legend.position = "none", axis.text.x=element_text(angle=90, vjust=0.5, hjust=1))
withinyear.habitat
withinyear.yearly<-visreg(gam_lb, "year", "SPID", partial=FALSE, rug=FALSE,
overlay=TRUE, scale="response", gg=TRUE,
line=list(lty=1))+
scale_fill_manual(values=alpha(c("darkred", "darkorange"), 0.4), labels=c("C7", "HA"), name="Species")+
scale_color_manual(values=c("darkred", "darkorange"), labels=c("C7", "HA"), name="Species")+
labs(x="Year\n\n\n", y="")+
theme_classic()
withinyear.yearly
#plot the withinyear model all together:
withinyear.modelplot<-plot_grid(withinyear.dd, withinyear.rain, withinyear.habitat, withinyear.yearly,
ncol=2, rel_widths=c(1, 1), rel_heights = c(0.85, 1), labels=c('A', 'B', 'C', 'D'))
withinyear.modelplot
#create overall y axis label
partresid<-text_grob(paste("     Partial residual captures"), color="black", size=12, rot=90)
#now replot with grob label
withinyear.plot<-plot_grid(partresid, withinyear.modelplot, ncol=2, rel_widths = c(1,9))
withinyear.plot
pdf("plots/figurewithinyear.gam.pdf", height=7, width=8)
withinyear.plot
dev.off()
#now replot with grob label
withinyear.plot<-plot_grid(partresid, withinyear.modelplot, ncol=2, rel_widths = c(1,10))
withinyear.plot
pdf("plots/figurewithinyeargam.pdf", height=6, width=8)
withinyear.plot
dev.off()
withinyear.plot<-plot_grid(partresid, withinyear.modelplot, ncol=2, rel_widths = c(1,11))
withinyear.plot
pdf("plots/figurewithinyeargam.pdf", height=5, width=8)
withinyear.plot
dev.off()
#we'll want to extract the data associated with activity peaks
#ok, I think we found the method we should use! here's the tutorial:
# https://fromthebottomoftheheap.net/2014/05/15/identifying-periods-of-change-with-gams/
#first we create a new dataframe that we can use our model to predict the values for
#create data for C7, holding everything constant but degree days
newData.C7 <- with(lb_all,
data.frame(yearly.dd.accum = seq(0, 1500, length = 300),
TRAPS=5,
year=mean(year),
rain.days=median(rain.days),
SPID="C7",
HABITAT="alfalfa"))
#make the same frame but for 1 more degday
newData.C7.1<- with(lb_all,
data.frame(yearly.dd.accum = seq(1, 1501, length = 300),
TRAPS=5,
year=mean(year),
rain.days=median(rain.days),
SPID="C7",
HABITAT="alfalfa"))
#make predictions
predict.dd.C7<-predict(gam_lb, newData.C7, type="link")
predict.dd.C7.1<-predict(gam_lb, newData.C7.1, type="link")
dd.C7.der<-as.data.frame(cbind(newData.C7$yearly.dd.accum, predict.dd.C7, predict.dd.C7.1))
dd.C7.der$slope<-(dd.C7.der$predict.dd.C7.1-dd.C7.der$predict.dd.C7)/1
#then let's do the same thing with harmonia
newData.HAXY <- with(lb_all,
data.frame(yearly.dd.accum = seq(0, 1500, length = 300),
TRAPS=5,
year=mean(year),
rain.days=median(rain.days),
SPID="HAXY",
HABITAT="alfalfa"))
#make the same frame but for 1 more degday
newData.HAXY.1<- with(lb_all,
data.frame(yearly.dd.accum = seq(1, 1501, length = 300),
TRAPS=5,
year=mean(year),
rain.days=median(rain.days),
SPID="HAXY",
HABITAT="alfalfa"))
#make predictions
predict.dd.HAXY<-predict(gam_lb, newData.HAXY, type="link")
predict.dd.HAXY.1<-predict(gam_lb, newData.HAXY.1, type="link")
dd.HAXY.der<-as.data.frame(cbind(newData.HAXY$yearly.dd.accum, predict.dd.HAXY, predict.dd.HAXY.1))
dd.HAXY.der$slope<-(dd.HAXY.der$predict.dd.HAXY.1-dd.HAXY.der$predict.dd.HAXY)/1
#Start of population growth dd.accum
#Peak population growth dd.accum
#other inflection points dd.accum
#look at the shape of the model for other environmental variables
#box plot of residuals by species and habitat
#now, what accounts for the year to-year variation in absolute numbers of both species?
#let's do another gam, but with the yearly aggregated data and the summary weather metrics
lb_yearly<-rename(lb_yearly, year=Year)
#also because we're looking for drivers, let's re-arrange the data so one beetle can
#be considered as a driver for the other
lb_yearly_1<-dcast(lb_yearly, year+REPLICATE+TREAT+HABITAT~SPID,
value.var ="SumOfADULTS",  sum)
lb_yearly_2<-merge(lb_yearly_1,unique(lb_yearly[,c(1:4,7)]), all.x=T)
lb_yearly_weather<-merge(lb_yearly_2, weather_yearly, all.x=T)
#another gam using this data aggregated by year but not by rep, and because the
#species seem to be responding to different factors, let's do one at a time
haxy.dd25<-visreg(gam_haxy_yearly, "dd25.dif", partial=FALSE, rug=FALSE,
overlay=TRUE, scale="response", gg=T, ylab="Residual captures",
xlab="Competitor captures", line=list(col="darkorange", lty=2),
fill=list(fill="tan1", alpha=0.5))+
theme_classic()
haxy.dd25
haxy.precip20<-visreg(gam_haxy_yearly, "precip20", partial=FALSE, rug=FALSE,
overlay=TRUE, scale="response", gg=T, ylab="Residual captures",
xlab="Competitor captures", line=list(col="darkorange", lty=2),
fill=list(fill="tan1", alpha=0.5))+
theme_classic()
haxy.precip20
haxy.precip35<-visreg(gam_haxy_yearly, "precip35.dif", partial=FALSE, rug=FALSE,
overlay=TRUE, scale="response", gg=T, ylab="Residual captures",
xlab="Competitor captures", line=list(col="darkorange", lty=2),
fill=list(fill="tan1", alpha=0.5))+
theme_classic()
haxy.precip35
gam_c7_yearly<-gam(C7~s(HAXY, sp=1, k=4)+
s(dd20, sp=1, k=4)+
#s(dd25.dif, sp=1, k=4)+
#s(dd30.dif, sp=1, k=4)+
s(dd35.dif, sp=1, k=4)+
#s(precip20, sp=1, k=4)+
s(precip25.dif, sp=1, k=4)+
#s(precip30.dif, sp=1, k=4)+
#s(precip35.dif, sp=1, k=4)+
HABITAT+
offset(log(TRAPS)), data=lb_yearly_weather, family="quasipoisson")
summary(gam_c7_yearly)
C7.precip25<-visreg(gam_c7_yearly, "precip25.dif", partial=FALSE, rug=FALSE,
overlay=TRUE, scale="response", gg=T, ylab="Residual captures",
xlab="Competitor captures",line=list(col="darkred", lty=4),
fill=list(fill="brown1", alpha=0.4))+
theme_classic()
C7.precip25
C7.precip25<-visreg(gam_c7_yearly, "precip25.dif", partial=FALSE, rug=FALSE,
overlay=TRUE, scale="response", gg=T, ylab="Residual captures",
xlab="Competitor captures",line=list(col="darkred", lty=4),
fill=list(fill="darkred", alpha=0.4))+
theme_classic()
C7.precip25
C7.precip25<-visreg(gam_c7_yearly, "precip25.dif", partial=FALSE, rug=FALSE,
overlay=TRUE, scale="response", gg=T, ylab="Residual captures",
xlab="Accumulated precipitation",line=list(col="darkred", lty=4),
fill=list(fill="darkred", alpha=0.4))+
theme_classic()
C7.precip25
gam_haxy_yearly<-gam(HAXY~s(C7, sp=1, k=4)+
#s(dd20, sp=1, k=4)+
s(dd25.dif, sp=1, k=4)+
s(dd30.dif, sp=1, k=4)+
#s(dd35.dif, sp=1, k=4)+
s(precip20, sp=1, k=4)+
#s(precip25.dif, sp=1, k=4)+
#s(precip30.dif, sp=1, k=4)+
s(precip35.dif, sp=1, k=4)+
HABITAT+
offset(log(TRAPS)), data=lb_yearly_weather, family="quasipoisson")
summary(gam_haxy_yearly)
#because the model has a lot of variables that are probably a bit autocorrelated,
#check concurvity to see if it needs simplification- aim to get observed >0.5 for all values
concurvity(gam_haxy_yearly)
#eliminate variables with least explanatory power (Lower F) from set with high concurvity
# start with precip25.dif,then dd20, then dd35.dif, then precip30.dif
haxy.c7.y<-visreg(gam_haxy_yearly, "C7", partial=FALSE, rug=FALSE,
overlay=TRUE, scale="response", gg=T, ylab="Residual captures",
xlab="Competitor captures", line=list(col="darkorange", lty=2),
fill=list(fill="darkorange", alpha=0.5))+
theme_classic()
haxy.c7.y
# visreg(gam_haxy_yearly, "dd20", partial=FALSE, rug=FALSE,
#        overlay=TRUE, scale="response")
haxy.dd25<-visreg(gam_haxy_yearly, "dd25.dif", partial=FALSE, rug=FALSE,
overlay=TRUE, scale="response", gg=T, ylab="Residual captures",
xlab="Degree day accumulation", line=list(col="darkorange", lty=2),
fill=list(fill="darkorange", alpha=0.5))+
theme_classic()
haxy.dd25
haxy.dd30<-visreg(gam_haxy_yearly, "dd30.dif", partial=FALSE, rug=FALSE,
overlay=TRUE, scale="response", gg=T, ylab="Residual captures",
xlab="Degree day accumulation", line=list(col="darkorange", lty=2),
fill=list(fill="darkorange", alpha=0.5))+
theme_classic()
haxy.dd30
# visreg(gam_haxy_yearly, "dd35.dif", partial=FALSE, rug=FALSE,
#        overlay=TRUE, scale="response")
haxy.precip20<-visreg(gam_haxy_yearly, "precip20", partial=FALSE, rug=FALSE,
overlay=TRUE, scale="response", gg=T, ylab="Residual captures",
xlab="Accumulated precipitation", line=list(col="darkorange", lty=2),
fill=list(fill="darkorange", alpha=0.5))+
theme_classic()
haxy.precip20
# visreg(gam_haxy_yearly, "precip25.dif", partial=FALSE, rug=FALSE,
#        overlay=TRUE, scale="response")
# visreg(gam_haxy_yearly, "precip30.dif", partial=FALSE, rug=FALSE,
#        overlay=TRUE)
haxy.precip35<-visreg(gam_haxy_yearly, "precip35.dif", partial=FALSE, rug=FALSE,
overlay=TRUE, scale="response", gg=T, ylab="Residual captures",
xlab="Competitor captures", line=list(col="darkorange", lty=2),
fill=list(fill="darkorange", alpha=0.5))+
theme_classic()
haxy.precip35
##### now C7
gam_c7_yearly<-gam(C7~s(HAXY, sp=1, k=4)+
s(dd20, sp=1, k=4)+
#s(dd25.dif, sp=1, k=4)+
#s(dd30.dif, sp=1, k=4)+
s(dd35.dif, sp=1, k=4)+
#s(precip20, sp=1, k=4)+
s(precip25.dif, sp=1, k=4)+
#s(precip30.dif, sp=1, k=4)+
#s(precip35.dif, sp=1, k=4)+
HABITAT+
offset(log(TRAPS)), data=lb_yearly_weather, family="quasipoisson")
summary(gam_c7_yearly)
#because the model has a lot of variables that are probably a bit autocorrelated,
#check concurvity to see if it needs simplification- aim to get observed >0.5 for all values
concurvity(gam_c7_yearly)
#eliminate variables with least explanatory power (Lower F) from set with high concurvity
# start with dd25.dif, dd30.dif, then precip20, precip30, precip35
C7.haxy.y<-visreg(gam_c7_yearly, "HAXY", partial=FALSE, rug=FALSE,
overlay=TRUE, scale="response", gg=T, ylab="Residual captures",
xlab="Competitor captures",line=list(col="darkred", lty=4),
fill=list(fill="darkred", alpha=0.4))+
theme_classic()
C7.haxy.y
C7.dd20<-visreg(gam_c7_yearly, "dd20", partial=FALSE, rug=FALSE,
overlay=TRUE, scale="response", gg=T, ylab="Residual captures",
xlab="Degree day accumulation",line=list(col="darkred", lty=4),
fill=list(fill="darkred", alpha=0.4))+
theme_classic()
C7.dd20
# visreg(gam_c7_yearly, "dd25.dif", partial=FALSE, rug=FALSE,
#        overlay=TRUE, scale="response")
#
# visreg(gam_c7_yearly, "dd30.dif", partial=FALSE, rug=FALSE,
#        overlay=TRUE, scale="response")
C7.dd35<-visreg(gam_c7_yearly, "dd35.dif", partial=FALSE, rug=FALSE,
overlay=TRUE, scale="response", gg=T, ylab="Residual captures",
xlab="Degree day accumulation",line=list(col="darkred", lty=4),
fill=list(fill="darkred", alpha=0.4))+
theme_classic()
C7.dd35
# visreg(gam_c7_yearly, "precip20", partial=FALSE, rug=FALSE,
#        overlay=TRUE, scale="response")
C7.precip25<-visreg(gam_c7_yearly, "precip25.dif", partial=FALSE, rug=FALSE,
overlay=TRUE, scale="response", gg=T, ylab="Residual captures",
xlab="Accumulated precipitation",line=list(col="darkred", lty=4),
fill=list(fill="darkred", alpha=0.4))+
theme_classic()
C7.precip25
# visreg(gam_c7_yearly, "precip30.dif", partial=FALSE, rug=FALSE,
#        overlay=TRUE)
# visreg(gam_c7_yearly, "precip35.dif", partial=FALSE, rug=FALSE,
#        overlay=TRUE)
haxy.c7.y<-visreg(gam_haxy_yearly, "C7", partial=FALSE, rug=FALSE,
overlay=TRUE, scale="response", gg=T, ylab="Residual captures",
xlab="Competitor captures", line=list(col="darkorange", lty=2),
fill=list(fill="darkorange", alpha=0.4))+
theme_classic()
haxy.c7.y
