|Primary Contact(s)||Created||Required Software|
|Rich Glor||9 March 2009||R|
|See Introduction||R for Phylogenetics parts I, II, III, and IV|
One of the simplest things one can do with a phylogeny and character data is to reconstruct the history of character evolution by inferring ancestral character states. We can use the ace function of ape to reconstruct ancestral character states using maximum likelihood:
Error may appear saying "the tree is unrooted and not bifurcating", use:
multi2di(anolisComparativeTree) -> anolisComparativeTree
to fix it
ace(micro, anolisComparativeTree, type="discrete") -> anolisMicro
If this function successfully runs to completion, we should be able to investigate the stored output by typing anolisMicro (see below). This object contains several important elements, including the overall likelihood score ($loglik), the inferred rate of evolution ($rates), the standard error ($se), a matrix indicating the probabilities of change among all possible states ($index.matrix), and large matrix comprised of the marginal likelihood of each character state at each node ($lik.anc).
Ancestral Character Estimation Call: ace(x = micro, phy = anolisComparativeTree, type = "discrete") Log-likelihood: -77.51006 Rate index matrix: 0 1 2 3 4 5 0 . 1 1 1 1 1 1 1 . 1 1 1 1 2 1 1 . 1 1 1 3 1 1 1 . 1 1 4 1 1 1 1 . 1 5 1 1 1 1 1 . Parameter estimates: rate index estimate std-err 1 0.0013 2e-04 Scaled likelihoods at the root (type '...$lik.anc' to get them for all nodes): 0 1 2 3 4 0.297521568 0.448486652 0.005334867 0.033448885 0.017595000 5 0.197613027
We can view the final element of this object graphically by plotting the marginal likelihoods of each state at each node using pie diagrams:
plot(anolisComparativeTree, show.node.label=FALSE, label.offset=3, cex=0.4) points(rep(105, length(anolisComparativeTree$tip.label)), 1:length(anolisComparativeTree$tip.label), pch=22, bg=microLabel[anolisComparativeTree$tip.label], cex=0.5, lwd=0.25) nodelabels(pie=anolisMicro$lik.anc, cex=0.5)
NOTE: An important warning is necessary here. Although it has improved dramatically since first introduced, the ace function sometimes fails to properly reconstruct ancestral character states. This is certainly true when you observe negative marginal likelihood values in the lik.anc portion of your ace output. Some other error messages may be ignored, but negative marginal likelihoods should not be ignored.