I would like to run code similar this:
https://distancesampling.org/Distance/articles/web-only/CTDS/camera-distill.html, but where the sample fraction in the call to dht2 is a data.frame with 2 columns -- Sample.Label and fraction (because my fractions are different for each transect). I am trying to use this for Camera Trap Distance Sampling, where I would like to use multiple types of cameras, each with a different angle of view. See below for the exact code I ran. When I tried to run the call to dht2, R Studio crashed. I am running Intel(R) Core(TM) i5-10310U CPU @ 1.70GHz, 2208 Mhz, 4 Core(s), 8 Logical Processor(s), with Installed Physical Memory (RAM)
16.0 GB, Total Physical Memory 15.7 GB, Available Physical Memory 4.42 GB, Total Virtual Memory
18.1 GB, Available Virtual Memory 3.48 GB, and Page File Space 2.38 GB. I am assuming the reason for the crash is that the task was too computationally intensive for my computer, but I would like to hear what others think -- whether there's a way I can adjust the code to get around the limitations of my computer.
```# Code mostly copied from:
https://distancesampling.org/Distance/articles/web-only/CTDS/camera-distill.html# Data Input
trigger.events <- read.table(file="VideoStartTimes_FullDays.txt", header=TRUE)
trigger.events$date <- paste("2014",
sprintf("%02i", trigger.events$month),
sprintf("%02i", trigger.events$day),
sep="/")
trigger.events$time <- paste(sprintf("%02i", trigger.events$hour),
sprintf("%02i", trigger.events$minute),
sep=":")
trigger.events$datetime <- paste(trigger.events$date, trigger.events$time)
# Functions in the Activity Package
library(activity)
trigger.events$rtime <- gettime(trigger.events$datetime,
tryFormats = "%Y/%m/%d %H:%M",
scale = "radian")
act_result <- fitact(trigger.events$rtime, sample="data", reps=100)
# Adjustment for Temporal Availability
camera.operation.per.day <- 11.5
prop.camera.time <- camera.operation.per.day / 24
avail <- list(creation=data.frame(rate = act_result@act[1]/prop.camera.time,
SE = act_result@act[2]/prop.camera.time))
### DETECTION DATA ANALYSIS ###
DuikerCameraTraps <- read.csv(file="DaytimeDistances.txt", header=TRUE, sep="\t")
DuikerCameraTraps$Area <- DuikerCameraTraps$Area / (1000*1000)
DuikerCameraTraps$object <- NA
DuikerCameraTraps$object[!
is.na(DuikerCameraTraps$distance)] <- 1:sum(!
is.na(DuikerCameraTraps$distance))
# Distance Recording
breakpoints <- c(seq(0, 8, 1), 10, 12, 15, 21)
hist(DuikerCameraTraps$distance, breaks=breakpoints, main="Peak activity data set",
xlab="Radial distance (m)")
# Detection Function Fits
library(Distance)
trunc.list <- list(left = 2, right = 15)
mybreaks <- c(seq(2, 8, 1), 10, 12, 15)
conversion <- convert_units("meter", NULL, "square kilometer")
uni3 <- ds(DuikerCameraTraps, transect = "point", key = "unif", adjustment = "cos",
nadj = 3, convert_units = conversion,
cutpoints = mybreaks, truncation = trunc.list)
# Density Estimates
# Original code from website (this runs fairly quickly)
viewangle <- 42 # degrees
samfrac <- viewangle / 360
peak.uni.dens <- dht2(uni3, flatfile=DuikerCameraTraps, strat_formula = ~1,
sample_fraction = samfrac, er_est = "P2", multipliers = avail,
convert_units = conversion)
print(peak.uni.dens, report="density")
# My adjusted code (this causes R studio to crash)
# Based on pg. 18 of
https://cran.r-project.org/web/packages/Distance/Distance.pdf# where it says this regarding the sample fraction term of the model: proportion
# of the transect covered (e.g., 0.5 for one-sided line transects). May be specified
# as either a single number or a data.frame with 2 columns Sample.Label and fraction
# (if fractions are different for each transect)
# Created that 2-column data.frame to test this out
samfrac_variable <- data.frame(
Sample.Label = DuikerCameraTraps$Sample.Label,
fraction = DuikerCameraTraps$multiplier)
samfrac_variable <- edit(samfrac_variable) # In this step I edited ~ 30 of the
# values to be slightly smaller than the others, to mimic what I might be working
# with in my study
peak.uni.dens <- dht2(uni3, flatfile=DuikerCameraTraps, strat_formula = ~1,
sample_fraction = samfrac_variable, er_est = "P2", multipliers = avail,
convert_units = conversion)
print(peak.uni.dens, report="density")```