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 or reach. The latter two are pretty straight-forward, so I am posting functions that will let you easily calculate those two measures. distance-weighted reachHere 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 (
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:
`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)` ` }` |

R Resources > Social Networks in R >