closepairs: Close Pairs of Points

View source: R/closepairs.R

closepairsR Documentation

Close Pairs of Points

Description

Low-level functions to find all close pairs of points.

Usage

closepairs(X, rmax, ...)

## S3 method for class 'ppp'
closepairs(X, rmax, twice=TRUE,
                         what=c("all","indices","ijd"),
                         distinct=TRUE, neat=TRUE,
                         periodic=FALSE, ...)

crosspairs(X, Y, rmax, ...)

## S3 method for class 'ppp'
crosspairs(X, Y, rmax,
                        what=c("all", "indices", "ijd"),
                        periodic=FALSE, ...,
                        iX=NULL, iY=NULL)

Arguments

X, Y

Point patterns (objects of class "ppp").

rmax

Maximum distance between pairs of points to be counted as close pairs.

twice

Logical value indicating whether all ordered pairs of close points should be returned. If twice=TRUE (the default), each pair will appear twice in the output, as (i,j) and again as (j,i). If twice=FALSE, then each pair will appear only once, as the pair (i,j) with i < j.

what

String specifying the data to be returned for each close pair of points. If what="all" (the default) then the returned information includes the indices i,j of each pair, their x,y coordinates, and the distance between them. If what="indices" then only the indices i,j are returned. If what="ijd" then the indices i,j and the distance d are returned.

distinct

Logical value indicating whether to return only the pairs of points with different indices i and j (distinct=TRUE, the default) or to also include the pairs where i=j (distinct=FALSE).

neat

Logical value indicating whether to ensure that i < j in each output pair, when twice=FALSE.

periodic

Logical value indicating whether to use the periodic edge correction. The window of X should be a rectangle. Opposite pairs of edges of the window will be treated as identical.

...

Extra arguments, ignored by methods.

iX, iY

Optional vectors used to determine whether a point in X is identical to a point in Y. See Details.

Details

These are the efficient low-level functions used by spatstat to find all close pairs of points in a point pattern or all close pairs between two point patterns.

closepairs(X,rmax) finds all pairs of distinct points in the pattern X which lie at a distance less than or equal to rmax apart, and returns them. The result is a list with the following components:

i

Integer vector of indices of the first point in each pair.

j

Integer vector of indices of the second point in each pair.

xi,yi

Coordinates of the first point in each pair.

xj,yj

Coordinates of the second point in each pair.

dx

Equal to xj-xi

dy

Equal to yj-yi

d

Euclidean distance between each pair of points.

If what="indices" then only the components i and j are returned. This is slightly faster and more efficient with use of memory.

crosspairs(X,rmax) identifies all pairs of neighbours (X[i], Y[j]) between the patterns X and Y, and returns them. The result is a list with the same format as for closepairs.

The arguments iX and iY are used when the two point patterns X and Y may have some points in common. In this situation crosspairs(X, Y) would return some pairs of points in which the two points are identical. To avoid this, attach a unique integer identifier to each point, such that two points are identical if their identifier values are equal. Let iX be the vector of identifier values for the points in X, and iY the vector of identifiers for points in Y. Then the code will only compare two points if they have different values of the identifier.

Value

A list with components i and j, and possibly other components as described under Details.

Warning about accuracy

The results of these functions may not agree exactly with the correct answer (as calculated by a human) and may not be consistent between different computers and different installations of R. The discrepancies arise in marginal cases where the interpoint distance is equal to, or very close to, the threshold rmax.

Floating-point numbers in a computer are not mathematical Real Numbers: they are approximations using finite-precision binary arithmetic. The approximation is accurate to a tolerance of about .Machine$double.eps.

If the true interpoint distance d and the threshold rmax are equal, or if their difference is no more than .Machine$double.eps, the result may be incorrect.

Author(s)

\adrian

and \rolf

See Also

closepairs.pp3 for the corresponding functions for 3D point patterns.

Kest, Kcross, nndist, nncross, applynbd, markstat for functions which use these capabilities.

Examples

   d <- closepairs(cells, 0.1)
   head(as.data.frame(d))

   Y <- split(amacrine)
   e <- crosspairs(Y$on, Y$off, 0.1)

spatstat.geom documentation built on Sept. 18, 2024, 9:08 a.m.