build.M.nbr: build.M.nbr

Description Usage Arguments Value Examples

View source: R/contrastMatrix.R

Description

Build the contrast matrix of an KNN graph with n nodes

Usage

1
build.M.nbr(K, nbr.K = NULL, D = NULL)

Arguments

K

number of neighbors for each node

nbr.K

nbr.K[i,] = the node indices ranked by proximity to node i (from the nearest to the farthest)

D

the distance matrix

Value

Returns the contrast matrix of a KNN graph with n nodes

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
set.seed(121)

n <- 5 # number of nodes
X <- runif(n, -1, 1) # nodes are generated from U(-1, 1)
D <- as.matrix(dist(X)) # distance matrix for the nodes
nbr.K <- t(sortIndex(D)) # ranked indices based on distance
M1 <- build.M.nbr(K = 2, nbr.K = nbr.K[,-1])
M2 <- build.M.nbr(K = 2, D = D)

mean(M1 == M2) == 1 #returns TRUE

wenda-1121/RHP documentation built on Feb. 18, 2020, 9:36 p.m.