Re: [R] Nodes edges with similarity matrix

2007-08-29 Thread Birgit Lemcke
Hello,

sorry that I interfer, but I tried to do this

The SymTest matrix:

 A   B   C   D   E   F   G
A 0.3 0.1 0.5 0.7 0.2 0.8 0.1
B 0.1 0.5 0.4 0.6 0.7 0.3 0.7
C 0.5 0.4 0.3 0.5 0.1 0.1 0.5
D 0.7 0.6 0.5 0.4 0.3 0.5 0.7
E 0.2 0.7 0.1 0.3 0.5 0.2 0.1
F 0.8 0.3 0.1 0.5 0.2 0.3 0.5
G 0.1 0.7 0.5 0.7 0.1 0.5 0.1

 g
A graphAM graph with undirected edges
Number of Nodes = 7
Number of Edges = 28

g - new(graphAM, adjMat=SymTest, values=list(weight=0))
  plot(g)
Fehler in as.vector(x, double) : kann nicht nach Vektor umwandeln
(Error in as.vector(x, double) : can not convert to vector)

what goes wrong?

Thanks in advance

Birgit

Am 29.08.2007 um 07:19 schrieb Gabor Grothendieck:

 Try this:

 # test data
 mat - structure(c(1, 0.325141612, 0.002109751, 0.250153137,  
 0.0223676,
 1, 0.342654, 0.1987485, 0.9723831, 0.9644216, 1, 0.7391222, 0.394331,
 0.5460461, 0.7080224, 1), .Dim = c(4L, 4L), .Dimnames = list(
 c(a, b, c, d), c(a, b, c, d)))

 library(sna)

 # draw edges according to value
 gplot(mat, edge.lwd = mat, label = rownames(mat))

 # thresholding at 0.5
  gplot(mat  .5, label = rownames(mat))


 On 8/28/07, H. Paul Benton [EMAIL PROTECTED] wrote:
 Hello,

I apologise if someone has already answered this but I searched  
 and
 googled but didn't find anything.

I have a matrix which gives me the similarity of each item to each
 other. I would like to turn this matrix into something like what they
 have in the graph package with the nodes and edges.
 http://cran.r-project.org/doc/packages/graph.pdf . However I  
 cannot find
 a method to convert my matrix to an object that graph can use.

 my similarity matrix looks like:
 sim[1:4,]
a  b  c  d
 [a]  1.0  0.0223676  0.9723831  0.3943310
 [b]  0.325141612  1.000  0.9644216  0.5460461
 [c]  0.002109751  0.3426540  1.000  0.7080224
 [d]  0.250153137  0.1987485  0.7391222  1.000

 please don't get caught up with the numbers I simple made this to  
 show.
 I have not produce the code yet to make my similitary matrix.

 Does anyone know a method to do this or do I have to write  
 something. :(
 If I do any starter code :D jj. If I've read something wrong or
 misunderstood my apologies.

 cheers,


 Paul


 --
 Research Technician
 Mass Spectrometry
   o The
  /
 o Scripps
  \
   o Research
  /
 o Institute

 __
 R-help@stat.math.ethz.ch 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.


 __
 R-help@stat.math.ethz.ch 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.

Birgit Lemcke
Institut für Systematische Botanik
Zollikerstrasse 107
CH-8008 Zürich
Switzerland
Ph: +41 (0)44 634 8351
[EMAIL PROTECTED]






[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch 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.


Re: [R] Nodes edges with similarity matrix

2007-08-29 Thread Seth Falcon
Birgit Lemcke [EMAIL PROTECTED] writes:

 Hello,

 sorry that I interfer, but I tried to do this

 The SymTest matrix:

  A   B   C   D   E   F   G
 A 0.3 0.1 0.5 0.7 0.2 0.8 0.1
 B 0.1 0.5 0.4 0.6 0.7 0.3 0.7
 C 0.5 0.4 0.3 0.5 0.1 0.1 0.5
 D 0.7 0.6 0.5 0.4 0.3 0.5 0.7
 E 0.2 0.7 0.1 0.3 0.5 0.2 0.1
 F 0.8 0.3 0.1 0.5 0.2 0.3 0.5
 G 0.1 0.7 0.5 0.7 0.1 0.5 0.1

  g
 A graphAM graph with undirected edges
 Number of Nodes = 7
 Number of Edges = 28

 g - new(graphAM, adjMat=SymTest, values=list(weight=0))
   plot(g)
 Fehler in as.vector(x, double) : kann nicht nach Vektor umwandeln
 (Error in as.vector(x, double) : can not convert to vector)

 what goes wrong?

I suspect that you have not installed and loaded Rgraphviz which
contains the code to plot graph objects from the graph package.

Without further details, for example the output of sessionInfo(), it
is difficult to say.

+ seth

-- 
Seth Falcon | Computational Biology | Fred Hutchinson Cancer Research Center
BioC: http://bioconductor.org/
Blog: http://userprimary.net/user/

__
R-help@stat.math.ethz.ch 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.


[R] Nodes edges with similarity matrix

2007-08-28 Thread H. Paul Benton
Hello,

I apologise if someone has already answered this but I searched and
googled but didn't find anything.

I have a matrix which gives me the similarity of each item to each
other. I would like to turn this matrix into something like what they
have in the graph package with the nodes and edges.
http://cran.r-project.org/doc/packages/graph.pdf . However I cannot find
a method to convert my matrix to an object that graph can use.

my similarity matrix looks like:
 sim[1:4,]
a  b  c  d
[a]  1.0  0.0223676  0.9723831  0.3943310
[b]  0.325141612  1.000  0.9644216  0.5460461
[c]  0.002109751  0.3426540  1.000  0.7080224
[d]  0.250153137  0.1987485  0.7391222  1.000

please don't get caught up with the numbers I simple made this to show.
I have not produce the code yet to make my similitary matrix.

Does anyone know a method to do this or do I have to write something. :(
If I do any starter code :D jj. If I've read something wrong or
misunderstood my apologies.

cheers,


Paul


-- 
Research Technician
Mass Spectrometry
   o The
  /
o Scripps
  \
   o Research
  /
o Institute

__
R-help@stat.math.ethz.ch 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.


Re: [R] Nodes edges with similarity matrix

2007-08-28 Thread Gabor Csardi
Paul,

i have no idea what functionality you need from graph, but 
if the igraph package can do what you want then it can 
easily convert this to a graph for you, basically it is just

threshold - 0.5
g - graph.adjacency(simthreshoold)

or you can create a weighted graph:

g - graph.adjacency(sim, weighted=TRUE)

or a weighted graph after a threshold:

sim2 - sim
sim2[ simthreshold ] - 0
g - graph.adjacency(sim2, weighted=TRUE)

etc.

Best,
Gabor

On Tue, Aug 28, 2007 at 02:25:27PM -0700, H. Paul Benton wrote:
 Hello,
 
 I apologise if someone has already answered this but I searched and
 googled but didn't find anything.
 
 I have a matrix which gives me the similarity of each item to each
 other. I would like to turn this matrix into something like what they
 have in the graph package with the nodes and edges.
 http://cran.r-project.org/doc/packages/graph.pdf . However I cannot find
 a method to convert my matrix to an object that graph can use.
 
 my similarity matrix looks like:
  sim[1:4,]
 a  b  c  d
 [a]  1.0  0.0223676  0.9723831  0.3943310
 [b]  0.325141612  1.000  0.9644216  0.5460461
 [c]  0.002109751  0.3426540  1.000  0.7080224
 [d]  0.250153137  0.1987485  0.7391222  1.000
 
 please don't get caught up with the numbers I simple made this to show.
 I have not produce the code yet to make my similitary matrix.
 
 Does anyone know a method to do this or do I have to write something. :(
 If I do any starter code :D jj. If I've read something wrong or
 misunderstood my apologies.
 
 cheers,
 
 
 Paul
 
 
 -- 
 Research Technician
 Mass Spectrometry
o The
   /
 o Scripps
   \
o Research
   /
 o Institute
 
 __
 R-help@stat.math.ethz.ch 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.

-- 
Csardi Gabor [EMAIL PROTECTED]MTA RMKI, ELTE TTK

__
R-help@stat.math.ethz.ch 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.


Re: [R] Nodes edges with similarity matrix

2007-08-28 Thread Seth Falcon
Hi Paul,

H. Paul Benton [EMAIL PROTECTED] writes:
 I have a matrix which gives me the similarity of each item to each
 other. I would like to turn this matrix into something like what they
 have in the graph package with the nodes and edges.
 http://cran.r-project.org/doc/packages/graph.pdf . However I cannot find
 a method to convert my matrix to an object that graph can use.

 my similarity matrix looks like:
 sim[1:4,]
 a  b  c  d
 [a]  1.0  0.0223676  0.9723831  0.3943310
 [b]  0.325141612  1.000  0.9644216  0.5460461
 [c]  0.002109751  0.3426540  1.000  0.7080224
 [d]  0.250153137  0.1987485  0.7391222  1.000

 please don't get caught up with the numbers I simple made this to show.
 I have not produce the code yet to make my similitary matrix.

 Does anyone know a method to do this or do I have to write something. :(
 If I do any starter code :D jj. If I've read something wrong or
 misunderstood my apologies.

The matrix you have can be interpreted as an adjacency matrix where a
value of zero means no relationship and a non-zero value indicates an
edge between two nodes with edge weight determined by the value.

You can create a graph object like this:

library(graph)
g - new(graphAM, adjMat=sim, values=list(weight=0))

The default is to create an undirected graph and in this case you must
provide a symmetric matrix.  Generally I would expect a similarity
matrix to be symmetric, but the similitary (sic) matrix you have above
is not.  In this case, you can use a directed graph:

g - new(graphAM, adjMat=sim, values=list(weight=0),
 edgemode=directed)

To visualize your graph you can use the Rgraphviz package which will
allow you to do:

  plot(g)

You might also be interested in the RBGL package which provides many
powerful graph algorithms.

All of these packages are available via Bioconductor (no bio required)
and can be installed as:

   source(http://bioconductor.org/biocLite.R;)
   biocLite(c(RBGL, Rgraphviz))

+ seth

-- 
Seth Falcon | Computational Biology | Fred Hutchinson Cancer Research Center
BioC: http://bioconductor.org/
Blog: http://userprimary.net/user/

__
R-help@stat.math.ethz.ch 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.


Re: [R] Nodes edges with similarity matrix

2007-08-28 Thread Seth Falcon
Along with the example I gave using graphAM, you might also want to
look at the help page for the distGraph class which may be more
directly what you want:

  library(graph)
  class ? distGraph

__
R-help@stat.math.ethz.ch 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.


Re: [R] Nodes edges with similarity matrix

2007-08-28 Thread Gabor Grothendieck
Try this:

# test data
mat - structure(c(1, 0.325141612, 0.002109751, 0.250153137, 0.0223676,
1, 0.342654, 0.1987485, 0.9723831, 0.9644216, 1, 0.7391222, 0.394331,
0.5460461, 0.7080224, 1), .Dim = c(4L, 4L), .Dimnames = list(
c(a, b, c, d), c(a, b, c, d)))

library(sna)

# draw edges according to value
gplot(mat, edge.lwd = mat, label = rownames(mat))

# thresholding at 0.5
 gplot(mat  .5, label = rownames(mat))


On 8/28/07, H. Paul Benton [EMAIL PROTECTED] wrote:
 Hello,

I apologise if someone has already answered this but I searched and
 googled but didn't find anything.

I have a matrix which gives me the similarity of each item to each
 other. I would like to turn this matrix into something like what they
 have in the graph package with the nodes and edges.
 http://cran.r-project.org/doc/packages/graph.pdf . However I cannot find
 a method to convert my matrix to an object that graph can use.

 my similarity matrix looks like:
  sim[1:4,]
a  b  c  d
 [a]  1.0  0.0223676  0.9723831  0.3943310
 [b]  0.325141612  1.000  0.9644216  0.5460461
 [c]  0.002109751  0.3426540  1.000  0.7080224
 [d]  0.250153137  0.1987485  0.7391222  1.000

 please don't get caught up with the numbers I simple made this to show.
 I have not produce the code yet to make my similitary matrix.

 Does anyone know a method to do this or do I have to write something. :(
 If I do any starter code :D jj. If I've read something wrong or
 misunderstood my apologies.

 cheers,


 Paul


 --
 Research Technician
 Mass Spectrometry
   o The
  /
 o Scripps
  \
   o Research
  /
 o Institute

 __
 R-help@stat.math.ethz.ch 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.


__
R-help@stat.math.ethz.ch 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.