igraph-help
[Top][All Lists]
Advanced

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

Re: [igraph] Structural equivalence / converting weighted graphs for SN


From: Gábor Csárdi
Subject: Re: [igraph] Structural equivalence / converting weighted graphs for SNA and back
Date: Fri, 10 Apr 2009 10:14:29 +0200

Hi Magnus,

my answers are below.

On Thu, Apr 9, 2009 at 10:04 PM, Magnus Torfason <address@hidden> wrote:
> 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?

It depends how you define it. Probably take a look at
?similarity.jaccard and there is one or two more on the manual page.

> 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()

Yes, you are.

> (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.
>

Yes, it might be possible to this in a faster way (with probably a lot
more coding), if the graph is sparse.

Gabor

[...]

-- 
Gabor Csardi <address@hidden>     UNIL DGM




reply via email to

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