Closed kflorko closed 5 months ago
Hi Katie,
there is new functionality to simulate in amt
. Here is a brief example:
library(amt)
data("deer")
forest <- get_sh_forest() # this needed because of terra
# prepare data
data_ssf <- deer |>
steps_by_burst() |>
random_steps(n_control = 15) |>
extract_covariates(forest, where = "both")
# fit model
m1 <- data_ssf |>
fit_clogit(case_ ~ forest_end + forest_start:cos(ta_) +
forest_start:sl_ + strata(step_id_))
# First generate a redistribution kernel
start <- make_start(deer[1, ]) # This is the starting location (we could sample it randomly from within the area we want to )
k1 <- redistribution_kernel(m1, map = forest, start = start)
# Now simulate a path of length 30 for 50 times. This will lead a transient UD. For a steady state UD, either increase `n` or choose many more random starting points.
n <- 50
p1 <- replicate(n, simulate_path(k1, n = 30), simplify = FALSE) # Takes about 2 min
uds <- lapply(c(5, 30), function(i) {
tibble(
rep = 1:n,
path = map(p1, ~ dplyr::slice(.x, i))
) |> unnest(cols = path) |> filter(!is.na(x_)) |>
make_track(x_, y_) |> hr_kde(trast = forest)
})
terra::plot(hr_ud(uds[[1]]))
terra::plot(hr_ud(uds[[2]]))
Hopefully, this helps. The advantage is that the redistribution_kernel()
is now dynamic and not static as it was before.
All the best, Johannes
Hello! I am trying to simulate a steady-state UD from a SSF by reproducing the code described in Signer et al. 2019, but the functions
habitat_kernel()
,movement_kernel()
, andsimulate_ud()
are not in the current version of amt (0.2.1.0). Is there another way to simulate the UD?Here is a small reproducible example showing what I'd like to do and how we get held up at the
habitat_kernel()
,movement_kernel()
, andsimulate_ud()
steps:Many thanks in advance! Katie
note: cross-posted on stack overflow