Exercise 1 solution

#install.packages("devtools")
#devtools::install_github("arcaravaggi/remBoot")

library(remBoot)
library(readxl)
library(dplyr)
library(activity)

Preparing data

camDat <- read_excel("camDat.xlsx")
camDat<-as.data.frame(camDat)
head(camDat)
##        Site count      dist     theta
## 1 Southwell     1 0.0023500 0.6981317
## 2 Southwell     1 0.0015200 0.6283185
## 3 Southwell     3 0.0005800 0.7446738
## 4 Southwell     4 0.0008075 0.7243116
## 5 Southwell     2 0.0009950 0.4886922
## 6 Southwell     1 0.0007000 0.3839724
camDat$Site[camDat$Site=="Southwell"] <- 1
camDat$Site[camDat$Site=="Brackenhurst2017"] <- 2
camDat$Site<-as.integer(camDat$Site)
camDat$count<-as.integer(camDat$count)
grpDat <- split_dat(camDat)

Calculating activity

acti_Brack <- read_excel("activity_Brack.xlsx")
head(acti_Brack)
## # A tibble: 6 × 3
##   Site             Date                Time    
##   <chr>            <dttm>              <chr>   
## 1 Brackenhurst2017 2017-09-20 00:00:00 05:04:00
## 2 Brackenhurst2017 2017-09-11 00:00:00 21:53:00
## 3 Brackenhurst2017 2017-09-28 00:00:00 23:55:00
## 4 Brackenhurst2017 2017-09-25 00:00:00 23:33:00
## 5 Brackenhurst2017 2017-10-01 00:00:00 04:21:00
## 6 Brackenhurst2017 2017-09-26 00:00:00 02:16:00

Time to radians

rad_Brack <- gettime(acti_Brack$Time, tryFormats =  "%H:%M:%S", scale = "radian")
rad_Brack
##  [1] 1.3264502 5.7290433 6.2613687 6.1653756 1.1388273 0.5934119 0.8857546
##  [8] 0.8683013 0.7853982 5.5326937 5.6155969 0.4843289 5.4890605 0.9861110
## [15] 0.3490659 5.4061574 5.3887041 0.8203047 6.1042891 5.3058009 5.7115900

!!! Depending on how excel/R interprets the data, it may be necessary to choose different “tryFormats” options. If excel adds default date, try “%Y-%m-%d %H:%M:%S”, if it saved only hours, put “%H:%M:%S”.

Identify the first and the last video

#identifying the first video
noon_time <- pi
#filter the times after noon
times_after_noon2 <- rad_Brack[rad_Brack > noon_time]
#choose the lowest- beginning of activity
first_video2 <- min(times_after_noon2)
first_video2
## [1] 5.305801
#identifying the last video
#filter the times before noon
times_before_noon2 <- rad_Brack[rad_Brack < noon_time]
#choose the highest
last_video2 <- max(times_before_noon2)
last_video2
## [1] 1.32645

First video: 5.305801

Last video: 1.32645

Fitting activity model

act2<-fitact(rad_Brack,bounds=c(first_video2,last_video2), sample = "data")
act2

act=0.65

se=0.12

Plotting activity

plot(act2,centre="night")

Calculating day range

s_Brack<- 0.50 #speed for Brack in km/h

v2 <- 0.65 * s_Brack
v2
## [1] 0.325

Trapping effort

deployment_Brack <- read_excel("Brack_cam_deployment.xlsx")
head(deployment_Brack)
## # A tibble: 6 × 6
##   Habitat Site             Camera_ID Nights_active      X      Y
##   <chr>   <chr>            <chr>             <dbl>  <dbl>  <dbl>
## 1 Rural   Brackenhurst2017 Brk221                1 469561 352140
## 2 Rural   Brackenhurst2017 Brk222                1 470379 352235
## 3 Rural   Brackenhurst2017 Brk406                1 469575 352052
## 4 Rural   Brackenhurst2017 Brk204                2 470223 352188
## 5 Rural   Brackenhurst2017 Brk103                5 469617 352012
## 6 Rural   Brackenhurst2017 Brk104                5 470080 352480

Nights active

days_Brack <- sum(as.numeric(deployment_Brack$Nights_active))
days_Brack
## [1] 723

Multiply by hours active

#install.packages("astroFns")
library(astroFns)

f_vid<-rad2hms(rad = 5.305801,places = 0)
l_vid<-rad2hms(rad = 1.32645,places = 0)

f_vid
## [1] "20:16:00"
l_vid
## [1] "05:04:00"

Hour gap: 20:16->5:04=9h

tm2<- days_Brack*9
tm2
## [1] 6507

Calculate density

rem(grpDat[[2]], tm = 6507, v = 0.32)
## [1] 9.317734

And standard deviation

output <- remBoot(grpDat[[2]], tm = 6507, v = 0.32,nboots = 1000, error_stat = c("sd"))
output
## $sd
## $sd[[1]]
## [1] 3.496374

Density of hedgehogs is 9 individuals per km2, noticeably less than in urban environment (Southwell).