n_density.Rdn_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.
n_density(vec, neighbors, n = 8)
| 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 | The potential neighbors, usually given as data frame or matrix. |
| n | The number of neighbors wanted as output. Defaults to |
D. Schmitz
### a vector saved as object & a matrix of neighbors vector <- runif(50, 0, 10) data("gdsm_mat") n_density(vec = vector, neighbors = gdsm_mat) #> [1] 0.2224997 n_density(vec = vector, neighbors = gdsm_mat, n = 4) #> [1] 0.2436874 ### a vector specified by its name & its matrix of neighbors data("gdsm_mat") n_density(vec = "var12", neighbors = gdsm_mat) #> [1] 0.2120284 n_density(vec = "var12", neighbors = gdsm_mat, n = 4) #> [1] 0.2380132