#Author: Hannah Edwards #Population density estimates of spotted hyaena (Crocuta crocuta) in two KwaZulu-Natal protected areas #SECR model for the uMkhuze 2019 density estimate with a 20km buffer #There are three input files for each SECR model: #"..._td_ml.txt" Trap deployment file - contains the ID number of each detector (camera trap station), the X and Y coordinates of the spatial location of the camera trap stations, and whether the camera station was active (1; at least one camera active) or non-active (0; both cameras inactive) on each sampling occasion. #"..._ac_ml.txt" Capture history file - contains the animal identity, camera trap station, and sampling occasion of captures of identified spotted hyaenas. #"...SS.csv" state-space file - contains a binary matrix of suitable (1) and unsuitable (0) habitat for spotted hyaenas within the study site. I removed all "unsuitable" habitat before importing the state-space file into R. #Clear R workspace rm(list=ls()) #Load the secr library library(secr) library(sp) library(rgdal) #Set the working directory - 20,000 buffer setwd("C:/Users/hedwa/Desktop/Hyaena Project/SECR Models/S3_uMkhuze_2019_SECR/SECR_Inputs_S3_uMkhuze_2019_20000 buffer") #Load the secr input data trap.obj<-read.traps('S3_20190811_20191004_Hyaena_Spotted_td_ml.txt',detector="proximity", binary.usage=T) #Remember to remove all non-habitat rows from SS csv and then delete 'Habitat' column #change X-Coord and Y_Coord to X and Y msk<-read.mask(file= 'S3_20190811_20191004_Hyaena_Spotted_SS.csv',spacing=500,header=T) ch<-read.capthist("S3_20190811_20191004_Hyaena_Spotted_ac_ml.txt","S3_20190811_20191004_Hyaena_Spotted_td_ml.txt", detector="proximity",fmt="trapID",noccasions=55) #Run the model - Keep sigma and g0 constant model_null <- secr.fit(ch, model = list(D ~ 1, g0 ~ 1, sigma ~ 1), mask = msk, detectfn = 0, hcov = NULL, trace = F, method = "Nelder-Mead",control = list(maxit = 9999)) model_null