nnmark {spatstat.geom} | R Documentation |
Mark of Nearest Neighbour
Description
Given a marked point pattern dataset X
this function computes, for each desired location y
,
the mark attached to the nearest neighbour of y
in X
.
The desired locations y
can be either a pixel grid
or the point pattern X
itself.
Usage
nnmark(X, ..., k = 1, at=c("pixels", "points"),
ties=c("first", "mean", "min", "max"),
proper=FALSE)
Arguments
X |
A marked point pattern (object of class |
... |
Arguments passed to |
k |
Single integer. The |
at |
String specifying whether to compute the values
at a grid of pixel locations ( |
ties |
Character string (partially matched) indicating how to handle the case of ties, where there are two or more data points at the same location. See Details. |
proper |
Logical value specifying how to define nearest neighbours
if there are two or more data points at the same location.
Applies only when |
Details
Given a marked point pattern dataset X
this function computes, for each desired location y
,
the mark attached to the point of X
that is nearest
to y
. The desired locations y
can be either a pixel grid
or the point pattern X
itself.
The argument X
must be a marked point pattern (object
of class "ppp"
, see ppp.object
).
The marks are allowed to be a vector or a data frame.
-
If
at="points"
, then for each point inX
, the algorithm finds the nearest other point inX
, and extracts the mark attached to it. The result is a vector or data frame containing the marks of the neighbours of each point. -
If
at="pixels"
(the default), then for each pixel in a rectangular grid, the algorithm finds the nearest point inX
, and extracts the mark attached to it. The result is an image or a list of images containing the marks of the neighbours of each pixel. The pixel resolution is controlled by the arguments...
passed toas.mask
.
If the argument k
is given, then the k
-th nearest
neighbour will be used.
The arguments ties
and proper
specify how to handle
the case where two or more data points are at the same spatial
location.
-
ties
determines how to pool the mark values. Ifties="first"
(the default), the mark value for this location is taken to be the mark of the data point that is listed first in sequence in the datasetX
. Ifties="mean"
,ties="max"
orties="min"
, the mark value for this location is taken to be the mean, maximum or minimum (respectively) of the mark values of all the data points at this location (after converting the mark values to numerical values). -
proper
determines how to define nearest neighbours, whenat="points"
. Ifproper=TRUE
, the nearest neighbour of a data point must be another data point lying a nonzero distance away from it. Ifproper=FALSE
(the default), then two data points occupying the exact same spatial location can be nearest neighbours.
Value
If X
has a single column of marks:
-
If
at="pixels"
(the default), the result is a pixel image (object of class"im"
). The value at each pixel is the mark attached to the nearest point ofX
. -
If
at="points"
, the result is a vector or factor of length equal to the number of points inX
. Entries are the mark values of the nearest neighbours of each point ofX
.
If X
has a data frame of marks:
-
If
at="pixels"
(the default), the result is a named list of pixel images (object of class"im"
). There is one image for each column of marks. This list also belongs to the class"solist"
, for which there is a plot method. -
If
at="points"
, the result is a data frame with one row for each point ofX
, Entries are the mark values of the nearest neighbours of each point ofX
.
Author(s)
Adrian Baddeley Adrian.Baddeley@curtin.edu.au, Rolf Turner rolfturner@posteo.net and Ege Rubak rubak@math.aau.dk.
See Also
Smooth.ppp
,
marktable
,
nnwhich
Examples
plot(nnmark(ants))
v <- nnmark(ants, at="points")
v[1:10]
plot(nnmark(finpines))
vf <- nnmark(finpines, at="points")
vf[1:5,]