| knn {igraph} | R Documentation |
Average nearest neighbor degree
Description
Calculate the average nearest neighbor degree of the given vertices and the same quantity in the function of vertex degree
Usage
knn(
graph,
vids = V(graph),
mode = c("all", "out", "in", "total"),
neighbor.degree.mode = c("all", "out", "in", "total"),
weights = NULL
)
Arguments
graph |
The input graph. It may be directed. |
vids |
The vertices for which the calculation is performed. Normally it
includes all vertices. Note, that if not all vertices are given here, then
both ‘ |
mode |
Character constant to indicate the type of neighbors to consider
in directed graphs. |
neighbor.degree.mode |
The type of degree to average in directed graphs.
|
weights |
Weight vector. If the graph has a |
Details
Note that for zero degree vertices the answer in ‘knn’ is
NaN (zero divided by zero), the same is true for ‘knnk’
if a given degree never appears in the network.
The weighted version computes a weighted average of the neighbor degrees as
k_{nn,u} = \frac{1}{s_u} \sum_v w_{uv} k_v,
where s_u = \sum_v w_{uv} is the sum of the incident
edge weights of vertex u, i.e. its strength.
The sum runs over the neighbors v of vertex u
as indicated by mode. w_{uv} denotes the weighted adjacency matrix
and k_v is the neighbors' degree, specified by neighbor_degree_mode.
Value
A list with two members:
- knn
-
A numeric vector giving the average nearest neighbor degree for all vertices in
vids. - knnk
-
A numeric vector, its length is the maximum (total) vertex degree in the graph. The first element is the average nearest neighbor degree of vertices with degree one, etc.
Related documentation in the C library
avg_nearest_neighbor_degree().
Author(s)
Gabor Csardi csardi.gabor@gmail.com
References
Alain Barrat, Marc Barthelemy, Romualdo Pastor-Satorras, Alessandro Vespignani: The architecture of complex weighted networks, Proc. Natl. Acad. Sci. USA 101, 3747 (2004)
See Also
Other structural.properties:
bfs(),
component_distribution(),
connect(),
constraint(),
coreness(),
degree(),
dfs(),
distance_table(),
edge_density(),
feedback_arc_set(),
feedback_vertex_set(),
girth(),
is_acyclic(),
is_dag(),
is_matching(),
k_shortest_paths(),
reciprocity(),
subcomponent(),
subgraph(),
topo_sort(),
transitivity(),
unfold_tree(),
which_multiple(),
which_mutual()
Examples
# Some trivial ones
g <- make_ring(10)
knn(g)
g2 <- make_star(10)
knn(g2)
# A scale-free one, try to plot 'knnk'
g3 <- sample_pa(1000, m = 5)
knn(g3)
# A random graph
g4 <- sample_gnp(1000, p = 5 / 1000)
knn(g4)
# A weighted graph
g5 <- make_star(10)
E(g5)$weight <- seq(ecount(g5))
knn(g5)