Skip to content

Phylogenies and distance matrices with the multitable package

July 11, 2012

Oliver Purschke writes:

i just started to play around with the multitable package and i think it would really extent my toolbox if “data.lists” could handle phylogenies. i guess one could include a phylogenetic distance matrix but then distances need to be recalculated if one adds or deletes species from the community data set.
any hints are welcome.

My reply:

It would really extend my toolbox too if data lists could handle phylogenies! Its one of the things that’s on my ‘to do list’…What I do now is to use eigenvectors of the phylogenetic distance matrix as variables representing the phylogeny, but you are absolutely correct that the problem here is that these eigenvectors (and your distance matrices) would have to be recalculated if species lists are changed.

Here is some code I wrote to handle phylogenetic distance matrices in multitable (but it is far from slick as Oliver points out below):


# fake data that comes with multitable

# make a tree for the fake species
tree <- rcoal(3)
tree$tip.label <- dimnames([[3]]

# compute the distances
phylodist <- cophenetic(tree)

# convert the columns into variables and rows into replicates --
# in other words, matrices have two dimensions of replication (rows and columns)
# whereas data frames have only one (the rows) because columns represent variables
phylodist <-

# another way to look at this last step is that if we didn't convert to a
# data frame we'd get an error: + variable(cophenetic(tree), c('species','species'))

# make more informative variable names
colnames(phylodist) <- paste(colnames(phylodist), 'phylo.dist', sep = '.')

# add the distance information to the data list
dl <- + variableGroup(, dimids = 'species')

Oliver writes back:

your approach only seems to work for cases where the tip.labels are in the same order as the species names in the community data.frame, which requires additional reordering of the species and the trait data.

He’s right again! But I think its a good starting point.

Conclusion: I need some kind of better ‘workaround’ for this stuff.

No comments yet

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: