--- title: "Revised analysis in response to second set of PeerJ reviewer comments" author: "A. Hauger and G. Roloff; Sep 9" output: html_document --- ```{r, Packages, include = FALSE, message = FALSE} if (!require('lme4')) install.packages('lme4'); library('lme4') if (!require('ggplot2')) install.packages('ggplot2'); library('ggplot2') if (!require('regclass')) install.packages('regclass'); library('regclass') ``` ```{r, setup, message = FALSE, warning = FALSE} setwd("~/PigeDNA/PeerJRevised.2") AllData2 <- read.csv("AllData2.csv", header = TRUE) summary(AllData2) AllData2$Stream <- as.factor(AllData2$Stream) AllData2$Season<-as.factor(AllData2$Season) AllData2$Temperature <-as.numeric(as.character(AllData2$Temperature)) AllData2$Distance<- as.numeric(AllData2$Distance) #Need to recode Distance so that the data are ordinal where 0 = 0m, # 1 = 100m, 2 = 200m, 3 = 300m and 4 = 400m. AllData2$DistanceRecode <- ifelse(AllData2$Distance==3,1, ifelse(AllData2$Distance==4,2, ifelse(AllData2$Distance==5,3, ifelse(AllData2$Distance==6,4,0)))) ``` ```{r, Global.Model} # Per recommendation of reviewer, removed Season as a factor. Global.Mod = glm(Detection ~ DistanceRecode + Velocity + Temperature + pH + Discharge + Turbidity + factor(Stream), data=AllData2, family=binomial(link='logit')) summary(Global.Mod) # Use variance inflation factor to identify predictors that may be more related # to other predictors than to the response variable. VIF > 5 are suspect. VIF(Global.Mod) # Remove discharge. Global.Mod2 = glm(Detection ~ DistanceRecode + Velocity + Temperature + pH + Turbidity + factor(Stream), data=AllData2, family=binomial(link='logit')) summary(Global.Mod2) VIF(Global.Mod2) # Remove pH. Global.Mod3 = glm(Detection ~ DistanceRecode + Velocity + Temperature + Turbidity + factor(Stream), data=AllData2, family=binomial(link='logit')) summary(Global.Mod3) VIF(Global.Mod3) ``` ```{r} # Is interaction between distance and velocity potentially important? DistVelTest <- glm(Detection ~ DistanceRecode * Velocity, data = AllData2, family = binomial(link='logit')) summary(DistVelTest) # The intercation does not appear to be important. ``` ```{r, ConfInt} round(confint(Global.Mod3),3) ``` ```{r, Plot, warning=FALSE} ggplot(AllData2, aes(Temperature , Detection)) + stat_smooth(method="glm", method.args = list(family = "binomial"), formula=y~x, alpha=0.3, size=2) + geom_point(position=position_jitter(height=0.03, width=0)) + xlab("Temperature (C)") + ylab("Detection Probability") + coord_cartesian(ylim=c(0,1)) + theme(panel.background = element_blank()) + theme(axis.line = element_line(colour = "black")) + ggtitle("") + theme(axis.text.x = element_text(family="serif", size=12), axis.title.x = element_text(family="serif", size=12), axis.text.y = element_text(family="serif", size=12), axis.title.y = element_text(family="serif", size=12)) + theme(axis.title.y = element_text(margin = ggplot2::margin(t = 0, r = 10, b = 0, l = 0))) + theme(axis.title.x = element_text(margin = ggplot2::margin(t = 10, r = 0, b = 0, l = 0))) ``` ```{r} # Predict detection probability for min and max recorded temps. TempPredict = predict(Global.Mod3, data.frame = AllData2, type = "response") TempPredict ```