Resource Selection Functions (RSF) with amt
Author: Johannes Signer
Date: 2026-01-30

# Resource Selection Functions (RSF) with `amt`

#### Johannes Signer

#### 2026-01-30

## 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 × 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
    ## # ℹ 816 more rows

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

    sh_forest <- get_sh_forest()

## 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 `POLYGON`s or `MULTIPOLYGON`s 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`

    r1 <- random_points(deer)
    plot(r1)

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).

    r1 <- random_points(deer, n = 100)
    plot(r1)

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

    hr <- hr_mcp(deer)
    r1 <- random_points(hr, n = 500)
    plot(r1)

Here, we can also add the observed points:

    hr <- hr_mcp(deer)
    r1 <- random_points(hr, n = 500, presence = deer)
    plot(r1)

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

    hr <- hr_mcp(deer) |> hr_isopleths() |>
      sf::st_buffer(dist =3e4) # add a 30km buffer
    r1 <- random_points(hr, n = 500)
    plot(r1)

And we can also add the observed points.

    hr <- hr_mcp(deer) |> hr_isopleths() |>
      sf::st_buffer(dist =3e4) # add a 30km buffer
    r1 <- random_points(hr, n = 500, presence = deer)
    plot(r1)

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`.

    rsf1 <- deer |> random_points() |>
      extract_covariates(sh_forest)

## 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)
    ##
    ## Coefficients:
    ##             Estimate Std. Error z value Pr(>|z|)
    ## (Intercept) -2.44869    0.04405  -55.59  < 2e-16 ***
    ## forest       0.54838    0.07913    6.93  4.2e-12 ***
    ## ---
    ## 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: 5490.5  on 9084  degrees of freedom
    ## AIC: 5494.5
    ##
    ## Number of Fisher Scoring iterations: 5

## Session

    sessioninfo::session_info()

    ## ─ Session info ───────────────────────────────────────────────────────────────
    ##  setting  value
    ##  version  R version 4.5.1 (2025-06-13)
    ##  os       macOS Sequoia 15.7.3
    ##  system   aarch64, darwin20
    ##  ui       X11
    ##  language (EN)
    ##  collate  C
    ##  ctype    en_US.UTF-8
    ##  tz       Europe/Berlin
    ##  date     2026-01-30
    ##  pandoc   3.4 @ /Applications/RStudio.app/Contents/Resources/app/quarto/bin/tools/aarch64/ (via rmarkdown)
    ##  quarto   1.6.40 @ /usr/local/bin/quarto
    ##
    ## ─ Packages ───────────────────────────────────────────────────────────────────
    ##  package      * version date (UTC) lib source
    ##  amt          * 0.3.1.0 2026-01-30 [1] local
    ##  backports      1.5.0   2024-05-23 [3] CRAN (R 4.5.0)
    ##  bslib          0.9.0   2025-01-30 [3] CRAN (R 4.5.0)
    ##  cachem         1.1.0   2024-05-16 [3] CRAN (R 4.5.0)
    ##  checkmate      2.3.3   2025-08-18 [3] CRAN (R 4.5.0)
    ##  class          7.3-23  2025-01-01 [3] CRAN (R 4.5.1)
    ##  classInt       0.4-11  2025-01-08 [3] CRAN (R 4.5.0)
    ##  cli            3.6.5   2025-04-23 [3] CRAN (R 4.5.0)
    ##  codetools      0.2-20  2024-03-31 [3] CRAN (R 4.5.1)
    ##  data.table     1.17.8  2025-07-10 [3] CRAN (R 4.5.0)
    ##  DBI            1.2.3   2024-06-02 [3] CRAN (R 4.5.0)
    ##  digest         0.6.39  2025-11-19 [3] CRAN (R 4.5.2)
    ##  dplyr        * 1.1.4   2023-11-17 [3] CRAN (R 4.5.0)
    ##  e1071          1.7-16  2024-09-16 [3] CRAN (R 4.5.0)
    ##  evaluate       1.0.5   2025-08-27 [3] CRAN (R 4.5.0)
    ##  farver         2.1.2   2024-05-13 [3] CRAN (R 4.5.0)
    ##  fastmap        1.2.0   2024-05-15 [3] CRAN (R 4.5.0)
    ##  generics       0.1.4   2025-05-09 [3] CRAN (R 4.5.0)
    ##  ggforce        0.5.0   2025-06-18 [3] CRAN (R 4.5.0)
    ##  ggplot2      * 4.0.1   2025-11-14 [3] CRAN (R 4.5.2)
    ##  ggraph       * 2.2.2   2025-08-24 [3] CRAN (R 4.5.0)
    ##  ggrepel        0.9.6   2024-09-07 [3] CRAN (R 4.5.0)
    ##  glue           1.8.0   2024-09-30 [3] CRAN (R 4.5.0)
    ##  graphlayouts   1.2.2   2025-01-23 [3] CRAN (R 4.5.0)
    ##  gridExtra      2.3     2017-09-09 [3] CRAN (R 4.5.0)
    ##  gtable         0.3.6   2024-10-25 [3] CRAN (R 4.5.0)
    ##  htmltools      0.5.9   2025-12-04 [3] CRAN (R 4.5.2)
    ##  igraph         2.2.1   2025-10-27 [3] CRAN (R 4.5.0)
    ##  jquerylib      0.1.4   2021-04-26 [3] CRAN (R 4.5.0)
    ##  jsonlite       2.0.0   2025-03-27 [3] CRAN (R 4.5.0)
    ##  KernSmooth     2.23-26 2025-01-01 [3] CRAN (R 4.5.1)
    ##  knitr          1.50    2025-03-16 [3] CRAN (R 4.5.0)
    ##  labeling       0.4.3   2023-08-29 [3] CRAN (R 4.5.0)
    ##  lattice        0.22-7  2025-04-02 [3] CRAN (R 4.5.1)
    ##  lifecycle      1.0.4   2023-11-07 [3] CRAN (R 4.5.0)
    ##  lubridate      1.9.4   2024-12-08 [3] CRAN (R 4.5.0)
    ##  magrittr       2.0.4   2025-09-12 [3] CRAN (R 4.5.0)
    ##  MASS           7.3-65  2025-02-28 [3] CRAN (R 4.5.1)
    ##  Matrix         1.7-4   2025-08-28 [3] CRAN (R 4.5.0)
    ##  memoise        2.0.1   2021-11-26 [3] CRAN (R 4.5.0)
    ##  pillar         1.11.1  2025-09-17 [3] CRAN (R 4.5.0)
    ##  pkgconfig      2.0.3   2019-09-22 [3] CRAN (R 4.5.0)
    ##  polyclip       1.10-7  2024-07-23 [3] CRAN (R 4.5.0)
    ##  proxy          0.4-28  2025-12-11 [3] CRAN (R 4.5.2)
    ##  purrr          1.2.0   2025-11-04 [3] CRAN (R 4.5.0)
    ##  R6             2.6.1   2025-02-15 [3] CRAN (R 4.5.0)
    ##  rbibutils      2.4     2025-11-07 [3] CRAN (R 4.5.0)
    ##  RColorBrewer   1.1-3   2022-04-03 [3] CRAN (R 4.5.0)
    ##  Rcpp           1.1.0   2025-07-02 [3] CRAN (R 4.5.0)
    ##  Rdpack         2.6.4   2025-04-09 [3] CRAN (R 4.5.0)
    ##  rlang          1.1.6   2025-04-11 [3] CRAN (R 4.5.0)
    ##  rmarkdown      2.30    2025-09-28 [3] CRAN (R 4.5.0)
    ##  rstudioapi     0.17.1  2024-10-22 [3] CRAN (R 4.5.0)
    ##  S7             0.2.1   2025-11-14 [3] CRAN (R 4.5.2)
    ##  sass           0.4.10  2025-04-11 [3] CRAN (R 4.5.0)
    ##  scales         1.4.0   2025-04-24 [3] CRAN (R 4.5.0)
    ##  sessioninfo    1.2.3   2025-02-05 [3] CRAN (R 4.5.0)
    ##  sf             1.0-23  2025-11-28 [3] CRAN (R 4.5.2)
    ##  survival       3.8-3   2024-12-17 [3] CRAN (R 4.5.1)
    ##  terra          1.8-86  2025-11-28 [3] CRAN (R 4.5.1)
    ##  tibble         3.3.0   2025-06-08 [3] CRAN (R 4.5.0)
    ##  tidygraph    * 1.3.1   2024-01-30 [3] CRAN (R 4.5.0)
    ##  tidyr          1.3.1   2024-01-24 [3] CRAN (R 4.5.0)
    ##  tidyselect     1.2.1   2024-03-11 [3] CRAN (R 4.5.0)
    ##  timechange     0.3.0   2024-01-18 [3] CRAN (R 4.5.0)
    ##  tweenr         2.0.3   2024-02-26 [3] CRAN (R 4.5.0)
    ##  units          1.0-0   2025-10-09 [3] CRAN (R 4.5.0)
    ##  utf8           1.2.6   2025-06-08 [3] CRAN (R 4.5.0)
    ##  vctrs          0.6.5   2023-12-01 [3] CRAN (R 4.5.0)
    ##  viridis        0.6.5   2024-01-29 [3] CRAN (R 4.5.0)
    ##  viridisLite    0.4.2   2023-05-02 [3] CRAN (R 4.5.0)
    ##  withr          3.0.2   2024-10-28 [3] CRAN (R 4.5.0)
    ##  xfun           0.54    2025-10-30 [3] CRAN (R 4.5.0)
    ##  yaml           2.3.11  2025-11-28 [3] CRAN (R 4.5.2)
    ##
    ##  [1] /private/var/folders/ln/h3zng0fs2pq7mhn_hzn0d8x00000gn/T/RtmpiuVLeA/Rinst170c54b169d31
    ##  [2] /private/var/folders/ln/h3zng0fs2pq7mhn_hzn0d8x00000gn/T/RtmpQgoeq6/temp_libpath139ab582649cc
    ##  [3] /Library/Frameworks/R.framework/Versions/4.5-arm64/Resources/library
    ##  * ── Packages attached to the search path.
    ##
    ## ──────────────────────────────────────────────────────────────────────────────