R: Adding vertex attributes to a network (using statnet) - r

I'm currently doing a Network Analysis in R, using the Statnet package (http://statnet.csde.washington.edu/)
So far I have been able to:
1) Construct Social Networks using the network() function. The information I had was originally contained in a incidence matrix form (one row per project, project members in the columns), which I transformed to adjency (socio-matrix) form before building the networks in R.
2) Plot the networks and compute general statistics (both for the overall network and for network vertexes)
3) Add external vertex attributes to the networks
4) Plot the networks with vertexes in different colors according to their attributes.
Right now I would like to complement my analysis by adding edge attributes to the network (to differentiate relationships, for example different kinds of projects).
I know I can use the set.edge.attribute() function, and that I need to input a vector of the same size as the total of edges that exist in the network. However, I don't know exactly how to sort this vector of edge attributes, in order for the function to assign them correctly to the corresponding edges.
Anybody knows how the network() function sorts edges internally? Any ideas on how to sort my vector of edge attributes in order to get a appropriate matching?
Thanks in advance for your help!

The network() function can create networks from various types of inputs (such as an edgelist or an adjacency matrix) so it would help if you gave a bit more of a code example explaining how you are creating the network and the format of the structure your edge attribute data are in.
I believe that in general network() will create the edges in the same order as the input edgelist. So if your edge attribute vector is in the same order as your original data, you should be able to use set.edge.attribute() safely. If your edge attributes are in a matrix form, you can use set.edge.value().

Related

How do I convert a simple weighted graph to a hypergraph?

I have found a partitioning algorithm that works on hypergraphs and its name is hMETIS, but my input is in the form of a simple weighted graph. Is there any technique that maps a graph to a hypergraph?
In general: No.
A graph contains information on binary interactions between two vertices, and there is no way to extract the information about the higher order interactions.
In short, if I give you a hypergraph I can use (multiple methods) to turn it into a graph, but that graph could be the result of multiple hypergraphs.
There are a few exceptions to this, notably if you have more information about the vertices outside of the graph, or if the graph is bipartite.

Does igraph has "has_path" function?

I am trying to port code from python NetworkX to R igraph. In NetworkX there is a function with the name has_path that finds if two vertices have a path. I want to find in an efficient way all the vertices of a graph that don't have an edge between them but they have a path.
I think you can use the code below to check if there is a path from vertex V1 to V2 (the graph can be directed or undirected)
c(!is.infinite(distances(g, V1, V2, mode = "out")))
If you need to check this repeatedly in an undirected graph, simply break it into connected components and check if both vertices are within the same component. This will be very efficient, as the components need to be found only once.
See the components function. It gives you a membership vector. You need to check if the position corresponding to the two vertices has the same value (same component index).
If the graph is directed, the simplest solution is the one posted by #ThomasIsCoding. This is perfectly fine for a one-time check. Speeding up repeated checks is more trouble and warrants its own question.

Visualizing Multiple Networks in R using Igraph

I need to visualize a very large number (10k) of distinct networks, all on the same page, and label each node a type (binary). Each network aside from a few are relatively small. Link lengths/weighting is not important for this dataset, and a high degree of overlap on the bigger networks is fine as long as density is evident.
I have gone over some of the Igraph documentation and have been able to create individual graphs using a node/link list. However, I would like some insight if possible on how to translate this large number of networks (currently just 10k arrays with node identity and type inside) into 10k plots, and whether this is a feasible task with Igraph.
Any insight is greatly appreciated.

How to compute the propinquity of a graph in R?

I would like to test if the geographical location of my vertices (ie I have a matrix giving the distance between each pair of actors of my network) has an influence on the presence/absence of edges. If I have correctly understood, this feature is called propinquity....
In other words, I would like to know if two vertices are more likely (or less likely) to be connected if their distance is small.
Do you have any idea of how to do that in R? I usually use igraph but if another library does that I will use it of course :-).

Clustering in Gephi (Louvain Method)

I have started to work with gephi to help me display a dataset.
The dataset contains:
tags (terms for a certain picture) as nodes
Normalized Google Similarity Distance between those tags as edges with a weight (between 0 und 1)
Every tag is connected to every other tag, as long as they both belong to the same picture. So I have one cluster of nodes and edges for every picture.
I have now imported this dataset to gephi in the following format:
nodes: id, label
edges: target, source, weight (between 0 and 1)
Like 500 nodes and 6000 edges.
My problem now is that after importing all those nodes and edges the graph looks kind of bunched with no real order. Every cluster of every picture is mixed into other clusters of other pictures.
Now using Modularity as Partition algorithm (which should use the Louvain method) the graph is getting colored, each color represent a picture. Now I can split this mess, using the Force Atlas 2 Layout.
I now have a colored graph with something like 15 clusters (every cluster represent 1 picture)
Now I want to cluster those clusters again using tags (nodes) according to their Normalized google distance (weight of the edges), which should then be tags which are somewhat equal in their meaning.
I hope you guys understand what I want to accomplish.
I can also upload a picture to clarify it.
Thanks a lot
I don't think you can do that with the standard version of Gephi. You would need to develop a plugin to implement the very last step of your process.
Gephi is good for visualizing and browsing graphs, but (for now) there are more complete tools when it comes to processing topological properties. for instance, the igraph library (available in C, R and python) might be more appropriate for you. And note that you can use a file format compatible with both Gephi and igraph, which allows you to use both tools on the same data.
I was able to solve my problem. I had to import every one of these 15 clusters on their own. In this way i could use the Modularity method on just those few.

Resources