[R-sig-eco] R crashes while calculating BRB (Biased Random Bridge)

André Zehnder andrezehnder at hotmail.com
Tue Jun 16 10:29:27 CEST 2015


Hi Nick,

I had (supposably) the same issue just a few day ago. While the code ran
without any problems for some of the datasets, R suddenly crashed during the
computation of other datasets. In my case, the problem was the following:

When the temporal difference of at least two locations is smaller than the
chosen tau-value, BRB cannot split the step into its intervals (defined
through tau) and thus crashes. Therefore I had to ensure that the smallest
occurring temporal difference is larger than the tau-value. So, even if the
vast majority of your dataset has sampling intervals that are coarser than
your tau-value, it may be that only a few ones do not match this
restriction. Perhaps it solves your issue when you check all of your
sampling intervals and delete some of them, if necessary.

You could check the sampling intervals for example with this code:

for (i in 1:nrow(anim)) {
  anim$timeDiff[i] <- round(difftime(anim$timestamp[i+1],anim$timestamp[i],
tz="UTC", units="mins"), digits=0)
}
samplingI <- vector()
samplingI <- anim$timeDiff
samplingI <- samplingI[2:length(samplingI)] # First value of timeDiff is NA

plot(table(samplingI), type="h", xlim=c(),col=4, ylab="frequency",
xlab="sampling interval [min]")

anim is the name of a data.frame and timestamp a column that contains a
POSIXct-timestamp (format = "%Y-%m-%d %H:%M:%S" , tz = "UTC").

Best regards,
André

-----Ursprüngliche Nachricht-----
Von: R-sig-ecology [mailto:r-sig-ecology-bounces at r-project.org] Im Auftrag
von Nick van Doormaal
Gesendet: Dienstag, 16. Juni 2015 10:16
An: r-sig-ecology at r-project.org
Betreff: [R-sig-eco] R crashes while calculating BRB (Biased Random Bridge)

Dear list members,

The past few weeks I've been troubled (and frustrated) about calculating the
BRB in R, using adehabitatHR. For some reason, unknown to me, the program
just crashes while calculating the BRB. However, this does not happen for
all of them. The error occurs for about 10-20% of the data I used so far.

I've included a part of the dataset and the R-code, I hope it might be of
use to you in helping me solving this problem. One interesting that I've
found out so far is that the code works just fine using the first 1000
relocations. However, I don't think this is a data-size issue, as some other
datasets are much larger and working without any problem.

Thank you for your time and effort. If there's anything I need to provide,
please let me know.

Kind regards,

Nick


##R CODE FOR BRB 16-6-2015##
##LOADING ALL PACKAGES
library(ade4)
library(shapefiles)
library(adehabitatHS)
library(maptools)
library(rgdal)
library(raster)

##LOAD DATA
Dura <- readShapeSpatial("Dura, Jan 25 2013 (WGS 84).shp")

Dura$DateTime <- substr(Dura$Descriptio, 1, 19) Dura$Date <-
substr(Dura$Descriptio, 1, 10) Dura$Time <- substr(Dura$Descriptio, 12, 19)

##SET COORDINATE SYSTEM
proj4string(Dura) = CRS("+init=epsg:4326") #4326 IS LAT LONG WGS84

##TRANSFORM COORDINATES
Dura <- spTransform(Dura, CRS("+init=epsg:32736")) #UTM36S

##CREATE A LTRAJ-CLASS
Dura2 <- Dura[!duplicated(Dura$DateTime), ] Dura2$Descriptio <- NULL Dura.da
<- as.character(Dura2$DateTime) Dura.da <-
as.POSIXct(strptime(as.character(Dura2$DateTime),"%Y/%m/%d %H:%M:%S"))
Dura.df <- as.data.frame(Dura2) Dura.xy <- coordinates(Dura2) Dura.ltraj <-
as.ltraj(xy =Dura.xy, date = Dura.da, id = Dura.df$Date)

plot(Dura.ltraj[1])

##RUN THE MODEL
Dura.vv = BRB.D(Dura.ltraj[1], Tmax = 60, Lmin = 0) Dura.est = Dura.ltraj[1]

Dura.id <- BRB(Dura.est, D = Dura.vv, Tmax = 60, tau = 5, Lmin = 0, hmin=25,
grid = 100, type=("ID"), same4all=TRUE, extent=0.2, maxt = 20,
filtershort=TRUE) Dura.rd <- BRB(Dura.est, D = Dura.vv, Tmax = 60, tau = 5,
Lmin = 0, hmin=25, grid = 100, type=("RD"), same4all=TRUE, extent=0.2, maxt
= 20, filtershort=TRUE) Dura.ud <- BRB(Dura.est, D = Dura.vv, Tmax = 60, tau
= 5, Lmin = 0, hmin=25, grid = 100, type=("UD"), same4all=TRUE, extent=0.2,
maxt = 20, filtershort=TRUE)

##END
 		 	   		  
_______________________________________________
R-sig-ecology mailing list
R-sig-ecology at r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-ecology



More information about the R-sig-ecology mailing list