***** To join INSNA, visit http://www.insna.org *****
Hi Jesse,
I'd recommend posting these types of tool-specific questions to the
appropriate mailing list ( in this case, statnet_help:
https://mailman13.u.washington.edu/mailman/listinfo/statnet_help) as
they may be a bit specific for the general SOCNET audience. I'll try
to answer your question with R examples below.
On 03/04/2014 03:32 PM, Jesse Sayles wrote:
>
>>From what I can tell, the ego networks generated with ego.extract() is not
> stored as a separate matrix, but appears to be an object that is still
> associated with my original network. I want to convert it to a unique
> matrix so that I can remove the focal node and merge it with other ego
> networks as Moses described.
If you are going to merge networks, you will probably need a system to
keep track of the original ids associated with each vertex, as the
matrix ids will changes each time you extract a sub matrix. Since I'm
most familiar with it, I'd suggest using the "network" package (which
mostly inter-operates with the sna package) and attaching a vertex
attribute or vertex name with the ids. (I assume igraph probably
supports this as well?)
>
> The following code:
>
> ego224 = ego.extract(mx, ego=224, neighborhood = "combined")
> ego224net = as.matrix(ego224)
>
> gives me this:
>
>> ego224net
> [,1]
> AA Integer,7396
Is it possible that vertex 224 in the network "mx" is an isolate? It
appears that the ego.extract() function should return a list of matrices
containing an ego net for each ego supplied in the 'ego' argument.
>
> Again, *my overall goa*l is to create an "ego" network from two focal
> nodes, to exclude those nodes in the "two-ego" network, and then
calculate
> density, centerlization, and other measures on the "two-ego" network.
So if
> you know another way to do this, feel free to tell me I am on the wrong
> path and set me straight.
>
> More details of my ultimate goal:
> Would anyone know how to extract an ego-neighborhood for two nodes in the
> SNA R package?
If I'm understanding what you are trying to do, you may find the
combination of get.neighborhood() and the get.inducedSubgraph()
functions in network give you want you want.
library(sna)
library(network)
# make an example 'master' network because I don't have your data
mx<-rgraph(n=10,tprob=.5)
# convert to a network object
mxNet<-as.network(mx)
# create a list of vertices in the combined (undirected) neighborhood of
vertices 2 and 3
ngs <-union(get.neighborhood(mxNet,v=2),get.neighborhood(mxNet,v=3))
# make sure 2 and 3 are removed from list of neighbors (in case there
was a tie between them)
ngs<-setdiff(ngs,c(2,3))
# get a subnetwork that includes only neighbors of 2 and 3, but not 2 and 3
mxNetNo2_3<-get.inducedSubgraph(mxNet,v=ngs)
# compute density
gden(mxNetNo2_3)
# print it as a matrix
as.matrix(mxNetNo2_3)
NOTE: in the output above the rows and columns of the matrix are labeled
using the default vertex.names property of the original network we
created. However, these are NOT the matrix indices you would use to
query the network
best,
-skye
_____________________________________________________________________
SOCNET is a service of INSNA, the professional association for social
network researchers (http://www.insna.org). To unsubscribe, send
an email message to [log in to unmask] containing the line
UNSUBSCRIBE SOCNET in the body of the message.
|