[R] i graph library: how can generates a fully connected graph from a similarity matrix

Gábor Csárdi csardi.gabor at gmail.com
Fri Dec 12 09:46:18 CET 2008


On Fri, Dec 12, 2008 at 2:10 AM, dinesh kumar <barupal at gmail.com> wrote:
> Dear R users
>
> I have a similarity matrix 100X100. I used this matrix as adjacency matrix
> to generate igraph graph object. Its a fully connected graph. The similarity
> score is the weight of the edge. Now I want to remove all possible lowest
> scores (edges) but I want to get back a fully connected graph (dont want any
> isolated vertex).How can I do it?

Actually your matrix is only 87x87.

If you mean that you want a graph with 87 vertices, and some edge
weights being zero, then you can simply do (assuming there are no
negative edge weights)

G <- graph.adjacency(adjmat+1, mode="undirected", weighted=TRUE)
E(G)$weight <- E(G)$weight - 1

If you mean that you want to remove isolate vertices after creating
the graph, that would be:

G <- graph.adjacency(adjmat, mode="undirected", weighted=TRUE)
G <- remove.vertices(G, V(G)[ degree(G)==0 ])

(For your data nothing really happens, there are no isolate vertices.)

> Also is there any possibility that I can remove the edges which dont pass a
> threshold (below 70% similarity score).

You can remove it initially, from the matrix:

adjmat2 <- adjmat
adjmat2[ adjmat2 < 0.7 ] <- 0
G <- graph.adjacency(adjmat2, mode="undirected", weighted=TRUE)

or after, from the graph itself:

G <- graph.adjacency(adjmat+1, mode="undirected", weighted=TRUE)
E(G)$weight <- E(G)$weight - 1
G2 <- delete.edges(G, E(G)[ weight < 0.7 ])

Gabor

ps. there is also an igraph mailing list, you can find it from the
igraph homepage. Just in case I miss your messages here.

> I attached the similarity matrix.
>
> I would appreciate the reply
>
> Thanks in advance
>
> Dinesh
>
>
>
> --
> Dinesh Kumar Barupal
> Junior Specialist
> Metabolomics Fiehn Lab
> UCD Genome Center
> 451 East Health Science Drive
> GBSF Builidng
> University of California
> DAVIS
> 95616
> http://fiehnlab.ucdavis.edu/staff/kumar
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>



-- 
Gabor Csardi <Gabor.Csardi at unil.ch>     UNIL DGM



More information about the R-help mailing list