Species accumulation curves

349 views
Skip to first unread message

Scott Martin

unread,
Aug 24, 2017, 11:40:18 AM8/24/17
to camtrapR
Hello,
   I've been using camtrapR to manage my data from 18 camera stations I ran for a year. This package has been awesome for organizing, sorting, and removing duplicate captures (seriously, after manually sorting 100gb of images, this got the job done better and faster.)

I'm starting to work on some analyses, and wanted to know if there was an easy way to do species accumulation curves per station, and/or any community indices (ex. Shannon's diversity index). My stations were set up in 3 different habitat types, and I'm trying to compare communities among the habitats. I was thinking that for the accumulation curves, if there isn't a built in function the quickest route would be to pull the date of capture for each species from the meta data, then sort those and take the first one to build a dataframe of first day of capture for every species per camera station that I could then plot. However, if anyone has a better idea I would love to hear it.

Thanks for any help,
-Scott Martin

Juergen Niedballa

unread,
Aug 28, 2017, 1:50:05 AM8/28/17
to camtrapR
Hi Scott,
you are right, there is no built-in function to give you species accumulation curves. I would do the accumulation curves just the way you suggested. Here's some code that might work for you (it requires the DateTimeOriginal column to be in POSIXct format.

data(recordTableSample)
subset_specaccum <- aggregate(x = recordTableSample$DateTimeOriginal,
                              by = list(recordTableSample$Station,
                                        recordTableSample$Species),
                              FUN = min)



Best regards,
Jürgen

Scott Martin

unread,
Sep 11, 2017, 9:31:30 AM9/11/17
to camtrapR
Thank you for your help, that code worked great. If anyone else is looking to do this, here is my full code for one habitat type:

#'nat' stands for camera traps placed in natural scrub habitat
#For reading in my data from a .csv, needed to add the as.POSIXct command to the aggregate function to switch back from factor

subset_specaccum_nat <- aggregate(x = as.POSIXct(images_natural$DateTimeOriginal),
                                   by = list(images_natural$Station,
                                             images_natural$Species),
                                   FUN = min)

#I had some erroneous dates for some images, so I sorted on date, then visually inspected and subsetted out to the 'corrected_nat' dataframe
#start_nat is the date I started the first camera running to start the plot on day 0
#In the plot command, I multiple the indexed captures by 7 as I had 7 cameras running in the habitat

sorted_nat<-subset_specaccum_nat[order(subset_specaccum_nat$x),]
corrected_nat<-sorted_nat[15:68,]
unique_cap_nat<-corrected_nat[!duplicated(corrected_nat[,2]),]
nat_cap_date<-round(as.numeric(sort(trunc.POSIXt(unique_cap_nat[,3], "day")))/86400)
start_nat<-round(as.numeric(as.POSIXct("2015-06-24", format="%Y-%m-%d"))/86400)
indexed_captures_nat<-(nat_cap_date-start_nat)
plot(x=indexed_captures_nat*7, y=(1:length(indexed_captures_nat)*7), type = "l", xlab = "trap nights", ylab = "Total number of species", main ="Species accumulation along natural dunes")

#to get shannon's diversity index and evenness index, I used the following code:
#Dunes_nat is the camera operations table
#the first section extracts the raw number of captures by species, and standardizes it using the total number of captures in that habitat
SurveyInfo_nat<-surveyReport(images_natural,Dunes_nat, stationCol="Station",setupCol='Setup_date',cameraCol = 'CameraID',retrievalCol = 'Retrieval_date',CTDateFormat="%d/%m/%Y",
                              CTHasProblems=TRUE, Xcol='utm_x',Ycol='utm_y',sinkpath='C:/Users/smart/Documents/R/dune_community')
captures_by_sp_nat<-as.numeric(SurveyInfo_nat$events_by_species[,2])
captures_by_sp_nat<-captures_by_sp_nat/sum(captures_by_sp_nat)


#S_nat is Shannon's Diversity index, while Evenness_nat is the evenness index
S_nat<-0
for (i in 1:length(captures_by_sp_nat)){
  S_nat<-S_nat+(captures_by_sp_nat[i]*log(captures_by_sp_nat[i]))
}
S_nat<-S_nat*-1
Evenness_nat<-S_nat/(log(length(captures_by_sp_nat)))

Hope this helps others!
Reply all
Reply to author
Forward
0 new messages