Re: [R-sig-phylo] Collapsing nodes using node.labels

2011-09-28 Thread Emmanuel Paradis
Hello Daniel,

Try this small manipulation ('tr' is your tree and 'node' stores the label of 
the node): 

i - which(tr$node.label == node)
j - which(tr$edge[, 2] == i + Ntip(tr))
tr$edge.length[j] - 0

Then di2multi(tr) will do the job. (Hopefully, there's originally no 
zero-length branch in tr.)

HTH

Emmanuel
-Original Message-
From: Daniel Rafael Miranda-Esquivel dmira...@uis.edu.co
Sender: r-sig-phylo-boun...@r-project.org
Date: Wed, 28 Sep 2011 00:21:43 
To: r-sig-phylo@r-project.org
Subject: [R-sig-phylo] Collapsing nodes using node.labels

 Hello all,


I am trying to collapse some nodes in a tree but using node.label and
not  edge.length, is there a way to convert  node.label to
edge.length? or a function to collapse a node but using node.label
directly?


Daniel

___
R-sig-phylo mailing list
R-sig-phylo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-phylo

___
R-sig-phylo mailing list
R-sig-phylo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-phylo


Re: [R-sig-phylo] Negative Eigenvalues from Phylo Distance Matrix

2011-09-28 Thread Klaus Schliep
Hi Jonathan,

you probably mixed up positive matrices and positive definite matrices.
To have only positive eigen values a matrix must be positive definite.
Covariance matrices are for example are always positive semi-definite,
even though they can contain negative entries.
D is symmetric therefore all eigen values are reel and positive
therefore the largest eigen value is positive (Perron–Frobenius
theorem).

Regards
Klaus

On 9/27/11, Jonathan Mitchell jonsmit...@gmail.com wrote:
 Hello!

 I tried on some simulated trees last night and they weren't working, but
 after your message I started a fresh R session and now solve() works fine
 for both my ultrametric tree, and my simulated trees. No idea what happened
 there, but thanks!

 Unfortunately, I still am getting almost all negative eigenvalues for the
 decomposition of the distance matrix, which doesn't make sense to me. I was
 under the impression that the distance matrix from an ultrametric tree
 should be Euclidean. Further, I can confirm that the distance matrix is
 supposed to be euclidean by using the is.euclid() function from ade4
 [is.euclid(as.dist(D)) returns TRUE], which means I have no idea why
 eigen(D) is giving me negative eigenvalues...

 Any thoughts?

 --Jon

 On Tue, Sep 27, 2011 at 12:23 AM, Emmanuel Paradis
 emmanuel.para...@ird.frwrote:

 Hi John,

 I tried with a couple of simulated trees (ultrametric or not) and got no
 error. Have you tried using the 'tol' argument of solve()?

 Emmanuel
 -Original Message-
 From: Jonathan Mitchell mitchel...@uchicago.edu
 Sender: r-sig-phylo-boun...@r-project.org
 Date: Mon, 26 Sep 2011 17:42:49
 To: r-sig-phylo@r-project.org
 Reply-To: jonsmit...@gmail.com
 Subject: [R-sig-phylo] Negative Eigenvalues from Phylo Distance Matrix

 Hello all,

 I've run into a problem trying to find the eigen vectors for a
 phylogenetic
 distance matrix. Namely, the transposed vector matrix crossed with the
 matrix itself is singular. Also, the eigenvalues for the distance matrix
 proper are almost all negative, which I don't understand whatsoever.

 #Given a tree with branch lengths (in my case, it's ultrametric)
 D - cophenetic(tree)
 eD - eigen(D, symmetric=TRUE)$vectors  #note that all elements except the
 first in eD$values are negative for me
 inv - solve(t(eD)%*%eD)  #this is what I really want, the inverse of the
 transposed matrix of vectors multiplied by itself

 Error in solve.default(t(eD) %*% eD) :
  system is computationally singular: reciprocal condition number =
 2.46807e-29

 Any help would be greatly appreciated!

 -- Jon

 _

 Jonathan S. Mitchell
 http://home.uchicago.edu/~mitchelljs/

 PhD Student
 Committee on Evolutionary Biology
 The University of Chicago
 1025 57th Str, Culver Hall 402
 Chicago, IL 60637

 Geology Department
 The Field Museum of Natural History
 1400 S. Lake Shore Dr.
 Chicago, IL 60605

 [[alternative HTML version deleted]]

 ___
 R-sig-phylo mailing list
 R-sig-phylo@r-project.org
 https://stat.ethz.ch/mailman/listinfo/r-sig-phylo


   [[alternative HTML version deleted]]

 ___
 R-sig-phylo mailing list
 R-sig-phylo@r-project.org
 https://stat.ethz.ch/mailman/listinfo/r-sig-phylo



-- 
Klaus Schliep
Université Paris 6 (Pierre et Marie Curie)
9, Quai Saint-Bernard, 75005 Paris

___
R-sig-phylo mailing list
R-sig-phylo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-phylo


Re: [R-sig-phylo] Collapsing nodes using node.labels

2011-09-28 Thread Emmanuel Paradis
My suggestion below should work with trees initially with zero-length branch if 
using a negative value instead of 0, e.g.:

tr$edge.length[j] - -1

Then di2multi(tr, tol = -0.5) 

Emmanuel
-Original Message-
From: Emmanuel Paradis emmanuel.para...@ird.fr
Sender: r-sig-phylo-boun...@r-project.org
Date: Wed, 28 Sep 2011 14:10:55 
To: Daniel Rafael Miranda-Esquiveldmira...@uis.edu.co; 
r-sig-phylo-boun...@r-project.org; r-sig-phylo@r-project.org
Reply-To: emmanuel.para...@ird.fr
Subject: Re: [R-sig-phylo] Collapsing nodes using node.labels

Hello Daniel,

Try this small manipulation ('tr' is your tree and 'node' stores the label of 
the node): 

i - which(tr$node.label == node)
j - which(tr$edge[, 2] == i + Ntip(tr))
tr$edge.length[j] - 0

Then di2multi(tr) will do the job. (Hopefully, there's originally no 
zero-length branch in tr.)

HTH

Emmanuel
-Original Message-
From: Daniel Rafael Miranda-Esquivel dmira...@uis.edu.co
Sender: r-sig-phylo-boun...@r-project.org
Date: Wed, 28 Sep 2011 00:21:43 
To: r-sig-phylo@r-project.org
Subject: [R-sig-phylo] Collapsing nodes using node.labels

 Hello all,


I am trying to collapse some nodes in a tree but using node.label and
not  edge.length, is there a way to convert  node.label to
edge.length? or a function to collapse a node but using node.label
directly?


Daniel

___
R-sig-phylo mailing list
R-sig-phylo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-phylo

___
R-sig-phylo mailing list
R-sig-phylo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-phylo
___
R-sig-phylo mailing list
R-sig-phylo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-phylo