R script for stochastic mapping