nndist.lpp: Nearest neighbour distances on a linear network

View source: R/nndistlpp.R

nndist.lppR Documentation

Nearest neighbour distances on a linear network

Description

Given a pattern of points on a linear network, compute the nearest-neighbour distances, measured by the shortest path in the network.

Usage

## S3 method for class 'lpp'
nndist(X, ..., k=1, by=NULL, method="C")

Arguments

X

Point pattern on linear network (object of class "lpp").

k

Integer, or integer vector. The algorithm will compute the distance to the kth nearest neighbour.

by

Optional. A factor, which separates X into groups. The algorithm will compute the distance to the nearest point in each group.

method

Optional string determining the method of calculation. Either "interpreted" or "C".

...

Ignored.

Details

Given a pattern of points on a linear network, this function computes the nearest neighbour distance for each point (i.e. the distance from each point to the nearest other point), measuring distance by the shortest path in the network.

If method="C" the distances are computed using code in the C language. If method="interpreted" then the computation is performed using interpreted R code. The R code is much slower, but is provided for checking purposes.

The kth nearest neighbour distance is infinite if the kth nearest neighbour does not exist. This can occur if there are fewer than k+1 points in the dataset, or if the linear network is not connected.

If the argument by is given, it should be a factor, of length equal to the number of points in X. This factor effectively partitions X into subsets, each subset associated with one of the levels of X. The algorithm will then compute, for each point of X, the distance to the nearest neighbour in each subset.

Value

A numeric vector, of length equal to the number of points in X, or a matrix, with one row for each point in X and one column for each entry of k. Entries are nonnegative numbers or infinity (Inf).

Author(s)

\adrian

See Also

lpp

Examples

   X <- runiflpp(12, simplenet)
   nndist(X)
   nndist(X, k=2)

   marks(X) <- factor(rep(letters[1:3], 4))
   nndist(X, by=marks(X))

spatstat.linnet documentation built on Nov. 2, 2023, 6:10 p.m.