For a variety of a reasons, I've been thinking about clever ways to try and visualize uncertainty in ancestral state estimates. Here is one attempt using an adaptation of the phytools function phenogram. This function plots a projection of the tree into a two dimensional space defined by time since the root (on the x) and phenotype. Note that to run this I had to first add the optional argument add to phenogram, so you will need to download and load the source (phenogram.R) to get this to work.
library(phytools)
# load source
source("phenogram.R")
# simulate tree & data
tree<-pbtree(n=20)
plotTree(tree)
# load source
source("phenogram.R")
# simulate tree & data
tree<-pbtree(n=20)
plotTree(tree)
x<-fastBM(tree)
# estimate ancestors
A<-fastAnc(tree,x,CI=TRUE)
tree<-paintSubTree(tree,node=length(tree$tip)+1,"1")
# our transparencies
trans<-as.character(floor(0:50/2))
trans[as.numeric(trans)<10]<-
paste("0", trans[as.numeric(trans)<10],sep="")
# plot
for(i in 0:50){
p<-i/length(trans)
phenogram(tree,c(x,(1-p)*A$CI95[,1]+p*A$ace), colors=setNames(paste("#0000ff",trans[i+1],sep=""),1), add=i>0)
phenogram(tree,c(x,(1-p)*A$CI95[,2]+p*A$ace), colors=setNames(paste("#0000ff",trans[i+1],sep=""),1), add=TRUE)
}
phenogram(tree,c(x,A$ace),add=TRUE, colors=setNames("white",1))
One word of caution about this visualization. Since I plot uncertainty using transparent colors, it can be difficult to impossible to extract uncertainty about any specific ancestral node from this plot. However what the plot is good at showing is the probability density of all hypothetical ancestors at any time slice through the tree.
# estimate ancestors
A<-fastAnc(tree,x,CI=TRUE)
tree<-paintSubTree(tree,node=length(tree$tip)+1,"1")
# our transparencies
trans<-as.character(floor(0:50/2))
trans[as.numeric(trans)<10]<-
paste("0", trans[as.numeric(trans)<10],sep="")
# plot
for(i in 0:50){
p<-i/length(trans)
phenogram(tree,c(x,(1-p)*A$CI95[,1]+p*A$ace), colors=setNames(paste("#0000ff",trans[i+1],sep=""),1), add=i>0)
phenogram(tree,c(x,(1-p)*A$CI95[,2]+p*A$ace), colors=setNames(paste("#0000ff",trans[i+1],sep=""),1), add=TRUE)
}
phenogram(tree,c(x,A$ace),add=TRUE, colors=setNames("white",1))