igraph-help
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[igraph] Structural equivalence / converting weighted graphs for SNA and


From: Magnus Torfason
Subject: [igraph] Structural equivalence / converting weighted graphs for SNA and back
Date: Thu, 09 Apr 2009 16:04:21 -0400
User-agent: Thunderbird 2.0.0.21 (Windows/20090302)

Hi everyone,

I have two related questions, stemming from my need for structural equivalence calculations of some weighted edge-list-formatted graphs.

I looked in the igraph package to see if there was a function to calculate this, but did not find it. So for my first question:

   Question 1: Is there a way to calculate structural equivalence
               correlations in igraph?

I did find that the sna package has the sedist function which does what I need on adjacency matrices. So I used igraph to convert my data to adjacency form, calculated the structural equivalence and converted back, as follows:

  # Use igraph to convert to adjacency matrix
  g.in = igraph::graph.data.frame(d.in, directed=FALSE)
  m.in = igraph::get.adjacency(g.in, attr="weight")

  # Use SNA to calculate structural equivalence
  m.out = sedist(m.in,method="hamming",mode="graph")
  dimnames(m.out) = dimnames(m.in)

  # Use igraph to convert back to a data frame
  g.out = igraph::graph.adjacency(m.out, mode="undirected",
                                  weighted=TRUE)
  d.out = data.frame( cbind( igraph::get.edgelist(g.out),
                             igraph::E(g.out)$weight))

As can be seen from the code, I am binding the result from get.edgelist with the weight list. Which leads me to the second question:

  Question 2: Am I guaranteed to get the edges in the same order when
              I list them using get.edgelist() as when I list them
              using E()

(My examinations do suggest that this is the case for the first 1 entries at least, but I'm not sure if I can be guaranteed to get that every single time)

Best,
Magnus

ps. Question 3: If I am going about this in a silly and inefficient
                manner, and if there are better ways to achieve the
                same goal, I would of course be grateful for pointers
                to that effect.






reply via email to

[Prev in Thread] Current Thread [Next in Thread]