Dear Mario.

 From your drawing it looks like each node & tip has a value, and then 
you update these values by reassigning each node a value equal to the 
sum of its value and that of all its descendants. Is this correct?

If so, then assuming you have ordered your quantities in x such that 
they are in the order of their node indices in the "phylo" tree object, 
you should be able to just compute:

library(phytools)
desc<-sapply(1:(Ntip(tree)+tree$Nnode),function(n,tree)
        if(n<=Ntip(tree)) n else c(n,getDescendants(tree,n)),
        tree=tree)
y<-sapply(desc,function(n,x) sum(x[n]),x=x)

Does that help?

Here is a complete example using a small random tree & randomly chosen 
integer values for the tips & nodes. In the illustrative plot, the 
values being summed are shown in round parentheses, while the sums are 
given in square brackets:

library(phytools)

## random tree
tree<-rtree(n=6,tip.label=LETTERS[1:6],br=NULL)

## random starting values at nodes
x<-setNames(sample(0:5,Ntip(tree)+tree$Nnode,replace=TRUE),
        c(tree$tip.label,1:tree$Nnode+Ntip(tree)))
x

x<-x[c(tree$tip.label,1:tree$Nnode+Ntip(tree))]

plotTree(tree,type="cladogram",nodes="centered")

tiplabels(paste("(",x[1:Ntip(tree)],")",sep=""),
        tip=1:Ntip(tree),frame="none",adj=c(-1,-1))

nodelabels(paste("(",x[1:tree$Nnode+Ntip(tree)],")",sep=""),
        node=1:tree$Nnode+Ntip(tree),frame="none",
        adj=c(0.5,-1))

desc<-sapply(1:(Ntip(tree)+tree$Nnode),function(n,tree)
        if(n<=Ntip(tree)) n else c(n,getDescendants(tree,n)),
        tree=tree)

y<-sapply(desc,function(n,x) sum(x[n]),x=x)

tiplabels(paste("[",y[1:Ntip(tree)],"]",sep=""),
        tip=1:Ntip(tree),frame="none",adj=c(-1,1))

nodelabels(paste("[",y[1:tree$Nnode+Ntip(tree)],"]",sep=""),
        node=1:tree$Nnode+Ntip(tree),frame="none",
        adj=c(0.5,1.5))

All the best, Liam

Liam J. Revell
Associate Professor, University of Massachusetts Boston
Profesor Asistente, Universidad Católica de la Ssma Concepción
web: http://faculty.umb.edu/liam.revell/, http://www.phytools.org

Academic Director UMass Boston Chile Abroad (starting 2019):
https://www.umb.edu/academics/caps/international/biology_chile

On 8/3/2019 9:32 PM, Mario Schädel wrote:
> Dear people on this list,
> 
> I am a German PhD student in the field of arthropod palaeontology. I 
> want to develop a new approach for comparing abundance data in a 
> phylogenetic context. Unlike following the standard techniques of 
> community ecology, I want to include the abundance data not only for the 
> tips of a tree but also for its nodes. The background for this is, that 
> in palaeontology it is often not possible to identify specimens to 
> species level and also some fossils are better preserved as others, 
> hence the level of identification within samples can vary a lot.
> 
> So, I want to link a vector, or at best a data frame, that holds 
> abundance data for tips and nodes, to a tree (even this proved to be 
> problematic as all functions that I found make distinctions between tip 
> and node data). In the next step, I would like to recursively sum-up the 
> abundances along the tree, from the leaves to the root. When the data is 
> properly linked, this should not be too complicated, once the tree is 
> reordered into the “postorder” format. Afterwards, the computed data 
> should be converted in a format, that can be included into plots. 
> Alternatively, I also came up with the idea, that the abundance data 
> could be visualised by the branch lengths of the tree.
> 
> I would be more than grateful, if someone could offer me some help with 
> this project. I have been wrecking my head around this since months now.
> 
> I attached a graphical representation of my idea in case my explanations 
> are a bit confusing (orange color, abundances before computation; green, 
> summed up aundances).
> 
> 
> Best wishes to all of you!
> 
> Mario
> 
> 
> 
> _______________________________________________
> R-sig-phylo mailing list - R-sig-phylo@r-project.org
> https://nam01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-sig-phylo&amp;data=02%7C01%7Cliam.revell%40umb.edu%7Cf182d74c49814d14ea4d08d7187ba78d%7Cb97188711ee94425953c1ace1373eb38%7C0%7C0%7C637004791700218025&amp;sdata=XKgwyKOdMhOPkJ9mcC5%2FTHsvoI3JrdFqQ1fVcVCavFM%3D&amp;reserved=0
> Searchable archive at 
> https://nam01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.mail-archive.com%2Fr-sig-phylo%40r-project.org%2F&amp;data=02%7C01%7Cliam.revell%40umb.edu%7Cf182d74c49814d14ea4d08d7187ba78d%7Cb97188711ee94425953c1ace1373eb38%7C0%7C0%7C637004791700218025&amp;sdata=ykNTk0VNMFGgOEGRk6w2vTJHVaXIJjNSQ9dxUxGEejc%3D&amp;reserved=0
> 
_______________________________________________
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/

Reply via email to