Hello,

 

I think you're right, this would be very computationally intensive.

Something else I thought about was using the raster package like this:

 

1.       Generate first random point.

2.       Make a distance raster to this first point.

3.       Select raster cells that have a distance value that lies within the
desired values.

4.       Amongst these, randomly select one point.

5.       Repeat the process from point 2 on.

 

However I 'm not sure if I like this approach because it makes use of the
raster package (which I like very much), not really using it (in the
output). I don't know if my objection is clear.

This might be possible without using raster, if a "distance surface" could
be generated using coordinates. I don't know.

 

Thanks anyway,

 

Frederico 

 

 

De: Seth Myers [mailto:sjmyers3142@gmail.com] 
Enviada: segunda-feira, 20 de Maio de 2013 10:15
Para: Frederico Mestre
Assunto: Re: random points with specified mean distance and std. dev.

 

How many points are you needing?  I can see a way to do what you would like,
but it will be very computationally intensive.  I'll wait until someone else
chimes in with a pre-made solution.  My idea is based upon picking the
position for a point given the distribution of all previous points.  This
will cause the computation time to increase very rapidly as the number of
points increases.  You need to think very carefully regarding what you want
as far as the distribution of distances among points.  Let's say we have N
number of points.  We can then define an N x N matrix where the intersection
of rows and columns is the distance between any 2 points.  The diagonal of
this matrix can be ignored because it will identify when the same point is
being compared to itself and so distance is zero.  For similar reasons, the
bottom triangle of the matrix can be ignored because it will replicate the
top triangle (e.g. the distance between points 1 and 2 is the same as the
distance between points 2 and 1).  Now, given this matrix, what do you want
to be true of it?  All pairwise distances of a certain distribution?  The
number of pairwise distances will be (N*N - N)/2.  You shouldn't spend a ton
of time on this until you are sure.

 

On Mon, May 20, 2013 at 4:24 AM, Frederico Mestre
<mestre.frederico@gmail.com> wrote:

Hello Seth,

 

Initially I was thinking in using the normal distribution, but I must see
first If this is the more adequate to my purpose.

 

Nevertheless let's assume I'll be using the normal distribution.

 

As for the distance, this would be the distance between all pair of points
not the nearest neighbor. The area will be defined as a square with a given
side length. 

 

I previously used an approach almost identical to the one you suggest the
problem is: when defining the point 3 (and all the others after), the
distance of 3 to 2 (or, more generally, the distance of the i th point to
the i-1) can be defined but the distance between 1 and 3 (or the distance of
the i th point to points 1 to i-2) is not controlled. The result is a
landscape with a varying mean distance between points.

 

I've considered that, after generating the point  i, I should evaluate if
the distance between this point and all others falls between a given
interval around the defined mean.

 

Thanks, 

 

Frederico 

 

 

De: Seth Myers [mailto:sjmyers3142@gmail.com] 
Enviada: segunda-feira, 20 de Maio de 2013 00:27
Para: mestre.frederico@gmail.com
Assunto: random points with specified mean distance and std. dev.

 

Hi,

 

Specifying the mean and std. dev. will not be enough.  You can have several
different distributions with the same mean and std. dev.  Were you thinking
of perhaps a normal distribution or another?  Also, are you concerned with
the distribution of each point in relation to all other, there nearest
neighbor only, or something else?

 

I do not know of a built in method to do this, and perhaps someone else will
chime in, but I can describe how you can use lower level R functions to do
this.  I will write this in plain English, and not code.

 

First, determine the mean, std. dev., type of distribution, number of
points, and study area.  Will the location and size of the study area simply
be defined by a raster with a known extent or do you have minimum and
maximum northing and easting?

 

One way to do this is as follows within a for loop that executes this once
per point: (this is similar to a random walk model, if you know about those
or want to read about them)

 

1. use a random number generator to come up with a location for the first
point

2. save the location for this point

3. use a random number generator to draw a number from a distribution of the
proper form, mean, and standard deviation, this will be the distance between
the first point and the second

4. draw another number from a random number generator using a uniform
distribution bounded between 0 and 360, this is the angle above the
horizontal for a straight line connecting points 1 and 2

5. find the coordinates for point 2 using trigonometry, make sure that the
distance between points 1 and 2 is equal to the number you drew in step 3
above and the angle of the connecting line is the correct degrees as
determined in step 4 above.

6. repeat these steps for point 3, but use point 2 as the anchor point from
which you use a new set of random numbers to determine the location of point
3, keep doing this until all your points are placed on the area

 

Be sure to save the seeds for your random number generators in case you want
to recreate the same pattern later.

 

A problem I see is when you points fall near the edge.  Let's say your first
point was close to the northeast corner of your area.  What do you do when
the next point falls outside your study area?  You could toss it out and
pick another, but this may cause issues.  I would think about that quite a
bit.

 

It seems to get this up and running in an hour or so, you only need to learn
to draw the type of random number you desire, use arrays to store
coordinates, and use a for loop.  If you get started and get stuck, someone
here, or myself can likely provide assistance.

 

Seth Myers

 


	[[alternative HTML version deleted]]

