library(overlap) library(activity) library(ggplot2) library(CircMLE) setwd("C:/Users/Oscar/Documents/Maremani") #Read in CT data from waterholes water <- read.csv2("water.csv") #Read in CT data from roads and trails away <- read.csv2("fusion_data.csv") #Convert time to radians for water dataset water$Time2=as.numeric(water$Time2) timeRadwater <- water$Time2 * 2 * pi #read in CT data for leopards at waterhole wleopard <- timeRadwater[water$Species == 'pardus'] #plot activity pattern for leopard at waterhole - use adjust = 1 for species with more than 75 records (Dhat4) densityPlot(wleopard, rug=TRUE, main="Leopard", adjust = 1) #read in CT data for spotted at waterhole wspotted <- timeRadwater[water$Species == 'crocuta'] densityPlot(wspotted, rug=TRUE, main="Spotted hyena", adjust = 1) #read in CT data for wild dog at waterhole wdog <- timeRadwater[water$Species == 'pictus'] #use adjust=0.8 for species with less than 75 records (Dhat1) densityPlot(wdog, rug=TRUE, adjust = 0.8, main="African wild dog") #convert time to radians for away from water dataset away$Time.delta=as.numeric(away$Time.delta) timeRadaway <- away$Time.delta * 2 * pi leopard <- timeRadaway[away$Species == 'pardus'] densityPlot(leopard, rug=TRUE, main="Leopard", adjust = 1) spotted <- timeRadaway[away$Species == 'crocuta'] densityPlot(spotted, rug=TRUE, main="Spotted hyena", adjust = 1) brown <- timeRadaway[away$Species == 'brunnea'] densityPlot(brown, rug=TRUE, main="Brown hyena", adjust = 1) dog <- timeRadaway[away$Species == 'pictus'] densityPlot(dog, rug=TRUE, main="African wild dog", adjust = 0.8) ############################################################################ #HR_test to assess if a random activity pattern is exhibited over a circadian cycle HR_test(wdog, original = F, iter = 9999) HR_test(wleopard, original = F, iter = 9999) HR_test(wspotted, original = F, iter = 9999) HR_test(dog, original = F, iter = 9999) HR_test(leopard, original = F, iter = 9999) HR_test(spotted, original = F, iter = 9999) HR_test(brown, original = F, iter = 9999) ############################################################################### #Overlap analysis between same species at and away from artificial waterhole ############################################################################### est <- overlapEst(wdog, dog, type="Dhat1") est overlapPlot(wdog,dog,rug=TRUE, main="African wild dog") legend('topright', c("artificial waterhole (n = 43)", "away from artificial waterhole (n = 31)"), lty=c(1,2), col=c(1,4), bty='n', cex=0.7) text(x=15, y=0.11, labels="Δ = 0.70 (0.49 - 0.80), P = 0.003", col="black",cex=0.8) dogboot <- bootstrap(wdog, dog, 10000, type="Dhat1") #Gives you upper and lower confidence levels - use basic0 bootCI(est, dogboot) # Use sample = "model" for smaller samples (under 100) and use "data" for the bigger samples # in fitact use adj = 1.25 for Dhat1 and adj=1 for Dhat4 wdogfit <- fitact(wdog, wt=NULL, reps = 10000, adj = 1.25, sample = "model") dogfit <- fitact(dog, wt=NULL, reps=10000, adj=1.25, sample = "model") compareCkern(wdogfit, dogfit) compareAct(list(wdogfit,dogfit)) ############################################################################### est2 <- overlapEst(wleopard, leopard, type="Dhat4") est2 overlapPlot(wleopard,leopard, rug=TRUE,main="Leopard") legend('topright', c("artificial waterhole (n = 1382)", "away from artificial waterhole (n = 232)"), lty=c(1,2), col=c(1,4), bty='n', cex=0.7) text(x=12, y=0.06, labels="Δ = 0.87 (0.82 - 0.90), P = 0.2", col="black",cex=0.8) leopardboot <- bootstrap(wleopard, leopard, 10000, type="Dhat4") bootCI(est2, leopardboot) wleopardfit <- fitact(wleopard,wt=NULL, reps=10000, adj=1, sample="data") leopardfit <- fitact(leopard, wt=NULL, reps=10000, adj=1, sample="data") compareCkern(wleopardfit, leopardfit) compareAct(list(wleopardfit, leopardfit)) ############################################################################### est3 <- overlapEst(wspotted, spotted, type="Dhat4") est3 overlapPlot(wspotted,spotted,rug=TRUE, main="Spotted hyena") legend('topright', c("artificial waterhole (n = 1229)", "away from artificial waterhole (n = 115)"), lty=c(1,2), col=c(1,4), bty='n', cex=0.7) text(x=13, y=0.06, labels="Δ = 0.85 (0.79 - 0.90), P = 0.8", col="black",cex=0.8) spottedboot <- bootstrap(wspotted, spotted, 10000, type="Dhat4") bootCI(est3, spottedboot) wspottedfit <- fitact(wspotted,wt=NULL, reps=10000, adj=1, sample="data") spottedfit <- fitact(spotted, wt=NULL, reps=10000, adj=1, sample="data") compareCkern(wspottedfit, spottedfit) compareAct(list(wspottedfit, spottedfit)) ############################################################################### #Overlap analysis away from artificial wateherholes ############################################################################### est5 <- overlapEst(spotted,brown, type="Dhat4") est5 overlapPlot(spotted,brown, rug=TRUE,main="Away from artificial waterholes") legend('topright', c("Spotted hyena (n = 115)", "Brown hyena (n = 361)"), lty=c(1,2), col=c(1,4), bty='n', cex=0.8) text(x=12, y=0.06, labels="Δ = 0.88 (0.83 - 0.96), P = 0.06", col="black",cex=0.8) boot5 <- bootstrap(spotted,brown,10000,type="Dhat4") bootCI(est5,boot5) brownfit <- fitact(brown, wt=NULL, reps=10000, adj=1, sample="data") compareCkern(spottedfit, brownfit) compareAct(list(spottedfit, brownfit)) ############################################################################### est6 <- overlapEst(spotted, dog, type="Dhat1") est6 overlapPlot(spotted, dog,rug=TRUE, main="Away from artificial waterholes") legend('topright', c("Spotted hyena (n = 115)", "African wild dog (n = 43)"), lty=c(1,2), col=c(1,4), bty='n', cex=0.8) text(x=15, y=0.12, labels="Δ = 0.56 (0.38 - 0.65), P = 0.0002", col="black",cex=0.8) boot6 <- bootstrap(spotted,dog,10000,type="Dhat1") bootCI(est6,boot6) compareCkern(spottedfit, dogfit) compareAct(list(spottedfit,dogfit)) ############################################################################## est7 <- overlapEst(brown, dog, type="Dhat1") est7 overlapPlot(brown, dog,rug=TRUE,main="Away from artificial waterholes") legend('topright', c("Brown hyena (n = 361)", "African wild dog (n = 43)"), lty=c(1,2), col=c(1,4), bty='n', cex=0.8) text(x=15, y=0.12, labels="Δ = 0.51 (0.34 - 0.60), P = 0.008", col="black",cex=0.8) boot7 <- bootstrap(brown,dog,10000,type="Dhat1") bootCI(est7,boot7) compareCkern(brownfit, dogfit) compareAct(list(brownfit,dogfit)) ############################################################################# est8 <- overlapEst(leopard,brown, type="Dhat4") est8 overlapPlot(leopard,brown,rug=TRUE, main="Away from artificial waterholes") legend('topright', c("Leopard (n = 232)", "Brown hyena (n = 361)"), lty=c(1,2), col=c(1,4), bty='n', cex=0.8) text(x=12, y=0.07, labels="Δ = 0.82 (0.76 - 0.87), P = 0.1", col="black",cex=0.8) boot8 <- bootstrap(leopard,brown,10000,type="Dhat4") bootCI(est8,boot8) compareCkern(leopardfit, brownfit) compareAct(list(leopardfit, brownfit)) ############################################################################### est9 <- overlapEst(leopard,spotted, type="Dhat4") est9 overlapPlot(leopard,spotted, rug=TRUE,main="Away from artificial waterholes") legend('topright', c("Leopard (n = 232)", "Spotted hyena (n = 115)"), lty=c(1,2), col=c(1,4), bty='n', cex=0.8) text(x=12.5, y=0.06, labels="Δ = 0.87 (0.82 - 0.95), P = 0.77", col="black",cex=0.8) boot9 <- bootstrap(leopard,spotted,10000,type="Dhat4") bootCI(est9,boot9) compareCkern(leopardfit, spottedfit) compareAct(list(leopardfit, spottedfit)) ############################################################################### est10 <- overlapEst(leopard, dog, type="Dhat1") est10 overlapPlot(leopard, dog, rug=TRUE,main="Away from artificial waterholes") legend('topright', c("Leopard (n = 232)", "African wild dog (n = 43)"), lty=c(1,2), col=c(1,4), bty='n', cex=0.8) text(x=15, y=0.11, labels="Δ = 0.64 (0.47 - 0.74), P = 0.0008", col="black",cex=0.8) boot10 <- bootstrap(leopard,dog,10000,type="Dhat1") bootCI(est10,boot10) compareCkern(leopardfit, dogfit) compareAct(list(leopardfit,dogfit)) ############################################################################## #Overlap analysis between species at artificial waterholes ############################################################################### est11 <- overlapEst(wleopard, wdog, type="Dhat1") est11 overlapPlot(wleopard,wdog, rug=TRUE, main="At artificial waterholes") legend('topright', c("Leopard (n = 1382)", "African wild dog (n = 31)"), lty=c(1,2), col=c(1,4), bty='n', cex=0.8) text(x=11.7, y=0.05, labels="Δ = 0.66 (0.54 - 0.81), P = 0.9", col="black",cex=0.8) boot11 <- bootstrap(wleopard,wdog,10000,type="Dhat1") bootCI(est11,boot11) compareCkern(wleopardfit, wdogfit) compareAct(list(wleopardfit,wdogfit)) ############################################################################## est12 <- overlapEst(wspotted,wleopard, type="Dhat4") est12 overlapPlot(wspotted,wleopard, rug=TRUE, main="At artificial waterholes") legend('topright', c("Spotted hyena (n = 1229)", "Leopard (n = 1382)"), lty=c(1,2), col=c(1,4), bty='n', cex=0.8) text(x=12.5, y=0.06, labels="Δ = 0.85 (0.82 - 0.89), P = 0.1", col="black",cex=0.8) boot12 <- bootstrap(wspotted,wleopard,10000,type="Dhat4") bootCI(est12,boot12) compareCkern(wspottedfit, wleopardfit) compareAct(list(wspottedfit, wleopardfit)) ############################################################################### est4 <- overlapEst(wspotted,wdog, type="Dhat1") est4 overlapPlot(wspotted,wdog,main="At artificial waterholes", rug=TRUE) legend('topright', c("Spotted hyena (n = 1229)", "African wild dog (n = 43)"), lty=c(1,2), col=c(1,4), bty='n', cex=0.8) text(x=12.5, y=0.08, labels="Δ = 0.63 (0.48 - 0.76), P = 0.5", col="black",cex=0.8) boot4 <- bootstrap(wspotted,wdog, 10000, type = "Dhat1") bootCI(est4, boot4) compareCkern(wspottedfit, wdogfit) compareAct(list(wspottedfit,wdogfit))