reduce_nodes_to_focus: Reduces the number of nodes in a network to those which are...

Description Usage Arguments Details Examples

View source: R/reduce_nodes_to_focus.R

Description

There is the option to select all nodes linked to the set of key nodes within a certain number of steps, or only in one direction

Usage

1
reduce_nodes_to_focus(startmat, maxdist, keynodes, tofrom)

Arguments

startmat

the starting adjacency matrix (NOT an igraph object), to be reduced

maxdist

the greatest distance (in terms of the number of links traversed) at which a node is considered connected to the key nodes

keynodes

the set of key nodes (e.g., c(1,5,9))

tofrom

choice between keeping nodes that are (1) linked towards the key nodes, 'to', (2) linked away from the key nodes, 'from', or (3) either to or from, 'either'

Details

Created 2020-05-29

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
j <- matrix(rbinom(n=100,p=0.1,size=1),nrow=10)
diag(j) <- 0
jnames <- letters[1:10]
library(igraph)
ji <- graph_from_adjacency_matrix(j)
V(ji)$names <- jnames
plot.igraph(ji, vertex.label=V(ji)$names, vertex.color='light green', main='Starting matrix')

jout <- reduce_nodes_to_focus(startmat=j, maxdist=2, keynodes=c(1,5), tofrom='to')
jouti <- graph_from_adjacency_matrix(jout$outmat)
V(jouti)$names <- jnames[jout$keepers]
plot(jouti, vertex.label=V(jouti)$names, vertex.color='light green', main='2 steps TO key nodes 1 and 5')

jout2 <- reduce_nodes_to_focus(startmat=j, maxdist=2, keynodes=c(1,5), tofrom='from')
jout2i <- graph_from_adjacency_matrix(jout2$outmat)
V(jout2i)$names <- jnames[jout2$keepers]
plot(jout2i, vertex.label=V(jout2i)$names, vertex.color='light green', main='2 steps FROM key nodes 1 and 5')

jout3 <- reduce_nodes_to_focus(startmat=j, maxdist=2, keynodes=c(1,5), tofrom='either')
jout3i <- graph_from_adjacency_matrix(jout3$outmat)
V(jout3i)$names <- jnames[jout3$keepers]
plot(jout3i, vertex.label=V(jout3i)$names, vertex.color='light green', main='2 steps TO OR FROM key nodes 1 and 5')

GarrettLab/INApreliminary documentation built on June 7, 2021, 10:59 a.m.