corr_nn {nntmvn} | R Documentation |
Find ordered nearest neighbors based on correlation, assuming the absolute value of the correlation is monotonically decreasing with distance. Returns an n X (m + 1) matrix, each row indicating the m + 1 nearest neighbors including itself.
Description
Find ordered nearest neighbors based on correlation, assuming the absolute value of the correlation is monotonically decreasing with distance. Returns an n X (m + 1) matrix, each row indicating the m + 1 nearest neighbors including itself.
Usage
corr_nn(covmat, m)
Arguments
covmat |
the covariance matrix |
m |
the number of nearest neighbors |
Value
an n X (m + 1) matrix
Examples
library(RANN)
library(nntmvn)
set.seed(123)
d <- 3
n <- 100
locs <- matrix(runif(d * n), n, d)
covparms <- c(2, 0.01, 0)
covmat <- GpGp::matern15_isotropic(covparms, locs)
m <- 10
NNarray_test <- RANN::nn2(locs, k = m + 1)[[1]]
NNarray <- nntmvn::corr_nn(covmat, m)
cat("Number of mismatch is", sum(NNarray != NNarray_test, na.rm = TRUE))
[Package nntmvn version 1.2.0 Index]