n_density: Calculate Neighborhood Density

View source: R/n_density.R

n_densityR Documentation

Calculate Neighborhood Density

Description

n_density takes the n most strongly correlated neighbors of a target vector and their correlation coefficients to calculate a mean correlation coefficient. The higher the value of this coefficient, the denser the neighborhood.

Usage

n_density(vec, neighbors, n = 8)

Arguments

vec

The vector for which the neighbor density is to be calculated. This is either a vector saved as object or a row of the neighbors data frame or matrix. If a row of a data frame or matrix is specified, this row is excluded as competitor for the nearest neighbor (as a row will be closest to itself).

neighbors

The potential neighbors, usually given as data frame or matrix.

n

The number of neighbors wanted as output. Defaults to 8.

Author(s)

D. Schmitz

Examples


### a vector saved as object & a matrix of neighbors

vector <- runif(50, 0, 10)
data("gdsm_mat")

n_density(vec = vector, neighbors = gdsm_mat)

n_density(vec = vector, neighbors = gdsm_mat, n = 4)


### a vector specified by its name & its matrix of neighbors

data("gdsm_mat")

n_density(vec = "var12", neighbors = gdsm_mat)

n_density(vec = "var12", neighbors = gdsm_mat, n = 4)


dosc91/gdsm documentation built on Aug. 21, 2022, 4:16 a.m.