Wmat: The incidence matrix 'W' for the NN digraph

View source: R/NNCTFunctions.R

WmatR Documentation

The incidence matrix W for the NN digraph

Description

Returns the W=(w_ij) matrix which is used to compute Q, R and T values in the NN structure. w_{ij}=I( point j is a NN of point i)) i.e., w_{ij}=1 if point j is a NN of point i and 0 otherwise.

The argument ties is a logical argument (default=FALSE) to take ties into account or not. If TRUE the function takes ties into account by making w_{ij}=1/m if point j is a NN of point i and there are m tied NNs and 0 otherwise. If FALSE, w_{ij}=1 if point j is a NN of point i and 0 otherwise. The matrix W is equivalent to A=(a_{ij}) matrix with k=1, i.e., Wmat(X)=aij.mat(X,k=1).

The argument is.ipd is a logical argument (default=TRUE) to determine the structure of the argument x. If TRUE, x is taken to be the inter-point distance (IPD) matrix, and if FALSE, x is taken to be the data set with rows representing the data points.

Usage

Wmat(x, ties = FALSE, is.ipd = TRUE, ...)

Arguments

x

The IPD matrix (if is.ipd=TRUE) or a data set of points in matrix or data frame form where points correspond to the rows (if is.ipd = FALSE).

ties

A logical parameter (default=FALSE) to take ties into account in computing the W matrix, so, if it is TRUE, w_{ij}=1/m if point j is a NN of point i and there are m tied NNs and 0 otherwise and if FALSE, w_{ij}=1 if point j is a NN of point i and 0 otherwise.

is.ipd

A logical parameter (default=TRUE). If TRUE, x is taken as the inter-point distance matrix, otherwise, x is taken as the data set with rows representing the data points.

...

are for further arguments, such as method and p, passed to the dist function.

Value

The incidence matrix W=(w_ij) where w_{ij}=I( point j is a NN of point i)), i.e., w_{ij}=1 if point j is a NN of point i and 0 otherwise.

Author(s)

Elvan Ceyhan

See Also

aij.mat, aij.nonzero, and aij.theta

Examples

n<-3
X<-matrix(runif(3*n),ncol=3)
ipd<-ipd.mat(X)
Wmat(ipd)
Wmat(X,is.ipd = FALSE)

n<-5
Y<-matrix(runif(3*n),ncol=3)
ipd<-ipd.mat(Y)
Wmat(ipd)
Wmat(Y,is.ipd = FALSE)
Wmat(Y,is.ipd = FALSE,method="max")

Wmat(Y,is.ipd = FALSE)
aij.mat(Y,k=1)

#1D data points
X<-as.matrix(runif(5)) # need to be entered as a matrix with one column
#(i.e., a column vector), hence X<-runif(5) would not work
ipd<-ipd.mat(X)
Wmat(ipd)
Wmat(X,is.ipd = FALSE)

#with ties=TRUE in the data
Y<-matrix(round(runif(15)*10),ncol=3)
ipd<-ipd.mat(Y)
Wmat(ipd,ties=TRUE)
Wmat(Y,ties=TRUE,is.ipd = FALSE)


nnspat documentation built on May 29, 2024, 10:03 a.m.