setwd("/Users/ivangonzalez/Desktop/GREENLAND-R1/paper Groenlandia -R1") dir() data <- read.table("data.csv", header=TRUE, sep=";", row.names=1) library(vegan) ######################################## ##### Testing differences in Physical-chemical properties of freshwater between colonies and controls ######################################### data$birds<-as.factor(data$birds) str(data) head(data) #1) PERMANOVA MyVar <- c( "pH", "DO", "Cond", "TN", "NO","TP", "PO4", "Chla") env1<-(as.matrix(data[,MyVar])) ### good<-complete.cases(env1) tot <- data[good,]### y<-env1[good,]## str(tot) # str(y) head(y) ### mod<-adonis(decostand(y,"standardize") ~ birds, data=tot, permutations=999, method="euclidean") mod ### w ### this makes a plot to see the data more clearly mod <- rda(y, scale =TRUE)## plot(mod, type = "n") text(mod, display = "sites", , cex = 0.8, col = c("black","green")[tot$birds]) text(mod, display = "species", , cex = 0.8, col="red") with(data, legend("topright", legend = c("no birds","birds"), bty = "n", pch = 20, col = c("black","green"))) ### puts hulls around the groups ordihull(mod, group=tot$birds, show="0", col="black") ordihull(mod, group=tot$birds, show="1", col="green") ### now pairwise models with space included if needed . # as some data does not have homogeneity of variance #we use GLS then we can put space in too if needed. ################################################# ####ANOVAS for pH, DO,TN NO, PO3, PT, CHL ################################################# ### for pH op<-par(mfrow=c(2,1),mar=c(4,4,1,1)) plot(data$pH~data$birds) shapiro.test(residuals(aov(data$pH~data$birds))) ## suggests normality is acccomplished bartlett.test(data$pH~data$birds) ## means we have homogeneity of variance- ############################################################################ ## we try GlS anyway.. ##################################### library(nlme) testpH<-data[which(data$pH >0 ), ]### this I made to remove NAs pHmod<-gls(pH~birds, data=testpH) summary(pHmod) ### No need to add variance structure as there is homogeneity of variance # now check for spatial autocorrelation E<- resid(pHmod, type="normalized") ### get the residuals F<- fitted (pHmod) ## and the fittefd whilst we are at it plot(E~testpH$birds)## xyplot(n1 ~ e1, aspect = "iso", data = data, col= testpH$birds, pch=16) #Spatial independence, this plots residuals in the map, size of symbol is residual size and colour is plus or minus resdual MyCex <- abs(E) / max(abs(E)) MyCol <- E MyCol[E >= 0 ] <- 1 MyCol[E < 0 ] <- 2 xyplot(n1~ e1, cex = 4* MyCex, pch = 1, col = MyCol, data = testpH, main = "Spatial plot of residuals") ### there might be a pattern there .. str(data) plot(E~testpH$birds) ### this makes a variogram to look for spatial autocorrelation variopHmod<- Variogram(pHmod, form=~n1+e1, robust=TRUE, maxDist=100000, restype="normalized") plot(variopHmod) ## actually i does not look too bad but there is a hint of autocorrelation, so we'll put space in the model ## this model puts in a wieghting stricture to account for spatial autocorrelation so the significance test can be trusted. pHmodspace<-gls(pH~birds,correlation=corGaus(form=~n1+e1,nugget=TRUE), data=testpH) AIC(pHmod, pHmodspace) anova(pHmod, pHmodspace)## the model with space in improves summary(pHmodspace)### with space in, Bird colony is still massively sig. There are no R2 values for GLS, but we can compare observed vs predicted F1<-fitted(pHmodspace) cor(F1,testpH$pH)^2 ## 0.33 for the cor^2 value ## ANOVA including spatial autocorrelation pHanova<-aov(pH~birds, data=testpH) summary(pHanova) ## this model puts in a wieghting stricture to account for spatial autocorrelation so the significance test can be trusted. pHanovaspace<-gls(pH~birds,correlation=corGaus(form=~n1+e1,nugget=TRUE), data=testpH)##### AIC(pHanova, pHanovaspace) anova(pHmod, pHanovaspace)#### with space in the model improves summary(pHanovaspace)### F1<-fitted(pHanovaspace) cor(F1,testpH$pH)^2 ## 0.33 for the cor^2 value ###### There are significant differences with ANOVA with space included #### for conductivity op<-par(mfrow=c(2,1),mar=c(4,4,1,1)) plot(data$Cond~data$birds) shapiro.test(residuals(aov(data$Cond~data$birds))) ## suggests normality is NOT acccomplished bartlett.test(data$Cond~data$birds) ############################################################################ ## we try GlS ##################################### library(nlme) testcond<-data[which(data$Cond >0 ), ] condmod<-gls(Cond~birds, data=testcond) summary(condmod) ### Need to add variance structure as there is no homogeneity of variance vf1<- varIdent(form=~1|birds)### this code allows for a different variance stucture across the two groups condmod1<-gls(Cond~birds, weights = vf1, data=testcond) # with the variance structure in the mode summary(condmod1) anova(condmod,condmod1) # model with the variance structure in significant improvement AIC(condmod,condmod1) # now check for spatial autocorrelation E<- resid(condmod1, type="normalized") ### get the residuals F<- fitted (condmod1) ## and the fittefd whilst we are at it plot(E~testcond$birds)## xyplot(n1 ~ e1, aspect = "iso", data = data, col= testcond$birds, pch=16) MyCex <- abs(E) / max(abs(E)) MyCol <- E MyCol[E >= 0 ] <- 1 MyCol[E < 0 ] <- 2 xyplot(n1~ e1, cex = 4* MyCex, pch = 1, col = MyCol, data = testcond, main = "Spatial plot of residuals") ### there might be a pattern there .. str(data) plot(E~testpH$birds) ### this makes a variogram to look for spatial autocorrelation variocondmod<- Variogram(condmod1, form=~n1+e1, robust=TRUE, maxDist=100000, restype="normalized") plot(variocondmod) condmodspace<-gls(Cond~birds,weights = vf1, correlation=corGaus(form=~n1+e1,nugget=TRUE), data=testcond) AIC(condmod1, condmodspace) anova(condmod1, condmodspace)## summary(condmodspace)### #### for DO op<-par(mfrow=c(2,1),mar=c(4,4,1,1)) plot(data$DO~data$birds) shapiro.test(residuals(aov(data$DO~data$birds))) ## Normality is acccomplished bartlett.test(data$DO~data$birds) ##We have homogeneity of variance-- ############################################################################ ## we try GlS ##################################### library(nlme) testDO<-data[which(data$DO >0 ), ]### this I made to remove NAs DOmod<-gls(DO~birds, data=testDO) summary(DOmod) ### NO Need to add variance structure as there is no homogeneity of variance # now check for spatial autocorrelation E<- resid(DOmod, type="normalized") ### get the residuals F<- fitted (DOmod) ## and the fittefd whilst we are at it plot(E~testDO$birds)## xyplot(n1 ~ e1, aspect = "iso", data = data, col= testDO$birds, pch=16) #Spatial independence, MyCol <- E MyCol[E >= 0 ] <- 1 MyCol[E < 0 ] <- 2 xyplot(n1~ e1, cex = 4* MyCex, pch = 1, col = MyCol, data = testDO, main = "Spatial plot of residuals") ### there is no spatial autocorrelation here .. str(data) plot(E~testDO$birds) ### this makes a variogram to look for spatial autocorrelation varioDOmod<- Variogram(DOmod, form=~n1+e1, robust=TRUE, maxDist=100000, restype="normalized") plot(varioDOmod) ## looks good, no spatial autocorrelation DOmodspace<-gls(DO~birds, correlation=corGaus(form=~n1+e1,nugget=TRUE), data=testDO) AIC(DOmod, DOmodspace) anova(DOmod, DOmodspace)## summary(DOmodspace)### #### For Total Nitrogen op<-par(mfrow=c(2,1),mar=c(4,4,1,1)) plot(data$TN~data$birds) shapiro.test(residuals(aov(data$TN~data$birds))) ## Normality is NOT acccomplished bartlett.test(data$TN~data$birds) ##We have homogeneity of variance NOT accomplished-- ## we try GlS ##################################### library(nlme) testTN<-data[which(data$TN >0 ), ]### this I made to remove NAs TNmod<-gls(TN~birds, data=testTN) summary(TNmod) ### Need to add variance structure as there is no homogeneity of variance vf1<- varIdent(form=~1|birds)### this code allows for a different variance stucture across the two groups TNmod1<-gls(TN~birds, weights = vf1, data=testTN) # with the variance structure in the mode summary(TNmod1) anova(TNmod,TNmod1) # model with the variance structure in significant improvement AIC(TNmod,TNmod1) # now check for spatial autocorrelation E<- resid(TNmod1, type="normalized") ### get the residuals F<- fitted (TNmod1) ## and the fittefd whilst we are at it plot(E~testTN$birds)## #can we see spatial autocorrelation? xyplot(n1 ~ e1, aspect = "iso", data = data, col= testTN$birds, pch=16) MyCex <- abs(E) / max(abs(E)) MyCol <- E MyCol[E >= 0 ] <- 1 MyCol[E < 0 ] <- 2 xyplot(n1~ e1, cex = 4* MyCex, pch = 1, col = MyCol, data = testTN, main = "Spatial plot of residuals") ### there might be a pattern there .. str(data) plot(E~testTN$birds) ### this makes a variogram to look for spatial autocorrelation varioTNmod<- Variogram(TNmod1, form=~n1+e1, robust=TRUE, maxDist=100000, restype="normalized") plot(varioTNmod) ## looks good ## this model puts in a wieghting stricture to account for spatial autocorrelation so the significance test can be trusted. TNmodspace<-gls(TN~birds,weights = vf1, correlation=corGaus(form=~n1+e1,nugget=TRUE), data=testTN) AIC(TNmod1, TNmodspace) anova(TNmod1, TNmodspace)## summary(TNmodspace)### ###################################### ## for NO2+ NO3 op<-par(mfrow=c(2,1),mar=c(4,4,1,1)) plot(data$NO~data$birds) shapiro.test(residuals(aov(data$NO~data$birds))) ## Normality is NOT acccomplished bartlett.test(data$NO~data$birds) ## homogeneity of variance NOT accomplished-- ## we try GlS library(nlme) testNO<-data[which(data$NO >0 ), ]### this I made to remove NAs NOmod<-gls(NO~birds, data=testNO) summary(NOmod) ### Need to add variance structure as there is no homogeneity of variance vf1<- varIdent(form=~1|birds)### this code allows for a different variance stucture across the two groups NOmod1<-gls(NO~birds, weights = vf1, data=testNO) # with the variance structure in the mode summary(NOmod1) anova(NOmod,NOmod1) # model with the variance structure in significant improvement ##continue with model woth diffrent variance structure # now check for spatial autocorrelation E<- resid(NOmod1, type="normalized") ### get the residuals F<- fitted (NOmod1) ## and the fittefd whilst we are at it plot(E~testNO$birds)## xyplot(n1 ~ e1, aspect = "iso", data = data, col= testNO$birds, pch=16) #Spatial independence, MyCol <- E MyCol[E >= 0 ] <- 1 MyCol[E < 0 ] <- 2 xyplot(n1~ e1, cex = 4* MyCex, pch = 1, col = MyCol, data = testNO, main = "Spatial plot of residuals") ### does not seem to be any pattern here .. str(data) plot(E~testNO$birds) ### this makes a variogram to look for spatial autocorrelation varioNOmod<- Variogram(NOmod1, form=~n1+e1, robust=TRUE, maxDist=100000, restype="normalized") plot(varioNOmod) ## looks good ## this model puts in a wieghting stricture to account for spatial autocorrelation so the significance test can be trusted. NOmodspace<-gls(NO~birds,weights = vf1, correlation=corGaus(form=~n1+e1,nugget=TRUE), data=testNO) AIC(NOmod1, NOmodspace) anova(NOmod1, NOmodspace)## summary(NOmodspace)### ###################################### ## for TP op<-par(mfrow=c(2,1),mar=c(4,4,1,1)) plot(data$TP~data$birds) shapiro.test(residuals(aov(data$TP~data$birds))) ## Normality is NOT acccomplished bartlett.test(data$TP~data$birds) ## homogeneity of variance NOT accomplished-- ## we try GlS library(nlme) testTP<-data[which(data$TP >0 ), ]# TPmod<-gls(TP~birds, data=testTP) summary(TPmod) vf1<- varIdent(form=~1|birds)### TPmod1<-gls(TP~birds, weights = vf1, data=testTP) # summary(TPmod1) anova(TPmod,TPmod1) # # now check for spatial autocorrelation E<- resid(TPmod1, type="normalized") ### get the residuals F<- fitted (TPmod1) ## and the fittefd whilst we are at it plot(E~testNO$birds)## #can we see spatial autocorrelation? xyplot(n1 ~ e1, aspect = "iso", data = testTP, col= testTP$birds, pch=16) MyCex <- abs(E) / max(abs(E)) MyCol <- E MyCol[E >= 0 ] <- 1 MyCol[E < 0 ] <- 2 xyplot(n1~ e1, cex = 4* MyCex, pch = 1, col = MyCol, data = testTP, main = "Spatial plot of residuals") str(data) plot(E~testTP$birds) varioTPmod<- Variogram(TPmod1, form=~n1+e1, robust=TRUE, maxDist=100000, restype="normalized") plot(varioTPmod) TPmodspace<-gls(TP~birds,weights = vf1, correlation=corGaus(form=~n1+e1,nugget=TRUE), data=testTP) AIC(TPmod1, TPmodspace) anova(TPmod1, TPmodspace)## summary(TPmodspace)### ###################################### ## for PO4 op<-par(mfrow=c(2,1),mar=c(4,4,1,1)) plot(data$PO4~data$birds) shapiro.test(residuals(aov(data$PO4~data$birds))) ## Normality is NOT acccomplished bartlett.test(data$PO4~data$birds) ## homogeneity of variance NOT accomplished-- ## we try GlS library(nlme) testPO4<-data[which(data$PO4 >0 ), ]### this I made to remove NAs PO4mod<-gls(PO4~birds, data=testPO4) summary(PO4mod) ### Need to add variance structure as there is no homogeneity of variance vf1<- varIdent(form=~1|birds)### this code allows for a different variance stucture across the two groups PO4mod1<-gls(PO4~birds, weights = vf1, data=testPO4) # with the variance structure in the mode summary(PO4mod1) anova(PO4mod,PO4mod1) # model with the variance structure in significant improvement ##continue with model woth diffrent variance structure # now check for spatial autocorrelation E<- resid(PO4mod1, type="normalized") ### get the residuals F<- fitted (PO4mod1) ## and the fittefd whilst we are at it plot(E~testNO$birds)## xyplot(n1 ~ e1, aspect = "iso", data = testPO4, col= testPO4$birds, pch=16) MyCex <- abs(E) / max(abs(E)) MyCol <- E MyCol[E >= 0 ] <- 1 MyCol[E < 0 ] <- 2 xyplot(n1~ e1, cex = 4* MyCex, pch = 1, col = MyCol, data = testPO4, main = "Spatial plot of residuals") str(data) plot(E~testPO4$birds) varioPO4mod<- Variogram(PO4mod1, form=~n1+e1, robust=TRUE, maxDist=100000, restype="normalized") plot(varioPO4mod) PO4modspace<-gls(PO4~birds,weights = vf1, correlation=corGaus(form=~n1+e1,nugget=TRUE), data=testPO4) AIC(PO4mod1, PO4modspace) anova(PO4mod1, PO4modspace)##adding space does improve the model summary(PO4modspace)### with space in, Bird colony does not affect ###################################### ## for richness of taxa op<-par(mfrow=c(2,1),mar=c(4,4,1,1)) plot(data$Consumer.taxa.diversity~data$birds) shapiro.test(residuals(aov(data$Consumer.taxa.diversity~data$birds))) ## Normality is NOT acccomplished bartlett.test(data$Consumer.taxa.diversity~data$birds) ## homogeneity of variance NOT accomplished-- library(nlme) testrich<-data[which(data$Consumer.taxa.diversity >-1 ), ]### richmod<-gls(Consumer.taxa.diversity~birds, data=testrich) summary(richmod) vf1<- varIdent(form=~1|birds)### richmod1<-gls(Consumer.taxa.diversity~birds, weights = vf1, data=testrich) # summary(richmod1) anova(richmod,richmod1) # E<- resid(richmod1, type="normalized") ### F<- fitted (richmod1) ## plot(E~testrich$birds)## xyplot(n1 ~ e1, aspect = "iso", data = testrich, col= testrich$birds, pch=16) MyCex <- abs(E) / max(abs(E)) MyCol <- E MyCol[E >= 0 ] <- 1 MyCol[E < 0 ] <- 2 xyplot(n1~ e1, cex = 4* MyCex, pch = 1, col = MyCol, data = testrich, main = "Spatial plot of residuals") str(data) plot(E~testrich$birds) variorichmod<- Variogram(richmod1, form=~n1+e1, robust=TRUE, maxDist=100000, restype="normalized") plot(variorichmod) richmodspace<-gls(Consumer.taxa.diversity~birds,weights = vf1, correlation=corGaus(form=~n1+e1,nugget=TRUE), data=testrich) AIC(richmod1, richmodspace) anova(richmod1, richmodspace)##adding space does improve the model summary(richmodspace)### with space in, Bird colony does not affect summary(richmod1) ##for EVI op<-par(mfrow=c(2,1),mar=c(4,4,1,1)) plot(data$EVI.500.max~data$birds) shapiro.test(residuals(aov(data$EVI.500.max~data$birds))) ## Normality is acccomplished bartlett.test(data$EVI.500.max~data$birds) ##We have homogeneity of variance-- ## we try GlS ##################################### library(nlme) EVImod<-gls(EVI.500.max~birds, data=data) summary(EVImod) ### NO Need to add variance structure as there is no homogeneity of variance # now check for spatial autocorrelation E<- resid(EVImod, type="normalized") ### get the residuals F<- fitted (EVImod) ## and the fittefd whilst we are at it plot(E~data$birds)## #can we see spatial autocorrelation? xyplot(n1 ~ e1, aspect = "iso", data = data, col= data$birds, pch=16) MyCex <- abs(E) / max(abs(E)) MyCol <- E MyCol[E >= 0 ] <- 1 MyCol[E < 0 ] <- 2 xyplot(n1~ e1, cex = 4* MyCex, pch = 1, col = MyCol, data = data, main = "Spatial plot of residuals") str(data) plot(E~data$birds) looks fine.. varioEVImod<- Variogram(EVImod, form=~n1+e1, robust=TRUE, maxDist=100000, restype="normalized") plot(varioEVImod) EVImodspace<-gls(EVI.500.max~birds, correlation=corGaus(form=~n1+e1,nugget=TRUE), data=data) AIC(EVImod, EVImodspace) anova(EVImod, EVImodspace)## adding space improves the model summary(EVImodspace)### #### Chl NOW only for Lentic systems#### ################################################################################### datalent<-data[which(data$lentvlot=="lentic" ), ] ##for Algae op<-par(mfrow=c(2,1),mar=c(4,4,1,1)) plot(datalent$Chla~datalent$birds) shapiro.test(residuals(aov(datalent$Chla~datalent$birds))) ## Normality is acccomplished bartlett.test(datalent$Chla~datalent$birds) ##We do not have homogeneity of variance-- ## we try GlS ##################################### library(nlme) testChl<-datalent[which(datalent$Chla >0 ), ] Chlmod<-gls(Chla~birds, data=testChl) summary(Chlmod) ### Need to add variance structure as there is no homogeneity of variance vf1<- varIdent(form=~1|birds)### this code allows for a different variance stucture across the two groups Chlmod1<-gls(Chla~birds, weights = vf1, data=testChl) # with the variance structure in the mode summary(Chlmod1) anova(richmod,Chlmod1) # model with the variance structure in significant improvement ##continue with model woth diffrent variance structure # now check for spatial autocorrelation E<- resid(Chlmod1, type="normalized") ### get the residuals F<- fitted (Chlmod1) ## and the fittefd whilst we are at it plot(E~testrich$birds)## xyplot(n1 ~ e1, aspect = "iso", data = testChl, col= testrich$birds, pch=16) MyCex <- abs(E) / max(abs(E)) MyCol <- E MyCol[E >= 0 ] <- 1 MyCol[E < 0 ] <- 2 xyplot(n1~ e1, cex = 4* MyCex, pch = 1, col = MyCol, data = testChl, main = "Spatial plot of residuals") str(datalent) plot(E~testrich$birds) variochlmod<- Variogram(Chlmod1, form=~n1+e1, robust=TRUE, maxDist=100000, restype="normalized") plot(variochlmod) CHLmodspace<-gls(Chla~birds,weights = vf1, correlation=corGaus(form=~n1+e1,nugget=TRUE), data=testChl) AIC(Chlmod1, CHLmodspace) anova(Chlmod1, CHLmodspace)##adding space does NOT improve the model summary(Chlmod1) #### for LOTIC systems#### datalot<-data[which(data$lentvlot=="lotic" ), ] ###################################### ##for Algae op<-par(mfrow=c(2,1),mar=c(4,4,1,1)) plot(datalot$Chla~datalot$birds) shapiro.test(residuals(aov(datalot$Chla~datalot$birds))) ## Normality is acccomplished bartlett.test(datalot$Chla~datalot$birds) ##We do not have homogeneity of variance-- ## we try GlS ##################################### library(nlme) testChl<-datalot[which(datalot$Chla >0 ), ] Chlmod<-gls(Chla~birds, data=testChl) summary(Chlmod) vf1<- varIdent(form=~1|birds)### this code allows for a different variance stucture across the two groups Chlmod1<-gls(Chla~birds, weights = vf1, data=testChl) # with the variance structure in the mode summary(Chlmod1) anova(Chlmod,Chlmod1) # model with the variance structure in significant improvement # now check for spatial autocorrelation E<- resid(Chlmod1, type="normalized") ### get the residuals F<- fitted (Chlmod1) ## and the fittefd whilst we are at it plot(E~testChl$birds)## xyplot(n1 ~ e1, aspect = "iso", data = testChl, col= testChl$birds, pch=16) MyCex <- abs(E) / max(abs(E)) MyCol <- E MyCol[E >= 0 ] <- 1 MyCol[E < 0 ] <- 2 xyplot(n1~ e1, cex = 4* MyCex, pch = 1, col = MyCol, data = testChl, main = "Spatial plot of residuals") str(datalot) plot(E~testChl$birds) ### this makes a variogram to look for spatial autocorrelation variochlmod<- Variogram(Chlmod1, form=~n1+e1, robust=TRUE, maxDist=100000, restype="normalized") plot(variochlmod) ## this model puts in a wieghting stricture to account for spatial autocorrelation so the significance test can be trusted. CHLmodspace<-gls(Chla~birds,weights = vf1, correlation=corGaus(form=~n1+e1,nugget=TRUE), data=testChl) AIC(Chlmod1, CHLmodspace) anova(Chlmod1, CHLmodspace)##adding space does NOT improve the model summary(Chlmod1) #################################################### ################################################ ## Test of Isotopic signatures ################################################# ##### 1) PERMANOVA dataiso <- read.csv("dataisotopes.csv", header=TRUE, sep=";") dataiso$birds<-as.factor(dataiso$birds) str(dataiso) head(dataiso) MyVariso <- c( "X13C.Aqmoss", "X13C.peri", "X13C.inv", "X15N.Aqmoss","X15N.peri", "X15N.inv") env1iso<-(as.matrix(dataiso[,MyVariso])) ### goodiso<-complete.cases(env1iso) ### totiso <- dataiso[goodiso,]### yiso<-env1iso[goodiso,]## str(totiso) # str(yiso) head(yiso) mod<-adonis(yiso ~ birds, data=totiso, permutations=999, method="euclidean") mod mod <- rda(yiso, scale =TRUE)## says RDA but is a PCA, scale =TRUE, means data are standardised plot(mod, type = "n") text(mod, display = "sites", , cex = 0.5, col = c("black","green")[tot$birds]) text(mod, display = "species", , cex = 0.5, col="red") with(data, legend("topright", legend = c("no birds","birds"), bty = "n", pch = 20, col = c("black","green"))) ### puts hulls around the groups ordihull(mod, group=totiso$birds, show="0", col="black") ordihull(mod, group=totiso$birds, show="1", col="green") ################################################################ ################################################################# ## Testing differences in isotopic signatures one by one now... ########## d15N in benthic algae op<-par(mfrow=c(2,1),mar=c(4,4,1,1)) plot(dataiso$X15N.peri~dataiso$birds) plot(dataiso$X13C.peri~dataiso$birds) par(op) ### can see large difference in variance between the two groups so ANOVA no ok anyway.. we use GLS then we can put space in too if needed. library(nlme) peri15nmod<-gls(X15N.peri~birds, data=dataiso) summary(peri15nmod) vf1<- varIdent(form=~1|birds)### this code allows for a different variance stucture across the two groups peri15mod1<-gls(X15N.peri~birds, weights = vf1, data=dataiso) # with the variance structure in the mode summary(peri15mod1) anova(peri15nmod,peri15mod1) # model with the variance structure in significant improvement AIC(peri15nmod,peri15mod1) ## two ways of comparing the models both say model with the data structure in to account for the heterogeneity is better. # now check for spatial autocorrelation E<- resid(peri15mod1, type="normalized") ### get the residuals F<- fitted (peri15mod1) ## and the fittefd whilst we are at it plot(E~dataiso$birds)## residual spread looks good xyplot(n1 ~ e1, aspect = "iso", data = dataiso, col= dataiso$birds, pch=16) MyCex <- abs(E) / max(abs(E)) MyCol <- E MyCol[E >= 0 ] <- 1 MyCol[E < 0 ] <- 2 xyplot(n1~ e1, cex = 4* MyCex, pch = 1, col = MyCol, data = dataiso, main = "Spatial plot of residuals") str(data) plot(E~dataiso$birds) vario15nperomod1<- Variogram(peri15mod1, form=~n1+e1, robust=TRUE, maxDist=100000, restype="normalized") plot(vario15nperomod1) nperimodspace<-gls(X15N.peri~birds, weights = vf1,correlation=corGaus(form=~n1+e1,nugget=TRUE), data=dataiso) AIC(peri15mod1, nperimodspace) anova(peri15mod1, nperimodspace) summary(nperimodspace)### with space in, Bird colony is still massively sig. There are no R2 values for GLS, but we can compare observed vs predicted F1<-fitted(nperimodspace) cor(F1,dataiso$X15N.peri)^2 ## pretty good at 0.5539 for the cor^2 value ## this is just one way of putting space in, we should see if the others are any better A1<-gls(X15N.peri~birds, weights = vf1,correlation=corGaus(form=~n1+e1,nugget=TRUE), data=dataiso) A2<-gls(X15N.peri~birds, weights = vf1,correlation=corSpher(form=~n1+e1,nugget=TRUE), data=dataiso) A3<-gls(X15N.peri~birds, weights = vf1,correlation=corLin(form=~n1+e1,nugget=TRUE), data=dataiso)# A4<-gls(X15N.peri~birds, weights = vf1,correlation=corExp(form=~n1+e1,nugget=TRUE), data=dataiso) A5<-gls(X15N.peri~birds, weights = vf1,correlation=corRatio(form=~n1+e1,nugget=TRUE), data=dataiso) AIC (A1,A2,A4,A5)## d15Nfinalmodel<-gls(X15N.peri~birds, weights = vf1,correlation=corExp(form=~n1+e1,nugget=TRUE),method="ML", data=dataiso) summary(d15Nfinalmodel) ########################################### ### d15N in chiroromidae op<-par(mfrow=c(2,1),mar=c(4,4,1,1)) plot(dataiso$X15N.chiro~dataiso$birds) par(op) library(nlme) testchiron<-dataiso[which(dataiso$X15N.chiro >-7 ),] chiro15nmod<-gls(X15N.chiro~birds, data=testchiron) summary(chiro15nmod) vf1<- varIdent(form=~1|birds) chiro15mod1<-gls(X15N.chiro~birds, weights = vf1, data=testchiron) summary(chiro15mod1) anova(chiro15nmod,chiro15mod1) E<- resid(chiro15mod1, type="normalized") F<- fitted (chiro15mod1) plot(E~testchiron$birds) xyplot(n1 ~ e1, aspect = "iso", data = testchiron, col= testchiron$birds, pch=16) MyCex <- abs(E) / max(abs(E)) MyCol <- E MyCol[E >= 0 ] <- 1 MyCol[E < 0 ] <- 2 xyplot(n1~ e1, cex = 4* MyCex, pch = 1, col = MyCol, data = testchiron, main = "Spatial plot of residuals") str(data) plot(E~testchiron$birds) vario15nchiromod1<- Variogram(chiro15mod1, form=~n1+e1, robust=TRUE, maxDist=100000, restype="normalized") plot(vario15nchiromod1) nchiromodspace<-gls(X15N.chiro~birds, weights = vf1,correlation=corGaus(form=~n1+e1,nugget=TRUE), data=testchiron) AIC(chiro15mod1, nchiromodspace) anova(chiro15mod1, nchiromodspace) summary(nchiromodspace) ### d15N in aquatic moss op<-par(mfrow=c(2,1),mar=c(4,4,1,1)) plot(dataiso$X15N.Aqmoss~dataiso$birds) par(op) library(nlme) testaqmossn<-dataiso[which(dataiso$X15N.Aqmoss >-7 ),] aqmoss15nmod<-gls(X15N.Aqmoss~birds, data=testaqmossn) summary(aqmoss15nmod) vf1<- varIdent(form=~1|birds) aqmoss15mod1<-gls(X15N.Aqmoss~birds, weights = vf1, data=testaqmossn) summary(aqmoss15mod1) anova(aqmoss15nmod,aqmoss15mod1) # E<- resid(aqmoss15mod1, type="normalized") ### F<- fitted (aqmoss15mod1) # plot(E~testaqmossn$birds)## xyplot(n1 ~ e1, aspect = "iso", data = testaqmossn, col= testaqmossn$birds, pch=16) MyCex <- abs(E) / max(abs(E)) MyCol <- E MyCol[E >= 0 ] <- 1 MyCol[E < 0 ] <- 2 xyplot(n1~ e1, cex = 4* MyCex, pch = 1, col = MyCol, data = testaqmossn, main = "Spatial plot of residuals") str(data) plot(E~testaqmossn$birds) vario15naqmossmod1<- Variogram(aqmoss15mod1, form=~n1+e1, robust=TRUE, maxDist=100000, restype="normalized") plot(vario15naqmossmod1) naqmossmodspace<-gls(X15N.Aqmoss~birds, weights = vf1,correlation=corGaus(form=~n1+e1,nugget=TRUE), data=testaqmossn) AIC(aqmoss15mod1, naqmossmodspace) anova(aqmoss15mod1, naqmossmodspace)## space does not improve summary(aqmoss15mod1) ### d15N in debris op<-par(mfrow=c(2,1),mar=c(4,4,1,1)) plot(dataiso$X15N.deb~dataiso$birds) par(op) library(nlme) testdebn<-dataiso[which(dataiso$X15N.deb >-7 ),] deb15nmod<-gls(X15N.deb~birds, data=testdebn) summary(deb15nmod) vf1<- varIdent(form=~1|birds)### deb15mod1<-gls(X15N.deb~birds, weights = vf1, data=testdebn) # with the variance structure in the mode summary(deb15mod1) anova(deb15nmod,deb15mod1) # E<- resid(deb15mod1, type="normalized") ### F<- fitted (deb15mod1) ## plot(E~testdebn$birds)## xyplot(n1 ~ e1, aspect = "iso", data = testdebn, col= testdebn$birds, pch=16) MyCex <- abs(E) / max(abs(E)) MyCol <- E MyCol[E >= 0 ] <- 1 MyCol[E < 0 ] <- 2 xyplot(n1~ e1, cex = 4* MyCex, pch = 1, col = MyCol, data = testdebn, main = "Spatial plot of residuals") str(data) plot(E~testdebn$birds) vario15ndebmod1<- Variogram(deb15mod1, form=~n1+e1, robust=TRUE, maxDist=100000, restype="normalized") plot(vario15ndebmod1) ndebmodspace<-gls(X15N.deb~birds, weights = vf1,correlation=corGaus(form=~n1+e1,nugget=TRUE), data=testdebn) AIC(deb15mod1, ndebmodspace) anova(deb15mod1, ndebmodspace)## space does not improve model summary(deb15mod1) ########################################### ### d15N of other invertebrates op<-par(mfrow=c(2,1),mar=c(4,4,1,1)) plot(dataiso$X15N.inv~dataiso$birds) shapiro.test(residuals(aov(dataiso$X15N.inv~dataiso$birds))) ## suggests normality is acccomplished bartlett.test(dataiso$X15N.inv~dataiso$birds) ## NOT homogeneity of variance-- par(op) library(nlme) testinvn<-dataiso[which(dataiso$X15N.inv >-7 ),] inv15nmod<-gls(X15N.inv~birds, data=testinvn) summary(inv15nmod) vf1<- varIdent(form=~1|birds) inv15mod1<-gls(X15N.inv~birds, weights = vf1, data=testinvn) # summary(inv15mod1) anova(inv15nmod,inv15mod1) E<- resid(inv15mod1, type="normalized") ### F<- fitted (inv15mod1) ## plot(E~testinvn$birds)## xyplot(n1 ~ e1, aspect = "iso", data = testinvn, col= testinvn$birds, pch=16) MyCex <- abs(E) / max(abs(E)) MyCol <- E MyCol[E >= 0 ] <- 1 MyCol[E < 0 ] <- 2 xyplot(n1~ e1, cex = 4* MyCex, pch = 1, col = MyCol, data = testinvn, main = "Spatial plot of residuals") str(data) plot(E~testinvn$birds) vario15ninvmod1<- Variogram(inv15mod1, form=~n1+e1, robust=TRUE, maxDist=100000, restype="normalized") plot(vario15ninvmod1) ninvmodspace<-gls(X15N.inv~birds, weights = vf1,correlation=corGaus(form=~n1+e1,nugget=TRUE), data=testinvn) AIC(inv15mod1, ninvmodspace) anova(inv15mod1, ninvmodspace)## space does not improve model summary(inv15mod1) ### 15N peat op<-par(mfrow=c(2,1),mar=c(4,4,1,1)) plot(dataiso$X15N.peat~dataiso$birds) shapiro.test(residuals(aov(dataiso$X15N.peat~dataiso$birds))) ## suggests normality is acccomplished bartlett.test(dataiso$X15N.peat~dataiso$birds) ## homogeneity of variance-- par(op) library(nlme) testpeatn<-dataiso[which(dataiso$X15N.peat >-7 ),] peat15nmod<-gls(X15N.peat~birds, data=testpeatn) summary(peat15nmod) E<- resid(peat15nmod, type="normalized") ### F<- fitted (peat15nmod) ## plot(E~testpeatn$birds)## xyplot(n1 ~ e1, aspect = "iso", data = testpeatn, col= testpeatn$birds, pch=16) MyCex <- abs(E) / max(abs(E)) MyCol <- E MyCol[E >= 0 ] <- 1 MyCol[E < 0 ] <- 2 xyplot(n1~ e1, cex = 4* MyCex, pch = 1, col = MyCol, data = testpeatn, main = "Spatial plot of residuals") str(data) plot(E~testpeatn$birds) vario15npeatmod1<- Variogram(peat15nmod, form=~n1+e1, robust=TRUE, maxDist=100000, restype="normalized") plot(vario15npeatmod1) npeatmodspace<-gls(X15N.peat~birds, weights = vf1,correlation=corGaus(form=~n1+e1,nugget=TRUE), data=testpeatn) AIC(peat15nmod, npeatmodspace) anova(peat15nmod, npeatmodspace)## space does not improve model summary(peat15nmod) ########################################### ### d15N in terrestrial vegetation op<-par(mfrow=c(2,1),mar=c(4,4,1,1)) plot(dataiso$X15N.tveg~dataiso$birds) shapiro.test(residuals(aov(dataiso$X15N.tveg~dataiso$birds))) ## suggests normality is acccomplished bartlett.test(dataiso$X15N.tveg~dataiso$birds) ## homogeneity of variance-- par(op) library(nlme) testtvegn<-dataiso[which(dataiso$X15N.tveg >-7 ),] tveg15nmod<-gls(X15N.tveg~birds, data=testtvegn) summary(tveg15nmod) E<- resid(tveg15nmod, type="normalized") ### F<- fitted (tveg15nmod) ## plot(E~testtvegn$birds)## xyplot(n1 ~ e1, aspect = "iso", data = testtvegn, col= testtvegn$birds, pch=16) MyCex <- abs(E) / max(abs(E)) MyCol <- E MyCol[E >= 0 ] <- 1 MyCol[E < 0 ] <- 2 xyplot(n1~ e1, cex = 4* MyCex, pch = 1, col = MyCol, data = testtvegn, main = "Spatial plot of residuals") str(data) plot(E~testtvegn$birds) vario15ntvegmod1<- Variogram(tveg15nmod, form=~n1+e1, robust=TRUE, maxDist=100000, restype="normalized") plot(vario15ntvegmod1) ntvegmodspace<-gls(X15N.tveg~birds, weights = vf1,correlation=corGaus(form=~n1+e1,nugget=TRUE), data=testtvegn) AIC(tveg15nmod, ntvegmodspace) anova(tveg15nmod, ntvegmodspace)## summary(tveg15nmod) ###for d13C signatures ############################################################### ########## d13C in benthic algae op<-par(mfrow=c(2,1),mar=c(4,4,1,1)) plot(dataiso$X13C.peri~dataiso$birds) shapiro.test(residuals(aov(dataiso$X13C.peri~dataiso$birds))) ## suggests normality is acccomplished bartlett.test(dataiso$X13C.peri~dataiso$birds) ## homogeneity of variance-- par(op) library(nlme) peri13Cmod<-gls(X13C.peri~birds, data=dataiso) summary(peri13Cmod) E<- resid(peri13Cmod, type="normalized") ### F<- fitted (peri13Cmod) # plot(E~dataiso$birds)# xyplot(n1 ~ e1, aspect = "iso", data = dataiso, col= dataiso$birds, pch=16) MyCex <- abs(E) / max(abs(E)) MyCol <- E MyCol[E >= 0 ] <- 1 MyCol[E < 0 ] <- 2 xyplot(n1~ e1, cex = 4* MyCex, pch = 1, col = MyCol, data = dataiso, main = "Spatial plot of residuals") str(data) plot(E~dataiso$birds) vario13Cperomod1<- Variogram(peri13Cmod, form=~n1+e1, robust=TRUE, maxDist=100000, restype="normalized") plot(vario13Cperomod1) nperimodspace<-gls(X13C.peri~birds, weights = vf1,correlation=corGaus(form=~n1+e1,nugget=TRUE), data=dataiso) AIC(peri13Cmod, nperimodspace) anova(peri13Cmod, nperimodspace) summary(peri13Cmod) # ### d13C in chironomidae op<-par(mfrow=c(2,1),mar=c(4,4,1,1)) plot(dataiso$X13C.chiro~dataiso$birds) shapiro.test(residuals(aov(dataiso$X13C.chiro~dataiso$birds))) ## suggests normality is acccomplished bartlett.test(dataiso$X13C.chiro~dataiso$birds) ## homogeneity of variance-- par(op) library(nlme) testchiron<-dataiso[which(dataiso$X13C.chiro <0 ),] chiro13Cmod<-gls(X13C.chiro~birds, data=testchiron) summary(chiro13Cmod) E<- resid(chiro13Cmod, type="normalized") F<- fitted (chiro13Cmod) plot(E~testchiron$birds)# xyplot(n1 ~ e1, aspect = "iso", data = testchiron, col= testchiron$birds, pch=16) MyCex <- abs(E) / max(abs(E)) MyCol <- E MyCol[E >= 0 ] <- 1 MyCol[E < 0 ] <- 2 xyplot(n1~ e1, cex = 4* MyCex, pch = 1, col = MyCol, data = testchiron, main = "Spatial plot of residuals") str(data) plot(E~testchiron$birds) vario13Cchiromod1<- Variogram(chiro13Cmod, form=~n1+e1, robust=TRUE, maxDist=100000, restype="normalized") plot(vario13Cchiromod1) nchiromodspace<-gls(X13C.chiro~birds, weights = vf1,correlation=corGaus(form=~n1+e1,nugget=TRUE), data=testchiron) AIC(chiro13Cmod, nchiromodspace) anova(chiro13Cmod, nchiromodspace) summary(chiro13Cmod) ########################################### ### d13C in aquatic moss op<-par(mfrow=c(2,1),mar=c(4,4,1,1)) plot(dataiso$X13C.Aqmoss~dataiso$birds) shapiro.test(residuals(aov(dataiso$X13C.Aqmoss~dataiso$birds))) ## suggests normality is acccomplished bartlett.test(dataiso$X13C.Aqmoss~dataiso$birds) ## not homogeneity par(op) library(nlme) testaqmossn<-dataiso[which(dataiso$X13C.Aqmoss <0 ),] aqmoss13Cmod<-gls(X13C.Aqmoss~birds, data=testaqmossn) summary(aqmoss13Cmod) vf1<- varIdent(form=~1|birds)# aqmoss15mod1<-gls(X13C.Aqmoss~birds, weights = vf1, data=testaqmossn) summary(aqmoss15mod1) anova(aqmoss13Cmod,aqmoss15mod1) E<- resid(aqmoss15mod1, type="normalized") # F<- fitted (aqmoss15mod1) # plot(E~testaqmossn$birds)# xyplot(n1 ~ e1, aspect = "iso", data = testaqmossn, col= testaqmossn$birds, pch=16) MyCex <- abs(E) / max(abs(E)) MyCol <- E MyCol[E >= 0 ] <- 1 MyCol[E < 0 ] <- 2 xyplot(n1~ e1, cex = 4* MyCex, pch = 1, col = MyCol, data = testaqmossn, main = "Spatial plot of residuals") str(data) plot(E~testaqmossn$birds) vario13Caqmossmod1<- Variogram(aqmoss15mod1, form=~n1+e1, robust=TRUE, maxDist=100000, restype="normalized") plot(vario13Caqmossmod1) naqmossmodspace<-gls(X13C.Aqmoss~birds, weights = vf1,correlation=corGaus(form=~n1+e1,nugget=TRUE), data=testaqmossn) AIC(aqmoss15mod1, naqmossmodspace) anova(aqmoss15mod1, naqmossmodspace)# summary(aqmoss15mod1) ### d13C in debris op<-par(mfrow=c(2,1),mar=c(4,4,1,1)) plot(dataiso$X13C.deb~dataiso$birds) shapiro.test(residuals(aov(dataiso$X13C.deb~dataiso$birds))) ## suggests normality is acccomplished bartlett.test(dataiso$X13C.deb~dataiso$birds) ## not homogeneity par(op) library(nlme) testdebn<-dataiso[which(dataiso$X13C.deb <0 ),] deb13Cmod<-gls(X13C.deb~birds, data=testdebn) summary(deb13Cmod) vf1<- varIdent(form=~1|birds) deb15mod1<-gls(X13C.deb~birds, weights = vf1, data=testdebn) summary(deb15mod1) anova(deb13Cmod,deb15mod1) E<- resid(deb15mod1, type="normalized") F<- fitted (deb15mod1) plot(E~testdebn$birds)## xyplot(n1 ~ e1, aspect = "iso", data = testdebn, col= testdebn$birds, pch=16) MyCex <- abs(E) / max(abs(E)) MyCol <- E MyCol[E >= 0 ] <- 1 MyCol[E < 0 ] <- 2 xyplot(n1~ e1, cex = 4* MyCex, pch = 1, col = MyCol, data = testdebn, main = "Spatial plot of residuals") str(data) plot(E~testdebn$birds) vario13Cdebmod1<- Variogram(deb15mod1, form=~n1+e1, robust=TRUE, maxDist=100000, restype="normalized") plot(vario13Cdebmod1) ndebmodspace<-gls(X13C.deb~birds, weights = vf1,correlation=corGaus(form=~n1+e1,nugget=TRUE), data=testdebn) AIC(deb15mod1, ndebmodspace) anova(deb15mod1, ndebmodspace)# summary(deb15mod1) ########################################### ### d13C in other invertebrates op<-par(mfrow=c(2,1),mar=c(4,4,1,1)) plot(dataiso$X13C.inv~dataiso$birds) shapiro.test(residuals(aov(dataiso$X13C.inv~dataiso$birds))) bartlett.test(dataiso$X13C.inv~dataiso$birds) par(op) library(nlme) testinvn<-dataiso[which(dataiso$X13C.inv <0 ),] inv13Cmod<-gls(X13C.inv~birds, data=testinvn) summary(inv13Cmod) E<- resid(inv13Cmod, type="normalized") F<- fitted (inv13Cmod) plot(E~testinvn$birds) xyplot(n1 ~ e1, aspect = "iso", data = testinvn, col= testinvn$birds, pch=16) MyCex <- abs(E) / max(abs(E)) MyCol <- E MyCol[E >= 0 ] <- 1 MyCol[E < 0 ] <- 2 xyplot(n1~ e1, cex = 4* MyCex, pch = 1, col = MyCol, data = testinvn, main = "Spatial plot of residuals") str(data) plot(E~testinvn$birds) vario13Cinvmod1<- Variogram(inv13Cmod, form=~n1+e1, robust=TRUE, maxDist=100000, restype="normalized") plot(vario13Cinvmod1) ninvmodspace<-gls(X13C.inv~birds, weights = vf1,correlation=corGaus(form=~n1+e1,nugget=TRUE), data=testinvn) AIC(inv13Cmod, ninvmodspace) anova(inv13Cmod, ninvmodspace)## space does not improve model summary(inv13Cmod) ########################################### ### d13C in peat op<-par(mfrow=c(2,1),mar=c(4,4,1,1)) plot(dataiso$X13C.peat~dataiso$birds) shapiro.test(residuals(aov(dataiso$X13C.peat~dataiso$birds))) bartlett.test(dataiso$X13C.peat~dataiso$birds) par(op) library(nlme) testpeatn<-dataiso[which(dataiso$X13C.peat <0 ),] peat13Cmod<-gls(X13C.peat~birds, data=testpeatn) summary(peat13Cmod) E<- resid(peat13Cmod, type="normalized") F<- fitted (peat13Cmod) plot(E~testpeatn$birds) xyplot(n1 ~ e1, aspect = "iso", data = testpeatn, col= testpeatn$birds, pch=16) MyCex <- abs(E) / max(abs(E)) MyCol <- E MyCol[E >= 0 ] <- 1 MyCol[E < 0 ] <- 2 xyplot(n1~ e1, cex = 4* MyCex, pch = 1, col = MyCol, data = testpeatn, main = "Spatial plot of residuals") str(data) plot(E~testpeatn$birds) vario13Cpeatmod1<- Variogram(peat13Cmod, form=~n1+e1, robust=TRUE, maxDist=100000, restype="normalized") plot(vario13Cpeatmod1) npeatmodspace<-gls(X13C.peat~birds, weights = vf1,correlation=corGaus(form=~n1+e1,nugget=TRUE), data=testpeatn) AIC(peat13Cmod, npeatmodspace) anova(peat13Cmod, npeatmodspace)## summary(peat13Cmod) ########################################### ### d13C in terrestrial vegetation op<-par(mfrow=c(2,1),mar=c(4,4,1,1)) plot(dataiso$X13C.tveg~dataiso$birds) shapiro.test(residuals(aov(dataiso$X13C.tveg~dataiso$birds))) ## suggests normality is acccomplished bartlett.test(dataiso$X13C.tveg~dataiso$birds) ## homogeneity of variance-- par(op) library(nlme) testtvegn<-dataiso[which(dataiso$X13C.tveg <0 ),] tveg13Cmod<-gls(X13C.tveg~birds, data=testtvegn) summary(tveg13Cmod) E<- resid(tveg13Cmod, type="normalized") ### F<- fitted (tveg13Cmod) # plot(E~testtvegn$birds) xyplot(n1 ~ e1, aspect = "iso", data = testtvegn, col= testtvegn$birds, pch=16) MyCex <- abs(E) / max(abs(E)) MyCol <- E MyCol[E >= 0 ] <- 1 MyCol[E < 0 ] <- 2 xyplot(n1~ e1, cex = 4* MyCex, pch = 1, col = MyCol, data = testtvegn, main = "Spatial plot of residuals") str(data) plot(E~testtvegn$birds) vario13Ctvegmod1<- Variogram(tveg13Cmod, form=~n1+e1, robust=TRUE, maxDist=100000, restype="normalized") plot(vario13Ctvegmod1) ntvegmodspace<-gls(X13C.tveg~birds, weights = vf1,correlation=corGaus(form=~n1+e1,nugget=TRUE), data=testtvegn) AIC(tveg13Cmod, ntvegmodspace) anova(tveg13Cmod, ntvegmodspace) summary(tveg13Cmod) ######### Testing changesin pHysicochemical properties along a gradient in algal d15N #setwd("/Users/ivangonzalez/Desktop/paper Groenlandia -R1") #### data <- read.csv("data.csv", header=TRUE, sep=";") data$birds<-as.factor(data$birds) library(nlme) require(lattice) require(mgcv) op<-par(mfrow=c(3,2),mar=c(4,4,1,1)) pHgrad<-data[which(data$pH>0 ),] ### PH model and plot pHmod<-lm(pH~d15Nperi, data=pHgrad) summary(pHmod) plot(pHgrad$d15Nperi, pHgrad$pH, ylab="System pH", xlab=expression(paste(delta^{15}, "N")), pch=c(1,19)[pHgrad$birds]) #Pmod<-predict(pHmod, newdata=md1) #lines(md1$d15Nperi, Pmod) ND <- data.frame(d15Nperi=seq(from=-2,to=33.2)) prd<-predict(pHmod,newdata=ND,interval = c("confidence"), level = 0.90,type="response") lines(ND$d15Nperi, prd[,1]) lines(ND$d15Nperi,prd[,2],col="gray",lty=2) lines(ND$d15Nperi,prd[,3],col="gray",lty=2) ##### TN TNgrad<-data[which(data$TN>0 ),] require(mgcv) library(nlme) require(lattice) vf5<-varIdent(form=~1|birds)## ident power M3 <- gamm(TN~s(d15Nperi), weights = vf5, method = "REML", data = TNgrad) summary(M3$gam) summary(M3$lme) ND <- data.frame(d15Nperi=seq(from=-2,to=33.2),100) PM3 <- predict(M3$gam,ND, se = TRUE) plot(TNgrad$d15Nperi, TNgrad$TN, pch=c(1,19)[TNgrad$birds], ylab=expression(paste("TN (mg l"^-1,")")), xlab=expression(paste(delta^{15}, "N"))) lines(ND$d15Nperi,PM3$fit) lines(ND$d15Nperi,(PM3$fit+PM3$se), lty=2) lines(ND$d15Nperi,(PM3$fit-PM3$se), lty=2) #### TP takes much the same model as there is a non-linear response and heterogeniety of variance - see model mess for details TPgrad<-data[which(data$TP>0 ),] M3 <- gamm(TP~s(d15Nperi), weights = vf5, method = "REML", data = TPgrad) summary(M3$gam) summary(M3$lme) ND <- data.frame(d15Nperi=seq(from=-2,to=33.2),100) PM3 <- predict(M3$gam,ND, se = TRUE) plot(TPgrad$d15Nperi, TPgrad$TP, pch=c(1,19)[TPgrad$birds], ylab=expression(paste("TP (",mu,"g l"^-1,")")), xlab=expression(paste(delta^{15}, "N"))) lines(ND$d15Nperi,PM3$fit) lines(ND$d15Nperi,(PM3$fit+PM3$se), lty=2) lines(ND$d15Nperi,(PM3$fit-PM3$se), lty=2) ##### Lentic Chla Chlagrad<-data[which(data$ChlaLent>0 ),]# M3 <- gamm(Chla~s(d15Nperi), weights = vf5, method = "REML", data = Chlagrad) summary(M3$gam) summary(M3$lme) range(Chlagrad$d15Nperi) ND <- data.frame(d15Nperi=seq(from=-1.56,to=24.96)) PM3 <- predict(M3$gam,ND, se = TRUE) plot(Chlagrad$d15Nperi, Chlagrad$Chla, pch=c(1,19)[Chlagrad$birds], ylab=expression(paste("Lentic Chla (",mu,"g l"^-1,")")), xlab=expression(paste(delta^{15}, "N"))) lines(ND$d15Nperi,PM3$fit) lines(ND$d15Nperi,(PM3$fit+PM3$se), lty=2) lines(ND$d15Nperi,(PM3$fit-PM3$se), lty=2) ### Lotic Chla Chlagrad<-data[which(data$ChlaLot>0 ),]# vf2<- varPower(form=~d15Nperi)## power M3 <- gamm(Chla~s(d15Nperi), weights = vf2, method = "REML", data = Chlagrad) summary(M3$gam) summary(M3$lme) range(Chlagrad$d15Nperi) ND <- data.frame(d15Nperi=seq(from=-2.07,to=33.2)) PM3 <- predict(M3$gam,ND, se = TRUE) plot(Chlagrad$d15Nperi, Chlagrad$Chla, pch=c(1,19)[Chlagrad$birds], ylab=expression(paste("Lotic Chla (",mu,"g l"^-1,")")), xlab=expression(paste(delta^{15}, "N"))) lines(ND$d15Nperi,PM3$fit) lines(ND$d15Nperi,(PM3$fit+PM3$se), lty=2) lines(ND$d15Nperi,(PM3$fit-PM3$se), lty=2) # Here is EVI code in case you need/want it.. # ####EVI plot # #evigrad<-data[which(data$EVI.500.max>0 ),] # #evimod<-lm(EVI.500.max~d15Nperi, data=evigrad) # #summary(evimod) # # plot(evigrad$d15Nperi, evigrad$EVI.500.max, ylab="EVI", xlab="15N", pch=c(1,19)[evigrad$birds]) # #Pmod<-predict(pHmod, newdata=md1) # #lines(md1$d15Nperi, Pmod) # prd<-predict(evimod,newdata=ND,interval = c("confidence"), # level = 0.90,type="response") # lines(ND$d15Nperi, prd[,1]) # lines(ND$d15Nperi,prd[,2],col="gray",lty=2) # lines(ND$d15Nperi,prd[,3],col="gray",lty=2) ################richness richgrad<-data[-(34:35),] is.na(richgrad$ Consumer.taxa.diversity) richgrad$rich<-richgrad$ Consumer.taxa.diversity## this is just to make the typing easier M3 <- gamm(rich~s(d15Nperi), weights = vf5, method = "REML", data = richgrad) summary(M3$gam) summary(M3$lme) range(richgrad$d15Nperi) ND <- data.frame(d15Nperi=seq(from=-2.07,to=33.2)) PM3 <- predict(M3$gam,ND, se = TRUE) plot(richgrad$d15Nperi, richgrad$rich, pch=c(1,19)[richgrad$birds], ylab="Number of consumer taxa", xlab=expression(paste(delta^{15}, "N"))) lines(ND$d15Nperi,PM3$fit) lines(ND$d15Nperi,(PM3$fit+PM3$se), lty=2) lines(ND$d15Nperi,(PM3$fit-PM3$se), lty=2) par(op) ##################################################################### ## DISTANCE PLOTS ##################################################################### op<-par(mfrow=c(4,2),mar=c(4,4,1,1)) ####### Lentic Chla - no satisfactory model.. Chlagrad<-data[which(data$ChlaLent>0 ),]# plot(Chlagrad$distance, Chlagrad$Chla, pch=c(1,19)[Chlagrad$birds], ylab=expression(paste("Lentic Chla (",mu,"g l"^-1,")")), xlab=("Distance from colony (m)")) Chlagrad<-Chlagrad[Chlagrad$distance < 5000,] plot(Chlagrad$distance, Chlagrad$Chla, pch=c(1,19)[Chlagrad$birds], ylab=expression(paste("Lentic Chla (",mu,"g l"^-1,")")), xlab=("Distance from colony (m)")) #### LOTIC CHla Chlagrad<-data[which(data$ChlaLot>0 ),]# plot(Chlagrad$distance, Chlagrad$Chla, pch=c(1,19)[Chlagrad$birds], ylab=expression(paste("Lotic Chla (",mu,"g l"^-1,")")), xlab=("Distance from colony (m)")) vf3<- varExp(form=~distance)## exponential M3 <- gls(Chla~distance, weights=vf3, data = Chlagrad) summary(M3) ND <- data.frame(distance=seq(from=0,to=50000, by=100)) require(AICcmodavg) PM3<-predictSE.gls (M3, ND, se.fit=T) lines(ND$distance,PM3$fit) lines(ND$distance,(PM3$fit+PM3$se), lty=2) lines(ND$distance,(PM3$fit-PM3$se), lty=2) F<-fitted(M3) cor(Chlagrad$Chla, F)^2 ### sites close to colonies.. Chlagrad<-Chlagrad[Chlagrad$distance < 5000,] plot(Chlagrad$distance, Chlagrad$Chla, pch=c(1,19)[Chlagrad$birds], ylab=expression(paste("Lotic Chla (",mu,"g l"^-1,")")), xlab=("Distance from colony (m)")) require(AICcmodavg) vf3<- varExp(form=~distance)## exponential M3 <- gls(Chla~distance, weights=vf3, data = Chlagrad) summary(M3) ND <- data.frame(distance=seq(from=0,to=2500, by=100)) PM3<-predictSE.gls (M3, ND, se.fit=T) lines(ND$distance,PM3$fit) lines(ND$distance,(PM3$fit+PM3$se), lty=2) lines(ND$distance,(PM3$fit-PM3$se), lty=2) F<-fitted(M3) cor(Chlagrad$Chla, F)^2 ### distance and EVI ### all data evigrad<-data[which(data$EVI.500.max>0 ),] plot(evigrad$distance, evigrad$EVI.500.max, pch=c(1,19)[evigrad$birds], ylab="EVI.500.max", xlab="Distance from colony (m)") M3 <- gls(EVI.500.max~distance, weights=vf3, data = evigrad) summary(M3) ND <- data.frame(distance=seq(from=0,to=50000, by=100)) require(AICcmodavg) PM3<-predictSE.gls (M3, ND, se.fit=T) lines(ND$distance,PM3$fit) lines(ND$distance,(PM3$fit+PM3$se), lty=2) lines(ND$distance,(PM3$fit-PM3$se), lty=2) F<-fitted(M3) cor(evigrad$EVI.500.max, F)^2 ###<3000 evigrad<-data[which(data$EVI.500.max>0 ),]### this way I use alll available data and remove NAs evigrad<-evigrad[evigrad$distance < 5000,] plot(evigrad$distance, evigrad$EVI.500.max, pch=c(1,19)[evigrad$birds], ylab="EVI.500.max", xlab="Distance from colony (m)") evimod<-lm(EVI.500.max~distance, data=evigrad) summary(evimod) ND <- data.frame(distance=seq(from=0,to=50000, by=100)) prd<-predict(evimod,newdata=ND,interval = c("confidence"), level = 0.90,type="response") lines(ND$distance, prd[,1]) lines(ND$distance,prd[,2],col="gray",lty=2) lines(ND$distance,prd[,3],col="gray",lty=2) F<-fitted(M3) cor(evigrad$EVI.500.max, F)^2 #### delta 15 N ALL DATA d15Ngrad<-data[which(data$d15Nperi>0 ),]### this way I use alll available data and remove NAs plot(d15Ngrad$distance, d15Ngrad$d15Nperi, pch=c(1,19)[d15Ngrad$birds], ylab=expression(paste(delta^{15}, "N")), xlab="Distance from colony (m)") M3 <- gls(d15Nperi~distance, weights=vf3, data = d15Ngrad) summary(M3) ND <- data.frame(distance=seq(from=0,to=50000, by=100)) require(AICcmodavg) PM3<-predictSE.gls (M3, ND, se.fit=T) lines(ND$distance,PM3$fit) lines(ND$distance,(PM3$fit+PM3$se), lty=2) lines(ND$distance,(PM3$fit-PM3$se), lty=2) F<-fitted(M3) cor(d15Ngrad$d15Nperi, F)^2 ################ sites closer to colonies ### d15Ngrad<-d15Ngrad[d15Ngrad$distance < 3000,] plot(d15Ngrad$distance, d15Ngrad$d15Nperi, pch=c(1,19)[d15Ngrad$birds], ylab=expression(paste(delta^{15}, "N")), xlab="Distance from colony (m)") M3 <- gls(d15Nperi~distance, weights=vf3, data = d15Ngrad) summary(M3) ND <- data.frame(distance=seq(from=0,to=25000, by=100)) require(AICcmodavg) PM3<-predictSE.gls (M3, ND, se.fit=T) lines(ND$distance,PM3$fit) lines(ND$distance,(PM3$fit+PM3$se), lty=2) lines(ND$distance,(PM3$fit-PM3$se), lty=2) F<-fitted(M3) cor(d15Ngrad$d15Nperi, F)^2 par(op) ######################################################################## ######################### for Savissivik island dataset ########################################################################## Savissivik<-data[which(data$Area == "Savi" ), ] par(mfrow=c(2, 1), mar=c(2, 4.5, 1,1)) plot(Savissivik$d15Nperi~Savissivik$OverfleightIntensity, xlab="Flight intensity", ylab=expression(delta^15*N), pch=16, cex=1.2, xaxt="n") modelsav<-lm(Savissivik$OverfleightIntensity~Savissivik$d15Nperi) summary(modelsav) abline(lm(Savissivik$d15Nperi~Savissivik$OverfleightIntensity)) text(42.473232, 15.059022 , "NOW 9",cex = 0.7, adj = c(1.2,0.1)) text(41.791172, 13.086962, "NOW 13",cex = 0.7, adj = c(1.2,1.4 )) text(17.029095 , 9.577321, "NOW 12",cex = 0.7, adj = c(1.2,1.4)) text(2.480434, 5.137263, "NOW 11",cex = 0.7, adj = c(-0.2,0.1)) text(1.540072, 4.495496, "NOW 10",cex = 0.7, adj = c(-0.2,0.1)) plot(Savissivik$EVI.500.max~Savissivik$OverfleightIntensity, pch=16) modelosavi<-lm(Savissivik$EVI.500.max~Savissivik$OverfleightIntensity) summary(modelosavi) abline(lm(Savissivik$EVI.500.max~Savissivik$OverfleightIntensity)) text(42.473232, 0.3399 , "NOW 9",cex = 0.7, adj = c(1.2,0.1)) text(41.791172, 0.2604, "NOW 13",cex = 0.7, adj = c(1.2,1.4 )) text(17.029095 , 0.1291, "NOW 12",cex = 0.7, adj = c(1.2,1.4)) text(2.480434, 0.0677, "NOW 11",cex = 0.7, adj = c(-0.2,0.1)) text(1.540072, 0.0732, "NOW 10",cex = 0.7, adj = c(-0.1,-0.4)) plot(Savissivik$d15Nperi~Savissivik$EVI.500.max, pch=16) modelosavi<-lm(Savissivik$d15Nperi~Savissivik$EVI.500.max) summary(modelosavi) abline(lm(Savissivik$d15Nperi~Savissivik$EVI.500.max)) #obj 3: mechanisms for periphyton increase and richnesss decrease, nutrients increase productivity #and ph decrease richness of consumers ############# Relationship of PH and lotic richness par(mfrow=c(3, 2), mar=c(4, 4, 2, 2)) streams<-data[which(data$lentvlot=="lotic" ),] birdstreams<-streams[which(streams$birds=="1" ),] birdlessstreams<-streams[which(streams$birds=="0" ),] lakes<-data[which(data$lentvlot=="lentic" ),] birdlakes<- lakes[which(lakes$birds=="1" ), ] birdlesslakes<- lakes[which(lakes$birds=="0" ), ] ##Total Nitrogen increase stream Chl plot(streams$ChlaLot~streams$TN, ylab="Stream Chl", xlab="System total nitrogen") testrelnutchl<-lm(ChlaLot~TN, data=streams) #plot(testrelnutchl) shapiro.test(residuals(testrelnutchl)) summary(testrelnutchl) abline(lm(streams$ChlaLot~ streams$TN)) points(birdstreams$ChlaLot~birdstreams$TN, pch=16, ) points(birdlessstreams$ChlaLot~birdlessstreams$TN, pch=5) legend("topleft", cex=0.8, legend=" linear regression p<0.0001, r2=0.77", bty="n") ###### 90 % CI library(nlme) require(lattice) require(mgcv) CI1 <- data.frame(TN=seq(0.111 ,5.550)) ic1 <- predict(testrelnutchl, CI1, interval = "confidence", level = 0.90,type="response") lines(CI1$TN, ic1[, 2], lty = 2) lines(CI1$TN, ic1[, 3], lty = 2) ## ##Total Phosphorous increase stream Chl plot(streams$ChlaLot~streams$TP, ylab="", xlab="System total phosphorous") testrelnutchlP<-lm(ChlaLot~TP, data=streams) summary(testrelnutchlP) abline(lm(ChlaLot~ TP,data=streams)) points(birdstreams$ChlaLot~birdstreams$TP, pch=16, ) points(birdlessstreams$ChlaLot~birdlessstreams$TP, pch=5) legend("topleft", cex=0.8, legend=" linear regression p<0.0001, r2=0.75", bty="n") #plot(testrelnutchlP) shapiro.test(residuals(testrelnutchlP)) CI2<-data.frame(TP=seq(from=0,to=1)) ic2<-predict(testrelnutchlP, CI2, interval = "confidence", level = 0.90,type="response") lines(CI2$ TP, ic2[, 2], lty = 2) lines(CI2$ TP, ic2[, 3], lty = 2) ##Total Nitrogen increase lentic Chl plot(lakes$ChlaLent~lakes$TN, ylab="phytoplankton Chl", xlab="System total nitrogen") testrelnutchllentic<-lm(ChlaLent~TN, data=lakes) summary(testrelnutchllentic) abline(lm(ChlaLent~ TN, data=lakes)) points(birdlakes$ChlaLent~birdlakes$TN, pch=16, ) points(birdlesslakes$ChlaLent~birdlesslakes$TN, pch=5) legend("topleft", cex=0.8, legend=" linear regression p<0.0001, r2=0.89", bty="n") #plot(testrelnutchllentic) shapiro.test(residuals(testrelnutchllentic)) CI3<- data.frame(TN=seq(from=0 ,to=4)) ic3<- predict(testrelnutchllentic, CI3, interval = "confidence", level = 0.90, type="response") lines(CI3$TN, ic3[, 2], lty = 2) lines(CI3$TN, ic3[, 3], lty = 2) ## ##Total Phosphorous increase lentic Chl plot(lakes$ChlaLent~lakes$TP, ylab="", xlab="System total phosphorous") testrelnutchlPlentic<-lm(ChlaLent~TP, data=lakes) summary(testrelnutchlPlentic) points(birdlakes$ChlaLent~birdlakes$TP, pch=16, ) points(birdlesslakes$ChlaLent~birdlesslakes$TP, pch=5) abline(lm(ChlaLent~ TP, data=lakes)) legend("topleft", cex=0.8, , legend=" linear regression p<0.0001, r2=0.99", bty="n") #plot(testrelnutchlPlentic) shapiro.test(residuals(testrelnutchlPlentic)) CI4<- data.frame(TP=seq(from=0 ,to=1)) ic4<- predict(testrelnutchlPlentic, CI4, interval = "confidence", level = 0.90, type="response") lines(CI4$TP, ic4[, 2], lty = 2) lines(CI4$TP, ic4[, 3], lty = 2) data$birds<-as.factor(data$birds) library(nlme) require(lattice) require(mgcv) streams<-data[which(data$lentvlot=="lotic" ),] strambirds<-streams[which(streams$birds=="1" ),] streampH<-streams[which(streams$pH>0 ),] vf5<-varIdent(form=~1|birds)## ident power Mphrich <- gamm(Consumer.taxa.diversity~s(pH), weights = vf5, method = "REML", data = streampH) summary(Mphrich$gam) summary(Mphrich$lme) ND <- data.frame(pH=seq(from=0,to=9),100) PM3 <- predict(Mphrich$gam,ND, se = TRUE) plot(Mphrich$Consumer.taxa.diversity, Mphrich$pH, pch=c(1,19)[Mphrich$birds],xlim=c(3, 8),ylim=c(0, 4), ylab="Taxa richness", xlab="Stream pH") lines(ND$pH,PM3$fit) lines(ND$pH,(PM3$fit+PM3$se), lty=2) lines(ND$pH,(PM3$fit-PM3$se), lty=2) points(streampH$Consumer.taxa.diversity~streampH$pH) points(strambirds$Consumer.taxa.diversity~strambirds$pH, pch=16) legend("topleft", cex=0.8, legend=" GAM p<0.0001, r2=0.44", bty="n") #### lentic pH lenticpH<-lakes[which(lakes$pH<8.9 ),] birdlenticpH<-lenticpH[which(lenticpH$birds=="1" ),] plot(lenticpH$Consumer.taxa.diversity~lenticpH$pH, ylab="", xlab="System pH", ylim=c(0, 5)) testphconslake<-lm(Consumer.taxa.diversity~pH, data=lenticpH) summary(testphconslake) abline(lm(Consumer.taxa.diversity~pH, data=lenticpH)) points(lenticpH$Consumer.taxa.diversity~lenticpH$pH ) points(birdlenticpH$Consumer.taxa.diversity~birdlenticpH$pH, pch=16) legend("topleft", cex=0.8, legend=" linear regression p<0.001, r2=0.49", bty="n") #plot(testphconslake) shapiro.test(residuals(testphconslake)) CI5<- data.frame(pH=seq(from=0 ,to=9)) ic5<- predict(testphconslake, CI5, interval = "confidence", level = 0.90, type="response") lines(CI5$pH, ic5[, 2], lty = 2) lines(CI5$pH, ic5[, 3], lty = 2)