mcmc2anc | R Documentation |
Obtain the ancestral reconstruction of characters from an MCMC sample using Felsenstein (1973) model of continuous character evolution.
mcmc2anc(tree, M, mcmc, time.name, rate.name, tip.ages = NULL)
tree |
a rooted, strictly bifurcating phylogeny |
M |
s x k matrix of k continuous morphological measurements for s species |
mcmc |
data frame with MCMC output from MCMCtree |
time.name |
character vector of length one |
rate.name |
character vector of length one |
tip.ages |
numeric, the ages of the terminal taxa in the tree |
The function first calculates the mean of divergence times and morphological rates in the MCMC sample. These are used to reconstruct the branch lengths in units of morphological evolution, and then Eq. (7) in Felsenstein (1973) is used to calculate the ancestral reconstruction on the tree.
Note time.name
is the name format used for the node ages in the MCMC
dataframe, usually of the form time.name = "t_"
. Similarly
rate.name
is the name format used in the MCMC sample for the rates, of
the form rate.name = "r_g1_"
where the subscript in "g" must be the
partition number containing the morphological rates. Note tree
must be
the same used by MCMCtree when generating the MCMC sample, right down to its
Newick representation. Taxon names in tree
and M
must match.
A n x k matrix with the ancestral reconstruction for the k characters at the n internal nodes of the phylogeny.
Mario dos Reis
Felsenstein J (1973) Maximum-likelihood estimation of evolutionary trees from continuous characters. Am J Hum Genet, 25: 471–492.
write.morpho
data(carnivores)
# calculate tip ages correctly, as they're needed by the function:
tips_info <- strsplit(carnivores$tree$tip.label, "\\^" )
back.ages <- as.numeric(unlist(tips_info)[seq(from=2, to=2*19, by=2)])
back.ages <- max(back.ages) - back.ages
C <- carnivores$C.proc
rownames(C) <- rownames(carnivores$M)
recM = mcmc2anc(carnivores$tree, C, mcmc=carnivores$mcmc, time.name="t_",
rate.name="r_g1_", tip.ages=back.ages)
x <- seq(1, 87, by=3); y <- seq(2, 87, by=3)
# Plot landmarks for the 19 carnivores:
plot(carnivores$C.proc[,x], carnivores$C.proc[,y], pch='+', cex=.5)
# plot ancestral reconstruction at the root (node 20):
points(recM["20",x], recM["20",y], pch=19, col="red")
# mean shape
mS <- apply(carnivores$C.proc, 2, mean)
points(mS[x], mS[y], pch=19, col="blue")
# Convert reconstruction to an array, as is the standard in
# morphometrics software
## Not run:
recA <- matrix2array(recM, 3)
options(rgl.printRglwidget = TRUE)
rgl::plot3d(recA[,,"20"], ty='s', size=2, col="red", aspect=FALSE)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.