Re: [R-sig-phylo] LTT plot non-ultrametric trees

2011-08-11 Thread Nick Matzke
Somewhere I wrote a function that samples at a series of 
user-set timepoints and counts the # of lineages crossing 
each timepoint -- this is pretty flexible, allows for 
increases/decreases in diversity etc., let me know if the 
other options aren't working for you  I can dig it up...



On 8/10/11 9:57 PM, Emmanuel Paradis wrote:

Hi Liam  Rob,

You may try using dist.nodes() for this:

x - dist.nodes(phy)
n - Ntip(phy)
ROOT - n + 1
x[ROOT, ]

The last command returns the distance from the root to all
nodes and tips which are ordered in the usual way. So you
may create a vector with +1 for the nodes, -1 for the tips,
and drop the tips not extinct. Then you sort on the values
of x, and plot cumsum() of the vector of +/-1 against them.

I can add this to ape if there's a general interest for it.

Best,

Emmanuel

Liam J. Revell wrote on 11/08/2011 11:05:

Hi Rob.

I can reproduce your error, but I haven't figured out the
problem yet.

You can try an earlier version of this function, which
seems to work:

source(http://anolis.oeb.harvard.edu/~liam/R-phylogenetics/ltt/v0.3/ltt.R;)

p2 - ltt(t1, log.lineages=FALSE, drop.extinct=FALSE)

Sorry about this.

Also:

max(p1$times)==max(p2$times)

can be FALSE because if drop.extinct is set to TRUE, then
the crown age of the pruned tree can be smaller than in
the full tree if some lineages arising at the root of the
tree do not leave any extant descendants.

- Liam





--

Nicholas J. Matzke
Ph.D. Candidate, Graduate Student Researcher

Huelsenbeck Lab
Center for Theoretical Evolutionary Genomics
4151 VLSB (Valley Life Sciences Building)
Department of Integrative Biology
University of California, Berkeley

Graduate Student Instructor, IB200B
Principles of Phylogenetics: Ecology and Evolution
http://ib.berkeley.edu/courses/ib200b/
http://phylo.wikidot.com/


Lab websites:
http://ib.berkeley.edu/people/lab_detail.php?lab=54
http://fisher.berkeley.edu/cteg/hlab.html
Dept. personal page: 
http://ib.berkeley.edu/people/students/person_detail.php?person=370
Lab personal page: 
http://fisher.berkeley.edu/cteg/members/matzke.html

Lab phone: 510-643-6299
Dept. fax: 510-643-6264

Cell phone: 510-301-0179
Email: mat...@berkeley.edu

Mailing address:
Department of Integrative Biology
3060 VLSB #3140
Berkeley, CA 94720-3140

-
[W]hen people thought the earth was flat, they were wrong. 
When people thought the earth was spherical, they were 
wrong. But if you think that thinking the earth is spherical 
is just as wrong as thinking the earth is flat, then your 
view is wronger than both of them put together.


Isaac Asimov (1989). The Relativity of Wrong. The 
Skeptical Inquirer, 14(1), 35-44. Fall 1989.

http://chem.tufts.edu/AnswersInScience/RelativityofWrong.htm

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


Re: [R-sig-phylo] LTT plot non-ultrametric trees

2011-08-11 Thread Liam J. Revell

Hi Rob.

Thanks for identifying the bug.  This should be fixed, I hope, in the 
newest version of phytools (v0.0-6; available: 
http://anolis.oeb.harvard.edu/~liam/R-phylogenetics/).


The way this function works is by first computing the heights above the 
root of all the nodes (including tip nodes) in the tree, and then at 
each event (that is, a speciation or extinction), it counts the number 
of edges that include that time point.  This is slow.  It seems likely 
that Emmanuel's suggestion (in a previous email) to use dist.nodes() 
would run much faster than this.


- Liam

--
Liam J. Revell
University of Massachusetts Boston
web: http://faculty.umb.edu/liam.revell/
email: liam.rev...@umb.edu
blog: http://phytools.blogspot.com

On 8/11/2011 12:42 AM, Rob Lanfear wrote:

Hi Liam,

Thanks for the help. Extremely useful.

And thanks for clearing up my lack of understanding about the
differences in maximum ages!

Cheers,

Rob

On 11 August 2011 14:05, Liam J. Revell liam.rev...@umb.edu
mailto:liam.rev...@umb.edu wrote:

Hi Rob.

I can reproduce your error, but I haven't figured out the problem yet.

You can try an earlier version of this function, which seems to work:


source(http://anolis.oeb.__harvard.edu/~liam/R-__phylogenetics/ltt/v0.3/ltt.R
http://anolis.oeb.harvard.edu/~liam/R-phylogenetics/ltt/v0.3/ltt.R)

p2 - ltt(t1, log.lineages=FALSE, drop.extinct=FALSE)

Sorry about this.

Also:


max(p1$times)==max(p2$times)

can be FALSE because if drop.extinct is set to TRUE, then the crown
age of the pruned tree can be smaller than in the full tree if some
lineages arising at the root of the tree do not leave any extant
descendants.


- Liam

--
Liam J. Revell
University of Massachusetts Boston
web: http://faculty.umb.edu/liam.__revell/
http://faculty.umb.edu/liam.revell/
email: liam.rev...@umb.edu mailto:liam.rev...@umb.edu
blog: http://phytools.blogspot.com

On 8/10/2011 9:50 PM, Rob Lanfear wrote:

library(TreeSim)

library(phytools)

library(geiger)


#simulate tree of 100 taxa with initial diversification followed
by a
period of B=D

t1 - sim.rateshift.taxa(100, 1, c(0.2, 0.2), c(0.2, 0.05),
c(1,1), c(0,
20))[[1]]

t1


#confirm number of extant taxa is 100

n.extant- length(prune.extinct.taxa(t1)$__tip.label)

n.extant


#do ltt plot without extinct taxa (works fine)

p1- ltt(t1, log.lineages=FALSE, drop.extinct=TRUE)


#do ltt plot with extinct taxa (looks odd)

p2- ltt(t1, log.lineages=FALSE, drop.extinct=FALSE)


#max times don't seem to correspond between the two plots.

max(p1$times)==max(p2$times)





--
Rob Lanfear
Postdoc,
Centre for Macroevolution and Macroecology,
Research School of Biology,
Australian National University

Tel: +61 2 6125 7270
www.robertlanfear.com http://www.robertlanfear.com


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


Re: [R-sig-phylo] LTT plot non-ultrametric trees

2011-08-11 Thread Rob Lanfear
Hi Liam, Emmanuel, Nick, et al

Thanks for all the help.

Liam, I can confirm that your new function works fine on all the trees I've
tested (about 20). Thanks!

Some of my trees are pretty large (a few thousand taxa), so for interest's
sake I coded up Emmanuel's suggestion too.

The code is below (liberally borrowed from suggestion on this list, and from
Liam's code). For reasons I don't entirely understand, my code gives my an
ltt vector which is 2 shorter than Liam's. Part of the difference is that I
start with 2 taxa at the root node, so I count one less event than Liam at
the start of the vector. But I'm not sure where the other difference lies -
I've probably made a mistake somewhere.

Any clues gratefully received.

Rob

   lttplot- function(phy, plot=TRUE, log.lineages=FALSE){

tol-1e-6

x - dist.nodes(phy)

n - Ntip(phy)

ROOT - n+1

 #distances from root to all nodes and tips

events - x[ROOT,]

 #tips are extinctions (we remove the extant tips later)

names(events)[1:n] - -1

 #nodes are speciations

names(events)[-(1:n)] - +1

 #but extant tips don't count

present - max(events)

events - events[-which(eventspresent-tol)]

 #sort w.r.t. time

events - sort(events)


 #the LTT plot is the cumsum of the names

ltt - cumsum(names(events))

 #add 1 to LTT, because the root node actually represents the creation of 2
taxa

#and we don't know the timing of the creation of the first taxon (root
branch)

ltt - ltt+1


 if(plot==TRUE){

 if(log.lineages==TRUE)

 plot(events,log(ltt),s,xlab=time,ylab=log(lineages))

 else

 plot(events,ltt,s,xlab=time,ylab=lineages)

}

return(list(ltt=ltt, times=events))

}

On 12 August 2011 07:44, Liam J. Revell liam.rev...@umb.edu wrote:

 Hi Rob.

 Thanks for identifying the bug.  This should be fixed, I hope, in the
 newest version of phytools (v0.0-6; available:
 http://anolis.oeb.harvard.edu/**~liam/R-phylogenetics/http://anolis.oeb.harvard.edu/~liam/R-phylogenetics/
 ).

 The way this function works is by first computing the heights above the
 root of all the nodes (including tip nodes) in the tree, and then at each
 event (that is, a speciation or extinction), it counts the number of edges
 that include that time point.  This is slow.  It seems likely that
 Emmanuel's suggestion (in a previous email) to use dist.nodes() would run
 much faster than this.


 - Liam

 --
 Liam J. Revell
 University of Massachusetts Boston
 web: 
 http://faculty.umb.edu/liam.**revell/http://faculty.umb.edu/liam.revell/
 email: liam.rev...@umb.edu
 blog: http://phytools.blogspot.com

 On 8/11/2011 12:42 AM, Rob Lanfear wrote:

 Hi Liam,

 Thanks for the help. Extremely useful.

 And thanks for clearing up my lack of understanding about the
 differences in maximum ages!

 Cheers,

 Rob

 On 11 August 2011 14:05, Liam J. Revell liam.rev...@umb.edu
 mailto:liam.rev...@umb.edu wrote:

Hi Rob.

I can reproduce your error, but I haven't figured out the problem yet.

You can try an earlier version of this function, which seems to work:

source(http://anolis.oeb.__ha**rvard.edu/~liam/R-__**
 phylogenetics/ltt/v0.3/ltt.Rhttp://harvard.edu/~liam/R-__phylogenetics/ltt/v0.3/ltt.R
http://anolis.oeb.harvard.**edu/~liam/R-phylogenetics/ltt/**
 v0.3/ltt.Rhttp://anolis.oeb.harvard.edu/~liam/R-phylogenetics/ltt/v0.3/ltt.R
 )

p2 - ltt(t1, log.lineages=FALSE, drop.extinct=FALSE)

Sorry about this.

Also:


max(p1$times)==max(p2$times)

can be FALSE because if drop.extinct is set to TRUE, then the crown
age of the pruned tree can be smaller than in the full tree if some
lineages arising at the root of the tree do not leave any extant
descendants.


- Liam

--
Liam J. Revell
University of Massachusetts Boston
web: 
 http://faculty.umb.edu/liam.__**revell/http://faculty.umb.edu/liam.__revell/

 http://faculty.umb.edu/liam.**revell/http://faculty.umb.edu/liam.revell/
 
email: liam.rev...@umb.edu mailto:liam.rev...@umb.edu

blog: http://phytools.blogspot.com

On 8/10/2011 9:50 PM, Rob Lanfear wrote:

library(TreeSim)

library(phytools)

library(geiger)


#simulate tree of 100 taxa with initial diversification followed
by a
period of B=D

t1 - sim.rateshift.taxa(100, 1, c(0.2, 0.2), c(0.2, 0.05),
c(1,1), c(0,
20))[[1]]

t1


#confirm number of extant taxa is 100

n.extant- length(prune.extinct.taxa(t1)$**__tip.label)

n.extant


#do ltt plot without extinct taxa (works fine)

p1- ltt(t1, log.lineages=FALSE, drop.extinct=TRUE)


#do ltt plot with extinct taxa (looks odd)

p2- ltt(t1, log.lineages=FALSE, drop.extinct=FALSE)


#max times don't seem to correspond between the two plots.

max(p1$times)==max(p2$times)





 --
 Rob Lanfear
 Postdoc,
 Centre for Macroevolution and Macroecology,
 Research School of Biology,
 Australian National University

 Tel: +61 2 6125 7270
 

Re: [R-sig-phylo] LTT plot non-ultrametric trees

2011-08-11 Thread Emmanuel Paradis

Hi all,

I'll make a new version of ltt.plot() that treats ultrametric and 
non-ultrametric trees. After all, I don't see a logical reason why both 
kinds of trees would be treated differently here. I'll add an option 
backward (FALSE by default) so the time scale can start from the root, 
and one tol as you did below. This will handle the root edge if present, 
and also return the data invisibly. Any other suggestion?


Best,

Emmanuel

Rob Lanfear wrote on 12/08/2011 06:52:

Hi Liam, Emmanuel, Nick, et al

Thanks for all the help.

Liam, I can confirm that your new function works fine on all the trees I've
tested (about 20). Thanks!

Some of my trees are pretty large (a few thousand taxa), so for interest's
sake I coded up Emmanuel's suggestion too.

The code is below (liberally borrowed from suggestion on this list, and from
Liam's code). For reasons I don't entirely understand, my code gives my an
ltt vector which is 2 shorter than Liam's. Part of the difference is that I
start with 2 taxa at the root node, so I count one less event than Liam at
the start of the vector. But I'm not sure where the other difference lies -
I've probably made a mistake somewhere.

Any clues gratefully received.

Rob

   lttplot- function(phy, plot=TRUE, log.lineages=FALSE){

tol-1e-6

x - dist.nodes(phy)

n - Ntip(phy)

ROOT - n+1

 #distances from root to all nodes and tips

events - x[ROOT,]

 #tips are extinctions (we remove the extant tips later)

names(events)[1:n] - -1

 #nodes are speciations

names(events)[-(1:n)] - +1

 #but extant tips don't count

present - max(events)

events - events[-which(eventspresent-tol)]

 #sort w.r.t. time

events - sort(events)


 #the LTT plot is the cumsum of the names

ltt - cumsum(names(events))

 #add 1 to LTT, because the root node actually represents the creation of 2
taxa

#and we don't know the timing of the creation of the first taxon (root
branch)

ltt - ltt+1


 if(plot==TRUE){

 if(log.lineages==TRUE)

 plot(events,log(ltt),s,xlab=time,ylab=log(lineages))

 else

 plot(events,ltt,s,xlab=time,ylab=lineages)

}

return(list(ltt=ltt, times=events))

}

On 12 August 2011 07:44, Liam J. Revell liam.rev...@umb.edu wrote:


Hi Rob.

Thanks for identifying the bug.  This should be fixed, I hope, in the
newest version of phytools (v0.0-6; available:
http://anolis.oeb.harvard.edu/**~liam/R-phylogenetics/http://anolis.oeb.harvard.edu/~liam/R-phylogenetics/
).

The way this function works is by first computing the heights above the
root of all the nodes (including tip nodes) in the tree, and then at each
event (that is, a speciation or extinction), it counts the number of edges
that include that time point.  This is slow.  It seems likely that
Emmanuel's suggestion (in a previous email) to use dist.nodes() would run
much faster than this.


- Liam

--
Liam J. Revell
University of Massachusetts Boston
web: http://faculty.umb.edu/liam.**revell/http://faculty.umb.edu/liam.revell/
email: liam.rev...@umb.edu
blog: http://phytools.blogspot.com

On 8/11/2011 12:42 AM, Rob Lanfear wrote:


Hi Liam,

Thanks for the help. Extremely useful.

And thanks for clearing up my lack of understanding about the
differences in maximum ages!

Cheers,

Rob

On 11 August 2011 14:05, Liam J. Revell liam.rev...@umb.edu
mailto:liam.rev...@umb.edu wrote:

   Hi Rob.

   I can reproduce your error, but I haven't figured out the problem yet.

   You can try an earlier version of this function, which seems to work:

   source(http://anolis.oeb.__ha**rvard.edu/~liam/R-__**
phylogenetics/ltt/v0.3/ltt.Rhttp://harvard.edu/~liam/R-__phylogenetics/ltt/v0.3/ltt.R
   http://anolis.oeb.harvard.**edu/~liam/R-phylogenetics/ltt/**
v0.3/ltt.Rhttp://anolis.oeb.harvard.edu/~liam/R-phylogenetics/ltt/v0.3/ltt.R

)

   p2 - ltt(t1, log.lineages=FALSE, drop.extinct=FALSE)

   Sorry about this.

   Also:


   max(p1$times)==max(p2$times)

   can be FALSE because if drop.extinct is set to TRUE, then the crown
   age of the pruned tree can be smaller than in the full tree if some
   lineages arising at the root of the tree do not leave any extant
   descendants.


   - Liam

   --
   Liam J. Revell
   University of Massachusetts Boston
   web: 
http://faculty.umb.edu/liam.__**revell/http://faculty.umb.edu/liam.__revell/
   http://faculty.umb.edu/liam.**revell/http://faculty.umb.edu/liam.revell/
   email: liam.rev...@umb.edu mailto:liam.rev...@umb.edu

   blog: http://phytools.blogspot.com

   On 8/10/2011 9:50 PM, Rob Lanfear wrote:

   library(TreeSim)

   library(phytools)

   library(geiger)


   #simulate tree of 100 taxa with initial diversification followed
   by a
   period of B=D

   t1 - sim.rateshift.taxa(100, 1, c(0.2, 0.2), c(0.2, 0.05),
   c(1,1), c(0,
   20))[[1]]

   t1


   #confirm number of extant taxa is 100

   n.extant- length(prune.extinct.taxa(t1)$**__tip.label)

   n.extant


   #do ltt plot without extinct taxa (works fine)

   p1- ltt(t1, 

Re: [R-sig-phylo] LTT plot non-ultrametric trees

2011-08-10 Thread Liam J. Revell
This is implemented in my phytools package.  This is not yet on CRAN, 
but can be downloaded from 
http://anolis.oeb.harvard.edu/~liam/R-phylogenetics/.  The function is 
ltt().  It is slow, but seems to work.  Please let me know if you have 
success with this.


- Liam

--
Liam J. Revell
University of Massachusetts Boston
web: http://faculty.umb.edu/liam.revell/
email: liam.rev...@umb.edu
blog: http://phytools.blogspot.com

On 8/10/2011 8:51 PM, Rob Lanfear wrote:

Hi All,

I have a set of simulated birth-death trees, which include extinct and
extant lineages. I'd like to see if my simulations are doing what I think
they should be, by plotting out the number of lineages through time.

Does anyone know of a method of doing this that incorporates extinct
lineages, i.e. one where the number of lineages can decrease as well as
increase through time.

I can see how it could be done (I think...) by making an ordered data frame
of node times (+1 lineage) and extinction events (-1 lineage), but it seems
like somebody might already have done it.

Cheers,

Rob



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


Re: [R-sig-phylo] LTT plot non-ultrametric trees

2011-08-10 Thread Emmanuel Paradis

Hi Liam  Rob,

You may try using dist.nodes() for this:

x - dist.nodes(phy)
n - Ntip(phy)
ROOT - n + 1
x[ROOT, ]

The last command returns the distance from the root to all nodes and 
tips which are ordered in the usual way. So you may create a vector with 
+1 for the nodes, -1 for the tips, and drop the tips not extinct. Then 
you sort on the values of x, and plot cumsum() of the vector of +/-1 
against them.


I can add this to ape if there's a general interest for it.

Best,

Emmanuel

Liam J. Revell wrote on 11/08/2011 11:05:

Hi Rob.

I can reproduce your error, but I haven't figured out the problem yet.

You can try an earlier version of this function, which seems to work:

source(http://anolis.oeb.harvard.edu/~liam/R-phylogenetics/ltt/v0.3/ltt.R;) 


p2 - ltt(t1, log.lineages=FALSE, drop.extinct=FALSE)

Sorry about this.

Also:

max(p1$times)==max(p2$times)

can be FALSE because if drop.extinct is set to TRUE, then the crown age 
of the pruned tree can be smaller than in the full tree if some lineages 
arising at the root of the tree do not leave any extant descendants.


- Liam



--
Emmanuel Paradis
IRD, Jakarta, Indonesia
http://ape.mpl.ird.fr/

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