eWalk, an R function to simulate two-dimensional evolutionary walks
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
eWalk 15){ # Levy jump probability threshold l=15 # length of the jump x= lon + (l * (sigma * rnorm(1))) + (alpha_x * ( theta_x - lon)) # Brownian or OU process for longitude y= lat + (l * (sigma * rnorm(1))) + (alpha_y * ( theta_y - lat)) # Brownian or OU process for latitude loc=cbind(x,y) route[generation,]
In addition, I have added a complement to simulate Lèvy flights, a non-gaussian process similar to Brownian motion but allowing for jumps during the motion. Lévy flights pattern has been found in searchingmovements of predators (Bartumeus et al., 2005), or have been used to simulatepunctuated equilibrium in traitsevolution (Gould and Eldredge, 1977; Landis et al., 2013). To perform Lèvy flight, eWalk selects a random number from Cauchy distribution and if it is higher than a threshold (15 by default), Brownian motion term is multiplied by a constant representing a jump (also 15 by default). Although this is not the formal expression of a Lèvy process, this is a simple way to simulate a negative exponential rate in for the length of each step.
par(mfrow=c(2,2)) a=eWalk(0.15,0,0,1000, 0, 0, 0, 0, color="blue", levy=FALSE, plot=FALSE) plot(a,type="n", main="Brownian motion") lines(a,lwd=3, col="blue") points(a, cex=.3, col="black", pch=21) a=eWalk(0.15,0,0,1000, 0, 0, 0, 0, color="red", levy=TRUE, plot=FALSE) plot(a,type="n", main="Lêvy flight") lines(a,lwd=3, col="red") points(a, cex=.3, col="black", pch=21) a=eWalk(0.15,0,0,1000, 0.01, 20, 0, 0, color="orange", levy=FALSE, plot=FALSE) plot(a,type="n", main="OU one optimum") lines(a,lwd=3, col="orange") abline(v=20, col="red", lwd="2") points(a, cex=.3, col="black", pch=21) a=eWalk(0.15,0,0,1000, 0.01, 20, 0.01, 20, color="green", levy=FALSE, plot=FALSE) plot(a,type="n", main="OU two optimum") lines(a,lwd=3, col="green") points(a, cex=.3, col="black", pch=21) abline(v=20, col="red", lwd="2") abline(h=20, col="red", lwd="2")
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.