Pages

Tuesday, August 4, 2015

Stochastic mapping: The order of the character data doesn't matter

Today a received the following query about the phytools function
make.simmap for stochastic charactr mapping:

I had a quick question about the make.simmap function in the phytools
package in R. Do the species names from the character trait vector need to
be in the same order as the tips from the phylogenetic tree we are using?
The order of the species in the character trait vector appears to influence
the output when I use the plotSimmap function. Is there a correct way?

The answer is - it certainly shouldn't matter - although it is wise to
check as this is, unfortunately, a relatively common bug afflicting
PCM functions in R for some reason (e.g.,
here).

What the user needs to keep in mind, though, is that because stochastic
character mapping uses simulations to sample states at nodes and changes
in state along edges, the outcome of any particular iteration of the
function will differ. This might cause us to (confusingly) suspect that the
order of the character vector matters, even though it does not.

## no colors provided. using the following legend:
## a b c
## "black" "red" "green3"

plotSimmap(tr2,direction="leftwards",lwd=3)

## no colors provided. using the following legend:
## a b c
## "black" "red" "green3"

Finally, there are very few circumstances in which we should be using
only one stochastic character maps. That is like just using one
sample from a Bayesian MCMC to summarize the posterior distribution. In
fact, what we will discover is that if we generate enough samples from
the posterior, it doesn't matter what random number seed we start with.
The results, integrating over our sample of trees, will be the same.

About this blog

This web-log chronicles the development of new tools for phylogenetic analyses in the phytools R package. Unless you a reading a very recent page of the blog, I recommend that you install the latest CRAN version of phytools (or latest beta release) before attempting to replicate any of the analyses of this site. That is because the linked functions may be archived, and very likely have been replaced by newer versions.