############################################# ###### Distances Moved Analysis Script ###### ############################################# dframe1<-read.csv(file.choose()) ## Load in raw butterfly capture data: "RawButterflyCaptureData.csv" names (dframe1) summary (dframe1) ## TOTAL DISTANCES MOVED PER INDIVIDUAL ## ## Forest individuals ## dframe1ForestNew<- dframe1[(dframe1$Habitat=="F")&(dframe1$NewRecap=="New"),] summary (dframe1ForestNew) length (dframe1ForestNew$UniqueNoALL) UniqueFor<-unique (dframe1ForestNew$UniqueNoALL) SubsetF<- dframe1 [dframe1$UniqueNoALL %in% (UniqueFor),] SubsetAll <- SubsetF [SubsetF$NewRecap=="Recap",] summary (SubsetAll) UniqueSubsetAll<-unique (SubsetAll$UniqueNoALL) UniqueSubsetAll length (UniqueSubsetAll) ForestDist<- SubsetAll[SubsetAll$Distance > 0,] TotDist<-sum (ForestDist$Distance) TotDist Distperind<- tapply(ForestDist$Distance, ForestDist$UniqueNoALL, sum) Distperind ## total distance moved by each individual that moved to a different trap mean (Distperind) # 121.4 m: mean total distance moved across individuals that moved to a different trap write.csv(Distperind,file='ForestDistances.csv') # write csv and combine with plantation individuals ## Plantation individuals ## dframe1PlanNew<- dframe1[(dframe1$Habitat=="P")&(dframe1$NewRecap=="New"),] summary (dframe1PlanNew) length (dframe1PlanNew$UniqueNoALL) UniquePlan<-unique (dframe1PlanNew$UniqueNoALL) SubsetP<- dframe1 [dframe1$UniqueNoALL %in% (UniquePlan),] SubsetAllP <- SubsetP [SubsetP$NewRecap=="Recap",] summary (SubsetAllP) UniqueSubsetAllP<-unique (SubsetAllP$UniqueNoALL) UniqueSubsetAllP length (UniqueSubsetAllP) PlanDist<- SubsetAllP[SubsetAllP$Distance > 0,] TotDistP<-sum (PlanDist$Distance) TotDistP DistperindP<- tapply(PlanDist$Distance, PlanDist$UniqueNoALL, sum) DistperindP mean (DistperindP) # 114.5 m: mean total distance moved across individuals that moved to a different trap write.csv(DistperindP,file='PlanDistances.csv') # write csv and combine with forest individuals ######################################################################## ### MANN-WHITNEY U TEST ### dframe2<-read.csv(file.choose()) ## Load csv with total distances moved: "TotalDistances20Species.csv" names (dframe2) wilcox.test (dframe2$TotDistF, dframe2$TotDistP, exact= TRUE, conf.int = TRUE) # Results: W = 14813, p-value = 0.04695 ################################################################# ### TOTAL DISTANCES MOVED PER INDIVIDUAL - SPECIES RECAPTURED IN BOTH HABITATS ### ### Analysis restricted to only those species recaptured in both habitats (n=12) ### SubsetSpecies<- c("AMPH", "CHBE", "DINE", "DOEV", "ELNE", "ELPA", "MELE", "MYAN", "MYHO", "MYMI", "MYOR", "NELO") Subset12<- dframe1 [dframe1$SpeciesCode %in% (SubsetSpecies),] unique(Subset12$SpeciesCode) ## Forest individuals ## dframe1ForestNew<- Subset12[(Subset12$Habitat=="F")&(Subset12$NewRecap=="New"),] summary (dframe1ForestNew) length (dframe1ForestNew$UniqueNoALL) UniqueFor<-unique (dframe1ForestNew$UniqueNoALL) SubsetF<- dframe1 [dframe1$UniqueNoALL %in% (UniqueFor),] SubsetAll <- SubsetF [SubsetF$NewRecap=="Recap",] summary (SubsetAll) UniqueSubsetAll<-unique (SubsetAll$UniqueNoALL) UniqueSubsetAll length (UniqueSubsetAll) ForestDist<- SubsetAll[SubsetAll$Distance > 0,] TotDist<-sum (ForestDist$Distance) TotDist Distperind<- tapply(ForestDist$Distance, ForestDist$UniqueNoALL, sum) Distperind ## total distance moved by each individual that moved to a different trap mean (Distperind) # 127.9 m: mean total distance moved across individuals that moved to a different trap write.csv(Distperind,file='ForestDistancesSub.csv') # write csv and combine with plantation individuals ## Plantation individuals ## dframe1PlanNew<- Subset12[(Subset12$Habitat=="P")&(Subset12$NewRecap=="New"),] summary (dframe1PlanNew) length (dframe1PlanNew$UniqueNoALL) UniquePlan<-unique (dframe1PlanNew$UniqueNoALL) SubsetP<- dframe1 [dframe1$UniqueNoALL %in% (UniquePlan),] SubsetAllP <- SubsetP [SubsetP$NewRecap=="Recap",] summary (SubsetAllP) UniqueSubsetAllP<-unique (SubsetAllP$UniqueNoALL) UniqueSubsetAllP length (UniqueSubsetAllP) PlanDist<- SubsetAllP[SubsetAllP$Distance > 0,] TotDistP<-sum (PlanDist$Distance) TotDistP DistperindP<- tapply(PlanDist$Distance, PlanDist$UniqueNoALL, sum) DistperindP mean (DistperindP) # 116: mean total distance moved across individuals that moved to a different trap write.csv(DistperindP,file='PlanDistancesSub.csv') # write csv and combine with forest individuals ### MANN-WHITNEY U TEST ### dframe3<-read.csv(file.choose()) ## Load csv with total distances moved script - only for 12x species recaptured in both habitats: "TotalDistances12Species.csv" ## names (dframe3) wilcox.test (dframe3$TotDistF, dframe3$TotDistP, exact= TRUE, conf.int = TRUE) # Results: W = 12244, p-value = 0.01615