nearest neighbour distances from data in one or two dimensions
nearest neighbour distances from data in one or two dimensions
This function calculates the k nearest neighbour distance from each value in x to the remainder of the data. In two dimensions, Euclidean distance is used after standardising the data to have unit variance in each component.
nnbr(x, k)
Arguments
x: the vector, or two-column matrix, of data.
k: the required order of nearest neighbour.
Returns
the vector of nearest neighbour distances.
Details
see Section 1.7.1 of the reference below.
References
Bowman, A.W. and Azzalini, A. (1997). Applied Smoothing Techniques for Data Analysis: the Kernel Approach with S-Plus Illustrations.
Oxford University Press, Oxford.
See Also
none.
Examples
x <- rnorm(50)hw <- nnbr(x,10)hw <- hw/exp(mean(log(hw)))sm.density(x, h.weights=hw)