1

I have GPS locations of 5 animals. I am trying to calculate the 50% and 95% kernel distribution to determine size of core and periphery areas in km2 (as a table) and I also want to plot the contours (50% and 95%) for these data. Can someone help with the code please?

After loading the required packages, I have been able to generate the raster image using the code below, but not the contours or the size of these areas.

dat <- read.csv("data/GW1.csv", stringsAsFactors = FALSE)
dat <- dat[, 1:6]

dat1 <- dat %>% mutate(date = ymd_hm(Time)) %>% 
  make_track(Longitude, Latitude, date, id = ID, crs = CRS("+init=epsg:4326")) %>% 
  filter(y_ < 10) %>% 
  group_by(id) %>% nest() %>% 
  mutate(hr_kde_ud = map(data, hr_kde), 
         hr_kde_area = map_dbl(hr_kde_ud, hr_area), 
         hr_mcp = map_dbl(data, ~ hr_mcp(.) %>% hr_area %>% pull(area)))

# get the uds for first animal
raster::plot(dat1$hr_kde_ud[[1]]$ud)

I am a very basic R user, and I have not used the dput function before. So here, I provide of my column headers and the first twenty three rows:

Time                Latitude    Longitude
2019-06-12 15:00    4.8708      97.3669
2019-06-12 14:00    4.87185     97.37221667
2019-06-12 13:00    4.86825     97.37365
2019-06-12 12:00    4.874516667 97.3715
2019-06-12 11:00    4.875483333 97.369
2019-06-12 10:00    4.8749      97.3695
2019-06-12 9:00     4.873416667 97.3693
2019-06-12 8:01     4.868933333 97.37481667
2019-06-12 7:00     4.872683333 97.37523333
2019-06-12 6:00     4.8725      97.37618333
2019-06-12 5:00     4.872466667 97.37611667
2019-06-12 4:00     4.872316667 97.37696667
2019-06-12 3:00     4.875716667 97.37618333
2019-06-12 2:00     4.876083333 97.37525
2019-06-12 1:00     4.877633333 97.37145
2019-06-12 0:00     4.8786      97.37205
2019-06-11 23:00    4.879683333 97.37051667
2019-06-11 22:00    4.8795      97.37171667
2019-06-11 21:00    4.877583333 97.37091667
2019-06-11 20:00    4.878233333 97.36876667
2019-06-11 19:01    4.872666667 97.36978333
2019-06-11 18:00    4.87035     97.37046667
2019-06-11 17:00    4.86995     97.37108333

I expect to get a table that says:

50% 100 km2
95% 210 km2

And a raster image that shows the contours (note that no contours are shown in my image) enter image description here

Marco Sandri
  • 23,289
  • 7
  • 54
  • 58
EleMan
  • 43
  • 1
  • 7

1 Answers1

1

I ran a home range analysis using the adehabitatHR package on your data for MCPs (I added an id variable as the first column and excluded the Time column). You'll probably need a different CRS that is more relevant to your data set. The KDE should follow the same logic.

library(adehabitatHR)

setwd("C:\\Users\\User\\desktop")

mydata <- read.csv("test.csv", header = T)
head(mydata)


mydata.spdf <-
  SpatialPointsDataFrame(
    coords = as.data.frame(cbind(mydata$Longitude,
                                 mydata$Latitude)),
    data = mydata,
    proj4string = CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs")
  )

#'  The data are in a degree-based coordinate system. transform them to a meter-based coordinate system, for purposes of area calculations and such with home ranges
mydata.spdf <- spTransform(
  mydata.spdf,
  CRS(
    "+proj=aea +lat_1=20 +lat_2=-23 +lat_0=0 +lon_0=25 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs"
  )
)

# First: 95% MCP
mydata.mcp.95 <- mcp(mydata.spdf[, 1],
                     percent = 95,
                     unin = "m",
                     unout = "km2")
mydata.mcp.95

# Now: 50% MCP
mydata.mcp.50 <- mcp(mydata.spdf[, 1],
                     percent = 50,
                     unin = "m",
                     unout = "km2")
mydata.mcp.50
plot(mydata.mcp.95)
plot(mydata.mcp.50, add = T)

#' Kernel Density Estimate
mydata.Khref <- kernelUD(mydata.spdf[, 1], h = "LSCV")

#' measure the size of the home range using this kernel estimator
mydata.Khref.poly <- getverticeshr(mydata.Khref, percent = 95, unin = "m", unout = "km2")
print(mydata.Khref.poly)  # returns the area of each polygon
image(mydata.Khref)
plot(mydata.Khref.poly, add = T)
points(mydata.spdf, pch = 16)
adkane
  • 1,429
  • 14
  • 29
  • Thank you for running the MCPs. I can run MCP's no problem. While I can run a part of the KDE (to generate the map), I am unable to generate the contours for the map and the area estimates (50%, 90% and 95%). Help on that part of the code would be appreciated. Thank you. – EleMan Sep 03 '19 at 16:13
  • After running the code for mydata.spdf <- I get the following error message: Error in .local(obj, ...) : cannot derive coordinates from non-numeric matrix. What do I need to change here? Thanks @adkane – EleMan Sep 04 '19 at 04:51
  • Did you load in the adehabitatHR package successfully? The only change I made was to include an id column containing 1s and your Latitude and Longitude data. – adkane Sep 05 '19 at 10:48
  • My apologies for not seeing your answer earlier, but I just tried the code and I get an error message after running mydata.spdf <- SpatialPointsDataFrame( coords = as.data.frame(cbind(mydata$Longitude, mydata$Latitude)), data = mydata, proj4string = CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs") ) "Error in .local(obj, ...) : cannot derive coordinates from non-numeric matrix" – EleMan Sep 09 '19 at 05:14
  • Is the data loading in correctly? You'll notice I changed the path name to "User" but you'll have to change this for your own directory. – adkane Sep 11 '19 at 09:27
  • Hi, thanks for your reply - yes the data has been loading correctly. The error I now get is > mydata.mcp.95 <- mcp(mydata.spdf[, 1], + percent = 95, + unin = "m", + unout = "km2") Error in mcp(mydata.spdf[, 1], percent = 95, unin = "m", unout = "km2") : At least 5 relocations are required to fit an home range I don't understand why I get this error despite the data (including when I run mydata.spdf) being read correctly. – EleMan Sep 12 '19 at 12:05