Hello Tristan, Does the code below work for your purpose? I don't know of a function off the top of my head that does this in a current package on CRAN (and although I might have missed such, I try to keep myself aware of time-scaling functions in R, given my interests). However, its not too difficult of an issue to come up with a solution for.
Cheers, -Dave PS: I appear to have done this with 16 minutes of getting your email... ################################################################### library(ape) nodeDates2branchLengths<-function(nodeDates, tree, allTipsModern){ if(!allTipsModern){ stop("nodeDates2branchLengths doesn't handle non-ultrametric trees or trees where not all tips are at the modern day... yet")} if(length(nodeDates)!=Nnode(tree)){ stop("nodeDates must be same length as number of nodes on input tree")} if(!is.null(tree$edge.lengths)){ message("Warning: input tree has $edge.lengths present, these will be replaced")} #add zero ages for tips allAges<-c(rep(0,Ntip(tree)),nodeDates) # get mother node age for each edge momAges<-allAges[tree$edge[,1]] # get node ages for child nodes of each edge childAges<-allAges[tree$edge[,2]] #edge lengths = mom - child edgeLengths<-momAges-childAges tree$edge.length<-edgeLengths return(tree) } chrono<-rcoal(10) tr <- chrono tr$edge.length <- NULL bt <- branching.times(chrono) chrono2 <- nodeDates2branchLengths(bt, tr, allTipsModern=TRUE) layout(1:2) plot(chrono);axisPhylo() plot(chrono);axisPhylo() On Wed, Oct 28, 2015 at 8:31 AM, Tristan Lefebure <tristan.lefeb...@gmail.com> wrote: > Greetings all, > > Does anyone know a way to transform branching times into branch length of a > chronogram. Like the inverse function of ape::branching.time() ? > > say you have a chronogram named chrono: > > tr <- chrono > tr$edge.length <- NULL > bt <- branching.times(chrono) > chrono2 <- magical.function.here(bt, tr) > > here I want : > > all(chrono2$edge.length == chrono$edge.length) > > This would be helpful in situations such as parsing the mcmctree output > (mcmc.txt) that are made of sampled branching times by the MCMC (a big > table with row=iteration and col=node age) and then, say, run the same > diversification analysis on the MCMC trees to get some credibility > intervals on the diversification parameters. > > Thanks ! > > -- > Tristan > > [[alternative HTML version deleted]] > > _______________________________________________ > R-sig-phylo mailing list - R-sig-phylo@r-project.org > https://stat.ethz.ch/mailman/listinfo/r-sig-phylo > Searchable archive at http://www.mail-archive.com/r-sig-phylo@r-project.org/ -- David W. Bapst, PhD Adjunct Asst. Professor, Geology and Geol. Eng. South Dakota School of Mines and Technology 501 E. St. Joseph Rapid City, SD 57701 http://webpages.sdsmt.edu/~dbapst/ http://cran.r-project.org/web/packages/paleotree/index.html _______________________________________________ R-sig-phylo mailing list - R-sig-phylo@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-phylo Searchable archive at http://www.mail-archive.com/r-sig-phylo@r-project.org/