[R] simulate a null expectation

Moshe Olshansky m_olshansky at yahoo.com
Tue Aug 7 05:01:26 CEST 2007

Hi Ryan,

I think that the only function you need is the one
which generates random variable. The simplest one is
to generate a uniform (0,1) variable U and then do not
move if U < 0.25, move to the first nearest point if
0.25 <= U < 0.5, move to the second nearest point if
).5 <= U < 0.75 and move to the third nearest point if
U >= 0.75.
To make things work faster you may wish to prepare for
which of your points the indexes of the 3 nearest
points (i.e. if you have N points you prepare an Nx3
matrix of indexes).



--- Ryan Briscoe Runquist <rdbriscoe at ucdavis.edu>

> Hello,
> I am trying to write a simulation to generate a null
> hypothesis so that I
> can test my data.  Essentially we started out with a
> grid of points and I
> have a symmetrical matrix of the distance between
> all of these points.  I
> then want to simulate random movement.  So I want to
> be able to start at a
> point, search through the matrix for the three
> closest points and with
> equal probability move to one of them or stay at the
> same place and then
> record the distance moved as well as the relative
> elevation (a vector of
> data that I also have) and then starting at that
> grid-point repeat the
> process a number of times.  Does anyone know of a
> function that could help
> me with this?
> Thanks,
> Ryan
> ~~~~~~~~~~~~~~~~~~
> Ryan D. Briscoe Runquist
> Population Biology Graduate Group
> University of California, Davis
> rdbriscoe at ucdavis.edu
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained,
> reproducible code.

More information about the R-help mailing list