TrajExpectedSquareDisplacement | R Documentation |
Calculates the expected square displacement for a trajectory assuming it is a correlated random walk, using the formula in Kareiva & Shigesada, (1983).
TrajExpectedSquareDisplacement(
trj,
n = nrow(trj),
eqn1 = TRUE,
compass.direction = NULL
)
trj |
A Trajectory. |
n |
Number of steps to calculate. |
eqn1 |
If |
compass.direction |
If not |
Note that Cheung, Zhang, Stricker, and Srinivasan (2007) define an
alternative formulation for expected maximum displacement, Emax (see
TrajEmax
).
Cheung, A., Zhang, S., Stricker, C., & Srinivasan, M. V. (2007). Animal navigation: the difficulty of moving in a straight line. Biological Cybernetics, 97(1), 47-61. doi:10.1007/s00422-007-0158-0
Kareiva, P. M., & Shigesada, N. (1983). Analyzing insect movement as a correlated random walk. Oecologia, 56(2), 234-238. doi:10.1007/bf00379695
TrajEmax
set.seed(1)
# A random walk
trj <- TrajGenerate(200)
smoothed <- TrajSmoothSG(trj)
# Calculate actual squared displacement at all points along the trajectory
sd2 <- sapply(2:nrow(smoothed), function(n) TrajDistance(smoothed, 1, n) ^ 2)
# Calculate expected squared displacement
ed2_1 <- sapply(2:nrow(smoothed), function(n) TrajExpectedSquareDisplacement(smoothed, n, TRUE))
ed2_2 <- sapply(2:nrow(smoothed), function(n) TrajExpectedSquareDisplacement(smoothed, n, FALSE))
# Plot expected against actual. According to Kareiva & Shigesada, (1983), if actual
# (approximately) matches expected, the trajectory is probably a correlated random walk
par(mar = c(5, 5, 0.1, 0.1) + .1)
plot(2:nrow(smoothed), sd2, type = 'l', pch = 16, cex = .2, lwd = 2,
xlab = 'Number of consecutive moves',
ylab = expression('Squared displacement, ' * R[n]^2))
lines(2:nrow(smoothed), ed2_1, col = "grey", lwd = 2)
lines(2:nrow(smoothed), ed2_2, col = "pink", lwd = 2)
legend("bottomright",
c(expression("Actual displacement"^2),
expression("Expected displacement"^2 * " (eqn 1)"),
expression("Expected displacement"^2 * " (eqn 2)")),
col = c('black', 'grey', 'pink'), lwd = 2,
inset = c(0.01, 0.02))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.