library(lattice) library(mgcv) library(MuMIn) library(MASS) library(Cairo) library(boot) library(AICcmodavg) ## Create list of models, with each models' number (MBF1,MBF2...MBF31) representing each hypothesis in Table 1 of the paper. ### Use models that employ landscape data quantified at the 1000-m radius scale, as this produced best-fit models. Models created at other scales are also included in the R dataframe. ### Denotation "MBF" is "monthly binomial fawn". Other models for adult deer (eg winter binomial, WB1; monthly binomial, MB1) are also included in the R dataframe. deerfawn.1000.MBF = list(model.deer1000.MBF1, model.deer1000.MBF2, model.deer1000.MBF3, model.deer1000.MBF4, model.deer1000.MBF5, model.deer1000.MBF6, model.deer1000.MBF7, model.deer1000.MBF8, model.deer1000.MBF9, model.deer1000.MBF10, model.deer1000.MBF11, model.deer1000.MBF12, model.deer1000.MBF13, model.deer1000.MBF14, model.deer1000.MBF15, model.deer1000.MBF16, model.deer1000.MBF17, model.deer1000.MBF18, model.deer1000.MBF19, model.deer1000.MBF20, model.deer1000.MBF21, model.deer1000.MBF22, model.deer1000.MBF23, model.deer1000.MBF24, model.deer1000.MBF25, model.deer1000.MBF26, model.deer1000.MBF27, model.deer1000.MBF28, model.deer1000.MBF29, model.deer1000.MBF30, model.deer1000.MBF31) ###Create AIC table for model ranking aictab(deerfawn.1000.MBF, modnames = c("Model 1","Model 2","Model 3","Model 4","Model 5","Model 6","Model 7","Model 8","Model 9","Model 10","Model 11","Model 12","Model 13","Model 14","Model 15","Model 16","Model 17","Model 18","Model 19","Model 20","Model 21","Model 22","Model 23","Model 24","Model 25","Model 26","Model 27","Model 28","Model 29","Model 30","Model 31"), sort = TRUE) ########Model validation##### ### function for computing Deviance Explained from model summary (following Zuur 2010) Dsq <- function(x) ((summary(x)$null.deviance - summary(x)$deviance)/summary(x)$null.deviance)*100 ### adjusted D-squared, following Franklin's SDM book p121 aDsq <- function(x) (1-(summary(x)$df.null/summary(x)$df.residual)* (1-(summary(x)$null.deviance - summary(x)$deviance)/summary(x)$null.deviance))*100 Dsq(model.deer1000.MBF31) aDsq(model.deer1000.MBF31) ###10-fold cross validation from R package boot. model.deer1000.MBF31.10fold = cv.glm(data = deer1000, glmfit = model.deer1000.MBF31, K=10) model.deer1000.MBF31.10fold ######Code for creating the graphs of he best-fit model#### library(tidyverse) library(cowplot) model.deer1000.MBF31 coefficients(model.deer1000.MBF31) # PercentHab1 = Broadleaf Forest vis.broadleaf <- visreg(model.deer1000.MQF31, "PercentHab1", scale = "response", ylim = c(0,0.6), gg=T) + theme_bw() + xlab("Percent Area Broadleaf Forest") + ylab("Fawn Occurrence") vis.3d <- visreg(model.deer1000.MQF32, "Percent3D", scale = "response", ylim = c(0,0.6), gg=T) + theme_bw() + xlab("Percent Area 3D Seismic Lines") + ylab("Fawn Occurrence") vis.seis_line <- visreg(model.deer1000.MQF31, "PercentCutline", scale = "response", ylim = c(0,0.6), gg=T) + theme_bw() + xlab("Percent Area Seismic Lines") + ylab("Fawn Occurrence") vis.pipelines <- visreg(model.deer1000.MQF31, "PercentPipeline.x", scale = "response", ylim = c(0,0.6), gg=T) + theme_bw() + xlab("Percent Area Pipelines") + ylab("Fawn Occurrence") visreg_plot <- plot_grid(vis.seis_line, vis.3d, vis.broadleaf, vis.pipelines, nrow = 2) # plot_grid from cowplot is nice for arrangng plots ggsave("modelMQF31_prediction_plot_cairo.jpeg", visreg_plot, dpi = 600, width = 10, height = 8, type = "cairo") ###END###