Resource Selection Functions (RSF) with amt

Johannes Signer

2020-04-23

About

This vignette briefly introduces how one can fit a Resource-Selection Function (RSF) with the amt package. We will be using the example data of one red deer from northern Germany and one covariate: a forest cover map.

Getting the data ready

First we load the required libraries and the relocation data (called deer)

library(amt)
data("deer")
deer
## # A tibble: 826 x 4
##          x_       y_ t_                  burst_
##  *    <dbl>    <dbl> <dttm>               <dbl>
##  1 4314068. 3445807. 2008-03-30 00:01:47      1
##  2 4314053. 3445768. 2008-03-30 06:00:54      1
##  3 4314105. 3445859. 2008-03-30 12:01:47      1
##  4 4314044. 3445785. 2008-03-30 18:01:24      1
##  5 4313015. 3445858. 2008-03-31 00:01:23      1
##  6 4312860. 3445857. 2008-03-31 06:01:45      1
##  7 4312854. 3445856. 2008-03-31 12:01:11      1
##  8 4312858. 3445858. 2008-03-31 18:01:55      1
##  9 4312745. 3445862. 2008-04-01 00:01:24      1
## 10 4312651. 3446024. 2008-04-01 06:00:54      1
## # … with 816 more rows

Next, we have to get the environmental covariates. A forest layer is included in the package. Note, that this a regular RasterLayer.

data("sh_forest")
sh_forest
## class      : RasterLayer 
## dimensions : 720, 751, 540720  (nrow, ncol, ncell)
## resolution : 25, 25  (x, y)
## extent     : 4304725, 4323500, 3437725, 3455725  (xmin, xmax, ymin, ymax)
## crs        : +proj=laea +lat_0=52 +lon_0=10 +x_0=4321000 +y_0=3210000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs 
## source     : memory
## names      : sh.forest 
## values     : 1, 2  (min, max)

Prepare Data for RSF

Random Points

Before fitting a RSF we have to do some data preparation. We have to generate random points, points that we think the animal could have used. The random points define the availability domain. In amt the function random_points is designed to do just that. The function can be used in 3 different ways, depending to the type of object that is passed to the function call.

  1. A track_* (such as the deer object) can be passed to the function random_points. The function then calculates a home range (the home-range estimator can be controlled with argument hr). Within this home range n random points are generated. The default value of n is ten times the number of present points.
  2. If a hr-object (i.e., the result of a home-range estimation in amt) is passed to random_points, points are generated within the home range. This allows to generate random points within any home range that was previously estimated in amt. Note, that this could be a home range of multiple animals. In this case, the function random_points has one additional argument called presence. This argument takes a trk_* with the presence points and adds these points for convenience to the random points.
  3. A SpatialPolygons*-object or sf-object. The latter must contain POLYGONs or MULTIPOLYGONs as features. This can be useful in situation where a home range needs to be buffered, or when other geographical features are considered as the availability domain. As before, this method for random_points also takes the argument presence to optionally add the observed points to the output.

Lets now illustrate the three different situations. First we take random points from a track_xy

With the argument n we can control the number of random points (remember that the default is ten times as many points as we observed points).

Next, we can create random point within a home range, that we estimated before.

Here, we can also add the observed points:

Finally, we can work with the home range and for example a buffer and then generate random points within the this new polygon.

And we can also add the observed points.

Of course we are not restricted to the sf::st_buffer function. All geometric operations from the sf package can be used to generate arbitrarily complex availability domains.

Extract covariates

As the next step we have to extract the covariates at point. We can do this with extract_covariates.

Fitting RSF

Now all pieces are there to fit a RSF. We will use fit_rsf, which is just a wrapper around stats::glm with family = binomial(link = "logit").

rsf1 %>% fit_rsf(case_ ~ forest) %>% 
  summary()
## 
## Call:
## stats::glm(formula = formula, family = stats::binomial(link = "logit"), 
##     data = data)
## 
## Deviance Residuals: 
##     Min       1Q   Median       3Q      Max  
## -0.5333  -0.4060  -0.4060  -0.4060   2.2525  
## 
## Coefficients:
##             Estimate Std. Error z value Pr(>|z|)    
## (Intercept) -2.45454    0.04404  -55.74  < 2e-16 ***
## forestTRUE   0.57582    0.07920    7.27 3.59e-13 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 5535.8  on 9085  degrees of freedom
## Residual deviance: 5486.1  on 9084  degrees of freedom
## AIC: 5490.1
## 
## Number of Fisher Scoring iterations: 5

Session

sessioninfo::session_info()
## ─ Session info ───────────────────────────────────────────────────────────────
##  setting  value                       
##  version  R version 3.6.3 (2020-02-29)
##  os       Ubuntu 18.04.4 LTS          
##  system   x86_64, linux-gnu           
##  ui       X11                         
##  language en_US:en                    
##  collate  C                           
##  ctype    en_US.UTF-8                 
##  tz       Europe/Berlin               
##  date     2020-04-23                  
## 
## ─ Packages ───────────────────────────────────────────────────────────────────
##  package     * version    date       lib source                           
##  amt         * 0.1.0      2020-04-23 [1] local                            
##  assertthat    0.2.1      2019-03-21 [3] CRAN (R 3.6.1)                   
##  backports     1.1.6      2020-04-05 [3] CRAN (R 3.6.3)                   
##  checkmate     2.0.0      2020-02-06 [3] CRAN (R 3.6.1)                   
##  class         7.3-15     2019-01-01 [6] CRAN (R 3.6.0)                   
##  classInt      0.4-2      2019-10-17 [3] CRAN (R 3.6.1)                   
##  cli           2.0.2      2020-02-28 [3] CRAN (R 3.6.1)                   
##  codetools     0.2-16     2018-12-24 [6] CRAN (R 3.6.0)                   
##  colorspace    1.4-1      2019-03-18 [3] CRAN (R 3.6.1)                   
##  crayon        1.3.4      2017-09-16 [3] CRAN (R 3.6.1)                   
##  DBI           1.1.0      2019-12-15 [3] CRAN (R 3.6.1)                   
##  digest        0.6.25     2020-02-23 [3] CRAN (R 3.6.1)                   
##  dplyr       * 0.8.5      2020-03-07 [3] CRAN (R 3.6.1)                   
##  e1071         1.7-3      2019-11-26 [3] CRAN (R 3.6.1)                   
##  ellipsis      0.3.0      2019-09-20 [3] CRAN (R 3.6.1)                   
##  evaluate      0.14       2019-05-28 [3] CRAN (R 3.6.1)                   
##  fansi         0.4.1      2020-01-08 [3] CRAN (R 3.6.1)                   
##  farver        2.0.3      2020-01-16 [3] CRAN (R 3.6.1)                   
##  ggplot2     * 3.3.0      2020-03-05 [3] CRAN (R 3.6.1)                   
##  glue          1.4.0      2020-04-03 [3] CRAN (R 3.6.3)                   
##  gtable        0.3.0      2019-03-25 [3] CRAN (R 3.6.1)                   
##  htmltools     0.4.0      2019-10-04 [3] CRAN (R 3.6.1)                   
##  KernSmooth    2.23-15    2015-06-29 [6] CRAN (R 3.5.0)                   
##  knitr       * 1.28       2020-02-06 [3] CRAN (R 3.6.3)                   
##  labeling      0.3        2014-08-23 [3] CRAN (R 3.6.1)                   
##  lattice       0.20-40    2020-02-19 [6] CRAN (R 3.6.2)                   
##  lazyeval      0.2.2      2019-03-15 [3] CRAN (R 3.6.1)                   
##  lifecycle     0.2.0      2020-03-06 [3] CRAN (R 3.6.1)                   
##  lubridate   * 1.7.4      2018-04-11 [3] CRAN (R 3.6.1)                   
##  magrittr      1.5        2014-11-22 [3] CRAN (R 3.6.1)                   
##  Matrix        1.2-17     2019-03-22 [6] CRAN (R 3.6.1)                   
##  munsell       0.5.0      2018-06-12 [3] CRAN (R 3.6.1)                   
##  pillar        1.4.3      2019-12-20 [3] CRAN (R 3.6.1)                   
##  pkgconfig     2.0.3      2019-09-22 [3] CRAN (R 3.6.1)                   
##  purrr         0.3.4      2020-04-17 [3] CRAN (R 3.6.3)                   
##  R6            2.4.1      2019-11-12 [3] CRAN (R 3.6.1)                   
##  raster      * 3.0-12     2020-01-30 [3] CRAN (R 3.6.1)                   
##  Rcpp          1.0.4.6    2020-04-09 [3] CRAN (R 3.6.3)                   
##  rgdal         1.4-8      2019-11-27 [3] CRAN (R 3.6.3)                   
##  rlang         0.4.5      2020-03-01 [3] CRAN (R 3.6.1)                   
##  rmarkdown     2.0        2019-12-12 [3] CRAN (R 3.6.1)                   
##  scales        1.1.0      2019-11-18 [3] CRAN (R 3.6.1)                   
##  sessioninfo   1.1.1      2018-11-05 [3] CRAN (R 3.6.1)                   
##  sf            0.9-0      2020-03-24 [3] CRAN (R 3.6.3)                   
##  sp          * 1.4-1      2020-02-28 [3] CRAN (R 3.6.3)                   
##  stringi       1.4.6      2020-02-17 [3] CRAN (R 3.6.1)                   
##  stringr       1.4.0      2019-02-10 [3] CRAN (R 3.6.1)                   
##  survival      3.1-8      2019-12-03 [3] CRAN (R 3.6.1)                   
##  tibble        3.0.1.9000 2020-04-23 [3] Github (tidyverse/tibble@3892a7f)
##  tidyr         1.0.2      2020-01-24 [3] CRAN (R 3.6.1)                   
##  tidyselect    1.0.0      2020-01-27 [3] CRAN (R 3.6.1)                   
##  units         0.6-6      2020-03-16 [3] CRAN (R 3.6.1)                   
##  utf8          1.1.4      2018-05-24 [3] CRAN (R 3.6.1)                   
##  vctrs         0.2.4      2020-03-10 [3] CRAN (R 3.6.1)                   
##  withr         2.2.0      2020-04-20 [3] CRAN (R 3.6.3)                   
##  xfun          0.13       2020-04-13 [3] CRAN (R 3.6.3)                   
##  yaml          2.2.1      2020-02-01 [3] CRAN (R 3.6.3)                   
## 
## [1] /tmp/Rtmp3TuR3g/Rinst55c47601aee6
## [2] /tmp/Rtmp8ySvX2/temp_libpath434e213f5de
## [3] /home/jsigner/R/x86_64-pc-linux-gnu-library/3.6
## [4] /usr/local/lib/R/site-library
## [5] /usr/lib/R/site-library
## [6] /usr/lib/R/library