Randomly shifts the points of a point pattern.
# S3 method for ppp
rshift(X, …, which=NULL, group, nsim=1, drop=TRUE)
Point pattern to be subjected to a random shift.
An object of class "ppp"
Arguments that determine the random shift. See Details.
Optional. Factor specifying a grouping of the points of X
,
or NULL
indicating that all points belong to the same group.
Each group will be shifted together, and
separately from other groups.
By default, points in a marked point pattern are grouped
according to their mark values,
while points in an unmarked point pattern are treated as a single group.
Optional. Identifies which groups of the pattern will be shifted,
while other groups are not shifted. A vector of levels of group
.
Number of simulated realisations to be generated.
Logical. If nsim=1
and drop=TRUE
(the default), the
result will be a point pattern, rather than a list
containing a point pattern.
A point pattern (object of class "ppp"
)
or a list of point patterns.
This operation randomly shifts the locations of the points in a point pattern.
The function rshift
is generic. This function rshift.ppp
is the method for point patterns.
The most common use of this function is to shift the points in a multitype point pattern. By default, points of the same type are shifted in parallel (i.e. points of a common type are shifted by a common displacement vector), and independently of other types. This is useful for testing the hypothesis of independence of types (the null hypothesis that the sub-patterns of points of each type are independent point processes).
In general the points of X
are divided into groups,
then the points within a group are shifted by a common
random displacement vector. Different groups of points are shifted
independently. The grouping is determined as follows:
If the argument group
is present, then this determines the grouping.
Otherwise, if X
is a multitype point pattern,
the marks determine the grouping.
Otherwise, all points belong to a single group.
The argument group
should be a factor, of length equal to the
number of points in X
. Alternatively group
may be NULL
,
which specifies that all points of X
belong to a single group.
By default, every group of points will be shifted.
The argument which
indicates that only some of the groups
should be shifted, while other groups should be left unchanged.
which
must be a vector of levels of group
(for example, a vector of types in a multitype pattern)
indicating which groups are to be shifted.
The displacement vector, i.e. the vector
by which the data points are shifted,
is generated at random.
Parameters that control the randomisation
and the handling of edge effects are passed through
the …
argument. They are
Parameters of the random shift vector.
String indicating how to deal with edges of the pattern.
Options are "torus"
, "erode"
and "none"
.
Optional. Window to which the final point pattern should be clipped.
If the window is a rectangle, the default behaviour is to generate a displacement vector at random with equal probability for all possible displacements. This means that the \(x\) and \(y\) coordinates of the displacement vector are independent random variables, uniformly distributed over the range of possible coordinates.
Alternatively, the displacement vector can be generated by
another random mechanism, controlled by the arguments
radius
, width
and height
.
if width
and height
are given, then
the displacement vector is uniformly distributed
in a rectangle of these dimensions, centred at
the origin. The maximum possible displacement in the \(x\)
direction is width/2
. The maximum possible displacement in
the \(y\) direction is height/2
. The \(x\) and \(y\)
displacements are independent. (If width
and height
are actually equal to the dimensions of the observation window,
then this is equivalent to the default.)
if radius
is given, then the displacement vector is
generated by choosing a random point inside a disc of
the given radius, centred at the origin, with uniform probability
density over the disc. Thus the argument radius
determines
the maximum possible displacement distance.
The argument radius
is incompatible with the
arguments width
and height
.
The argument edge
controls what happens when
a shifted point lies outside the window of X
.
Options are:
Points shifted outside the window of X
simply disappear.
Toroidal or periodic boundary. Treat opposite edges of the window as identical, so that a point which disappears off the right-hand edge will re-appear at the left-hand edge. This is called a ``toroidal shift'' because it makes the rectangle topologically equivalent to the surface of a torus (doughnut).
The window must be a rectangle. Toroidal shifts are undefined if the window is non-rectangular.
Clip the point pattern to a smaller window.
If the random displacements are generated by a radial
mechanism (see above), then the window of X
is eroded by a distance equal to the value of the argument
radius
, using erosion
.
If the random displacements are generated by a rectangular
mechanism, then the window of X
is
(if it is not rectangular) eroded by a distance
max(height,width)
using erosion
;
or (if it is rectangular) trimmed by a margin of width width
at the left and right sides and trimmed by a margin of
height height
at the top and bottom.
The rationale for this is that the clipping window is the largest window for which edge effects can be ignored.
The optional argument clip
specifies a smaller window
to which the pattern should be restricted.
If nsim > 1
, then the simulation procedure is
performed nsim
times; the result is a list of nsim
point patterns.
# NOT RUN {
# random toroidal shift
# shift "on" and "off" points separately
X <- rshift(amacrine)
# shift "on" points and leave "off" points fixed
X <- rshift(amacrine, which="on")
# shift all points simultaneously
X <- rshift(amacrine, group=NULL)
# maximum displacement distance 0.1 units
X <- rshift(amacrine, radius=0.1, nsim=2)
# shift with erosion
X <- rshift(amacrine, radius=0.1, edge="erode")
# }
Run the code above in your browser using DataLab