This is part of the supplementary material of the manuscript Detecting recurrent sources of variability in animal tracking studies by Virginia Morera-Pujol et al. submitted to Ecological Applications in 2021.

This document shows how to generate, using the package SIMRiv, simulated animal movement tracks to test the detection of Individual Site Fidelity by the test developed for the MS “Detecting recurrent sources of variability in animal tracking studies”, by Virginia Morera-Pujol et al. (2020)

0.1 Simulate template track

First, simulate a correlated RW. We’ve tried to simulate a Lévy Walk but since ideally we’re not using commuting points in our real-data analysis, CRW looks more similar to a real dataset

CRW15 <- species(state.CRW(0.25) + 7)
simCRW <- simulate(CRW15, coords = matrix(rep(0, 2), ncol = 2), time = 10000)
plot(simCRW[,1:2], type = "l", 
     xlim = c(min(simCRW[,1]), max(simCRW[,1])), 
     ylim = c(min(simCRW[,2]), max(simCRW[,2])), 
     main = "Simulation of a correlated random walk with 10,000 steps")

spSimCRW <- SpatialPoints(coords = simCRW[,1:2])

0.2 Turn template into resistance surface

Then, generate a convex hull of that correlated RW

example_MCP <- mcp(spSimCRW, percent = 100)
plot(example_MCP, main = "100% Minimum convex polygon of the simulated CRW")
plot(spSimCRW, add = T, pch = 20, cex = 0.5, col = "gray")

Convert this convex hull into a resistance surface from SiMRiv to limit distribution of newly simulated tracks

res_surface <- resistanceFromShape(example_MCP, res = 1, margin = c(500, 500))
plot(res_surface, main = "Resistance surface generated from the previous MCP")

0.3 Simulate tracks within the resistance surface

Now simulate tracks within the resistance shape

simCRW_res <- simulate(list(CRW15, CRW15, CRW15, CRW15), coords = matrix(rep(0, 8), 
                                                                         ncol = 2), 
                       time = 10000, resist = res_surface)
spSimCRW_res <- SpatialPointsDataFrame(coords = cbind(c(simCRW_res[,1], simCRW_res[,4], 
                                                        simCRW_res[,7], simCRW_res[,10]),
                                                      c(simCRW_res[,2], simCRW_res[,5], 
                                                        simCRW_res[,8], simCRW_res[,11])),
                                       data = data.frame(ID = c(rep(1, 10000), 
                                                                rep(2, 10000), 
                                                                rep(3, 10000),
                                                                rep(4, 10000))))

plot(res_surface, 
     main = "Simulated tracks within the MCP \nthrough the resistance surface")
plot(spSimCRW_res, pch = 20, cex = 0.5, add = T, col = spSimCRW_res$ID)

This is the basic workflow to generate simulated datasets displaying individual site fidelity. Different levels of fidelity can be simulated by changing the resistance values outside the convex hull. The higher the resistance, the more intense the “fidelity”. We are going to use it to generate different types of data to test aspects of the indEffectTest function developed for the manuscript.