Hi Andres.

To answer your question at its face value, the line of code you want is:

anc<-setNames(apply(ANC$lik.anc,1,function(x)
  names(which.max(x))),length(tree$tip.label)+1:tree$Nnode)

(The setNames ensures that your resultant vector gets the node numbers for names.)

This message really deserves a more lengthy response for two reasons:

1) The scaled likelihoods returned by ace(...,type="discrete") are actually conditional likelihoods of the subtree obtained via the pruning algorithm of Felsenstein. These should generally not be used for ancestral state estimation (we should use the marginal or joint reconstructions instead).

2) Extracting only the most likely state as *the* ancestral state at the node ignores the uncertainty of our estimate. Really we have a probability distribution for the states at each node.

- Liam

Liam J. Revell, Assistant Professor of Biology
University of Massachusetts Boston
web: http://faculty.umb.edu/liam.revell/
email: liam.rev...@umb.edu
blog: http://blog.phytools.org

On 3/20/2013 2:23 PM, Andrés Parada wrote:
Sorry if this was addressed before.

I reconstructed a binary discrete character with* ace* (coded as 0-1).
As suggested in APER 2nd edition with the* Sylvia *case I can obtain the
"lik.anc" values but I wanted to derive the ancestral states from this
matrix.

*First*

*ANC <- ace (data$character, tree, type="d", method="ML", model="ARD")*

ANC$lik.anc look like this:

                  0            1
   [1,] 9.999185e-01 8.147752e-05

*So I applied the same strategy as in the example mentioned above:*

*anc <- apply(ANC$lik.anc, 1, which.max)*


This returned a matrix of with values of 1 or 2.

Is there a way to modify the formula and sort this so it returns only 0 or
1 depending on which state has higher probability?

Thank you very much for your help.

        [[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/


_______________________________________________
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