Problems calculating home ranges

Viewed 92

I am using GPS data and the ctmm package to calculate home ranges for multiple individuals. The code runs without errors, but does contain warnings and produces incorrect results. A colleague used the same code and the same csv file on another computer without issue. I have gone as far as to copy and paste their code from email to ensure it was correct and tried multiple versions of R studio and have yet to find the issue. I have included a small sample of the data. I have also included the code and warnings after the line of code where they occur.

Id              DateTime           Latitude      Longitude   YearMonth
151_259_45_1    11/14/2007 0:00   27.4922397    -97.6223344   2007-11    
151_259_45_1    11/14/2007 1:30   27.4922361    -97.6224614   2007-11    
151_259_45_1    11/14/2007 2:00   27.4922217    -97.6225903   2007-11   
151_259_45_1    12/4/2007 0:30    27.4851964    -97.6170192   2007-12    
151_259_45_1    12/4/2007 3:00    27.4846739    -97.6277725   2007-12   
151_259_45_1    12/4/2007 3:30    27.4854247    -97.6346442   2007-12    
151_259_45_1    1/3/2008 14:30    27.4840406    -97.6196067   2008-01   
151_259_45_1    1/3/2008 15:00    27.4840003    -97.6195778   2008-01   
151_259_45_1    1/3/2008 15:30    27.4840381    -97.6196153   2008-01
#####Packages
library(sp)
library(rgdal)
library(move)
library(amt)
library(ggmap)
library(dplyr)
library(purrr)
library(tidyr)
library(lubridate)
library(adehabitatLT)
library(adehabitatMA)
library(raster)
library(mapview)
library(sf)
library(FNN)
library(ctmm)

#########Import Data
df<-read.csv("C:collars_sub.csv")

names(df)
unique(df$Id)
unique(df$YearMonth)

df$id2<-paste0(df$Id, df$YearMonth)
unique(df$id2)

df$DateTime2<-as.POSIXct(df$DateTime, format="%m/%d/%Y %H:%M")
df$DateTime2

############AKDE  
deers<-df%>%
  make_track(Longitude,Latitude,DateTime2,id=id2, crs = CRS("+proj=longlat"))

deers<-transform_coords(deers, sp::CRS("+proj=aea +lat_1=29.5 +lat_2=45.5 +lat_0=23 +lon_0=-96 +x_0=0 +y_0=0 +datum=NAD83 +units=m +no_defs +ellps=GRS80 +towgs84=0,0,0"))

Warning messages:
In showSRID(uprojargs, format = "PROJ", multiline = "NO") :
  Discarded datum North_American_Datum_1983 in CRS definition,
 but +towgs84= values preserved

deers<-deers%>%
  nest(data=c(x_, y_, t_))

#########calculate akde
akde<-deers%>%
  mutate(hr_akde = map(data, ~ hr_akde(., fit_ctmm(., "ouf"))))

Warning message:
1: Problem with `mutate()` column `hr_akde`.
i `hr_akde = map(data, ~hr_akde(., fit_ctmm(., "ouf")))`.
i Discarded datum Unknown based on GRS80 ellipsoid in CRS definition,
 but +towgs84= values preserved

########reformat to calculate hr sizes
hr_sizes_2 <- akde %>% 
  pivot_longer(hr_akde, names_to = "estimator", values_to = "hr")

#########calculate hr area
hr_sizes_2 <- hr_sizes_2 %>% 
  mutate(hr_area = map(hr, hr_area)) %>% 
  unnest(cols = hr_area)

###########We're not interested in LCI and UCI right now... get rid of

hr_sizes_3<-hr_sizes_2[hr_sizes_2$what=="estimate",]

#########look at each HR
for (i in 1:8) {
  telem<-as_telemetry(hr_sizes_3$data[[i]])
  plot(telem, UD=hr_sizes_3$hr[[i]]$akde, 
       main=paste(hr_sizes_3$id[[i]],hr_sizes_3$area[[i]]*3.861e-7),  cex=.5)
  compass()
}
1 Answers

This expands on my comment.

When I asked about package versions, I said you should see if you have the same versions as the other R-installed computer. The computer where you said this code works as expected. If their versions aren't the most recent that might be the difference.

When I look at the functions you used and the libraries you called, there are a lot of conflicts. However, when I looked closer, I noticed that you called libraries that are not needed.

The libraries needed for this code to work are here, along with those that are not needed commented out:

##### Packages
# library(sp)
# library(rgdal)
# library(move)
library(amt)
# library(ggmap)
library(dplyr)
library(purrr)
library(tidyr)
# library(lubridate)
# library(adehabitatLT)
# library(adehabitatMA)
# library(raster)
# library(mapview)
# library(sf)
# library(FNN)
library(ctmm)

If there is more code, make sure you only add the libraries you actually need. Sometimes this gets a bit convoluted (as you try different packages, for example).

I get a lot of deprecated errors when I run this code. I receive other warnings as well. If I run the code too quickly I get errors that the code didn't work. However, I run the line again and it works.

Since you know how this should look when it's finished, I do wonder if this is the output you expect:

enter image description here

I changed the limits so you could see the plot a bit better

enter image description here

If this is what you expected, then only use the libraries that are listed here, and wait for each function to complete before running the next one. I am guessing that the package amt isn't really stable and is doing a ton of work in the background.

Related