install.packages("mgcv") install.packages("readxl") install.packages("MuMIn") install.packages("openxlsx") library(mgcv) library(readxl) library(MuMIn) library(openxlsx) resamp <- read_excel("C:/Users/jcarvalho/Downloads/GAM10k.xlsx") options(na.action = "na.fail") #prevent fitting models to different datasets RSG <- gam(Presence ~ Date * ID + s(SPL3) + s(Fish) + s(Anthropogenic) + te(Gdepth, Sal) + te(Gdepth, Temp) + s(Depth) + s(CurrentS) + s(CurrentH) + s(Distance) + s(Chla), family = Tweedie(p = 1.1, link = power(0)), data = resamp, method = "REML") summary(RSG) RSGA <- dredge(RSG) # Write the result to an Excel file write.xlsx(RSGA, "RSGA.xlsx") resamp$DateNumeric <- as.numeric(resamp$Date) RSGT <- gam(Presence ~ te(DateNumeric, ID) + s(SPL3) + s(Fish) + s(Anthropogenic) + s(Sal) + te(Gdepth, Temp) + s(Depth) + s(CurrentS) + s(CurrentH) + s(Distance) + s(Chla), family = Tweedie(p = 1.1, link = power(0)), data = resamp, method = "REML") summary(RSGT) RSGA2 <- dredge(RSGT) # Write the result to an Excel file write.xlsx(RSGA2, "RSGT.xlsx") RSGT <- gam(Presence ~ te(DateNumeric, ID) + s(SPL3) + s(Fish) + s(Anthropogenic) + s(Sal) + s(Temp) + s(Depth) + s(CurrentS) + s(CurrentH) + s(Distance) + s(Chla), family = Tweedie(p = 1.1, link = power(0)), data = resamp, method = "REML") summary(RSGT) RSGA2 <- dredge(RSGT) # Write the result to an Excel file write.xlsx(RSGA2, "RSGTest.xlsx") resamp$DateNumeric <- as.numeric(resamp$Date) RSGTNS <- gam(Presence ~ te(DateNumeric, ID) + s(Sal) + s(Temp) + s(Depth) + s(CurrentS) + s(CurrentH) + s(Distance) + s(Chla), family = Tweedie(p = 1.1, link = power(0)), data = resamp, method = "REML") summary(RSGTNS) RSGANS <- dredge(RSGTNS) # Write the result to an Excel file write.xlsx(RSGANS, "RSGTNStest.xlsx") #satellite models RSS <- gam(Presence ~ Date * ID + s(SatSal) + s(SST) + s(Depth) + s(SatSpeed) + s(SatHeading) + s(Distance) + s(Satchla), family = Tweedie(p = 1.1, link = power(0)), data = resamp, method = "REML") summary(RSS) RSSA <- dredge(RSS) # Write the result to an Excel file write.xlsx(RSSA, "RSSA.xlsx") resampsat$DateNumeric <- as.numeric(resampsat$Date) RSST <- gam(Presence ~ te(DateNumeric, ID) + s(SatSal) + s(SST) + s(Depth) + s(SatSpeed) + s(SatHeading) + s(Distance) + s(Satchla), family = Tweedie(p = 1.1, link = power(0)), data = resamp, method = "REML") summary(RSST) RSSA2 <- dredge(RSST) # Write the result to an Excel file write.xlsx(RSSA2, "RSST.xlsx") ##Top three glider RSGT1 <- gam(Presence ~ te(DateNumeric, ID) + s(SPL3) + s(Temp) + s(Chla), family = Tweedie(p = 1.1, link = power(0)), data = resamp, method = "REML") summary(RSGT1) AICc(RSGT1) plot(RSGT1, scale = 0) RSGT2 <- gam(Presence ~ te(DateNumeric, ID) + s(SPL3) + s(Temp) + s(CurrentS) +s(Chla), family = Tweedie(p = 1.1, link = power(0)), data = resamp, method = "REML") summary(RSGT2) AICc(RSGT2) RSGT3 <- gam(Presence ~ te(DateNumeric, ID) + s(SPL3) + s(Temp) + s(Depth) + s(Chla), family = Tweedie(p = 1.1, link = power(0)), data = resamp, method = "REML") summary(RSGT3) AICc(RSGT3) ##Top three sat resampsat$DateNumeric <- as.numeric(resampsat$Date) RSST1 <- gam(Presence ~ te(DateNumeric, ID) + s(SatSpeed) + s(SatHeading) + s(Satchla), family = Tweedie(p = 1.1, link = power(0)), data = resamp, method = "REML") summary(RSST1) AICc(RSST1) plot(RSST1, scheme=2, scale = 0) plot(RSST1, scale = 0) RSST2 <- gam(Presence ~ s(SatSal) + s(SST) + s(Depth) + s(SatSpeed) + s(SatHeading) + s(Satchla), family = Tweedie(p = 1.1, link = power(0)), data = resamp, method = "REML") summary(RSST2) AICc(RSST2) RSST3 <- gam(Presence ~ te(DateNumeric, ID) + s(SatSpeed) + s(SatHeading) + s(Satchla) + s(SST), family = Tweedie(p = 1.1, link = power(0)), data = resamp, method = "REML") summary(RSST3) AICc(RSST3) #top three no sound resamp$DateNumeric <- as.numeric(resamp$Date) RSGTNS1 <- gam(Presence ~ te(DateNumeric, ID) + s(Temp) + s(Chla), family = Tweedie(p = 1.1, link = power(0)), data = resamp, method = "REML") summary(RSGTNS1) AICc(RSGTNS1) RSGTNS2 <- gam(Presence ~ te(DateNumeric, ID) + s(Temp) + s(Depth) + s(CurrentS) + s(CurrentH) + s(Chla), family = Tweedie(p = 1.1, link = power(0)), data = resamp, method = "REML") summary(RSGTNS2) AICc(RSGTNS2) RSGTNS3 <- gam(Presence ~ te(DateNumeric, ID) + s(Temp) + s(CurrentS) + s(Chla), family = Tweedie(p = 1.1, link = power(0)), data = resamp, method = "REML") summary(RSGTNS3) AICc(RSGTNS3) RSGT1 <- gam(Presence ~ te(DateNumeric, ID) + s(Depth) + s(SST) + s(SatSpeed) + s(Satchla), family = Tweedie(p = 1.1, link = power(0)), data = resamp, method = "REML") summary(RSGT1) AICc(RSGT1) plot(RSGT1, shade = T, scale = 0)