TrajGenerate {trajr} | R Documentation |
Generate a random trajectory
Description
Generates a trajectory. If random
is TRUE
, the trajectory will
be a correllated random walk/idiothetic directed walk (Kareiva & Shigesada,
1983), corresponding to an animal navigating without a compass (Cheung,
Zhang, Stricker, & Srinivasan, 2008). If random
is FALSE
, it
will be a directed walk/allothetic directed walk/oriented path, corresponding
to an animal navigating with a compass (Cheung, Zhang, Stricker, &
Srinivasan, 2007, 2008).
Usage
TrajGenerate(
n = 1000,
random = TRUE,
stepLength = 2,
angularErrorSd = 0.5,
angularErrorDist = function(n) stats::rnorm(n, sd = angularErrorSd),
linearErrorSd = 0.2,
linearErrorDist = function(n) stats::rnorm(n, sd = linearErrorSd),
fps = 50,
...
)
Arguments
n |
Number of steps in the trajectory. |
random |
If TRUE, a random search trajectory is returned, otherwise a directed trajectory (with direction = 0 radians) is returned. |
stepLength |
Mean length of each step in the trajectory, in arbitrary length units. |
angularErrorSd |
Standard deviation of angular errors in radians. |
angularErrorDist |
Function which accepts a single argument - the number
of values to return, and generates random deviates according to some
distribution. The returned values are added to the previous step angle
(when |
linearErrorSd |
Standard deviation of linear step length errors. |
linearErrorDist |
Function which accepts a single argument - the number
of values to return, and generates random deviates according to some
distribution. The returned values are added to |
fps |
Simulated frames-per-second - used to generate times for each point in the trajectory. |
... |
Additional arguments are passed to |
Details
By default, for both random and directed walks, errors are normally
distributed, unbiased, and independent of each other, so are simple
directed walks in the terminology of Cheung, Zhang, Stricker, & Srinivasan,
(2008). This behaviour may be modified by specifying alternative values for
the angularErrorDist
and/or linearErrorDist
parameters.
The initial angle (for a random walk) or the intended direction (for a
directed walk) is 0
radians. To change the initial angle or intended
direction, call TrajRotate
on the new trajectory. The starting
position is (0, 0)
. To change the starting position, call
TrajTranslate
on the new trajectory.
Value
A new Trajectory with n
segments and n + 1
coordinate
pairs.
References
Kareiva, P. M., & Shigesada, N. (1983). Analyzing insect movement as a correlated random walk. Oecologia, 56(2), 234-238. doi:10.1007/bf00379695
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
Cheung, A., Zhang, S., Stricker, C., & Srinivasan, M. V. (2008). Animal navigation: general properties of directed walks. Biological Cybernetics, 99(3), 197-217. doi:10.1007/s00422-008-0251-z
Examples
# Generate a 1000 step correlated random walk
trj <- TrajGenerate()
plot(trj, main = "Correlated walk")
# Generate a 1000 step levy flight - paths lengths follow a cauchy distribution
trj <- TrajGenerate(linearErrorDist = rcauchy)
plot(trj, main = "Levy flight")
# Generate a short directed trajectory
trj <- TrajGenerate(n = 20, random = FALSE)
plot(trj, main = "Directed walk")
# Generate an uncorrelated random walk
trj <- TrajGenerate(500, angularErrorDist = function(n) runif(n, -pi, pi))
plot(trj, main = "Uncorrelated walk")
# Generate a walk directed northwards, starting from (200, 300),
# with a mean step length of 200. The initially generated trajectory
# is directed to angle 0, with starting point (0, 0)
trj <- TrajGenerate(n = 20, stepLength = 200, random = FALSE)
# Rotate 90 degrees about (0, 0) (i.e. from east to north)
trj <- TrajRotate(trj, pi / 2, relative = FALSE)
# Translate to desired starting point
trj <- TrajTranslate(trj, 200, 300)