### 04. Node-level Calculations

There are certain pre-packaged commands in statnet and igraph that allows you to calculate various node-level measures. The statnet package seems to have a more comprehensive list, though igraph has a couple of measures that statnet does not have. The biggest problems (for my purposes) are that igraph does not have a command for calculating information centrality, and neither package seems to have commands for reach or distance-weighted reach. The latter two are pretty straight-forward, so I am posting functions that will let you easily calculate those two measures.

Here is a list of commands for node-level calculations included in the two packages. To find out what algorithms they use and how to use the commands, just look at the documentation with the help command for each index (?degree for example).

 Node-level index statnet igraph degree degree() degree() betweenness betweenness() betweenness() power (Bonacich 1987) bonpow() bonpow() closeness closeness() closeness() eigenvector centrality evcent() evcent() flow betweenness flowbet() N/A graph centrality (Harary) graphcent() N/A information centrality infocent() N/A load centrality loadcent() N/A prestige prestige() N/A stress centrality stresscent() N/A reach see codes below see codes below distance-weighted reach see codes below see codes below alpha centrality N/A alpha.centrality() Kleinberg’s authority score N/A authority.score() Kleinberg’s hub score N/A hub.score()

Reach and Distance-weighted Reach

For igraph:

Reach: 2-reach and 3-reach is simply the proportion of nodes you can reach within 2 steps or 3 steps, respectively. Here are codes for calculating this in igraph:

**Update 3/17/2015: I had forgotten to update these codes after igraph v0.6 updates. These should be now fixed.

2-reach:
`reach2=function(x){`
` r=vector(length=vcount(x))`
` for (i in 1:vcount(x)){`
` n=neighborhood(x,2,nodes=i)`
` ni=unlist(n)`
` l=length(ni)`
` r[i]=(l)/vcount(x)}`
` r}`

3-reach:
`reach3=function(x){`
` r=vector(length=vcount(x))`
` for (i in 1:vcount(x)){`
` n=neighborhood(x,3,nodes=i)`
` ni=unlist(n)`
` l=length(ni)`
` r[i]=(l)/vcount(x)}`
` r}`

distance-weighted reach:
`dwreach=function(x){`
` distances=shortest.paths(x) #create matrix of geodesic distances`
` diag(distances)=1 # replace the diagonal with 1s`
` weights=1/distances # take the reciprocal of distances`
` apply(weights,1,sum) # sum for each node (row)`
` }`

Comments