knitr::opts_chunk$set(echo = TRUE)

Partially matching trait data and tree(s)

The as.treedata.table function enables users to match a tree (or multiple trees) against a single trait database. We first load the sample dataset.

library(ape)
library(treedata.table)

# Load example data
data(anolis)
#Create treedata.table object with as.treedata.table
td <- as.treedata.table(tree = anolis$phy, data = anolis$dat)

Tips that are not common between the tree (or trees) and dataset are dropped from the resulting treedata.table object. For instance, below I have modified the original anole phylogeny such that A. ahli (ahli) is replaced for a label that is not present in the dataset (NAA).

anolis_newtip<-anolis$phy
anolis_newtip$tip.label[1]<-'NAA'
anolis_newtip

We then use this modified tree to fit a treedata.table object using the as.treedata.table function:

td <- as.treedata.table(tree=anolis_newtip, data=anolis$dat)

Note that as.treedata.table drops all non-overlapping tips (NAA [present in the tree but not in the trait data] and ahi [present in the database but not in tree] in this case) and returns a treedata.table object with fully matching phy and data objects.

td

Fully-matching matrix and trees are also returned in treedata.table objects with multiPhylo objects in their phy component. See the example below.

We first construct a multiPhylo object that partially overlaps the original trait database by using NAA instead of ahi.

anolis2<-anolis$phy
anolis2$tip.label[1]<-'NAA'
anolis1<-anolis$phy
anolis1$tip.label[1]<-'NAA'
trees<-list(anolis1,anolis2)
class(trees) <- "multiPhylo"
trees

Next, we fit the treedata.table object using the relevant multiPhylo object and the original trait database.

td <- as.treedata.table(tree=trees, data=anolis$dat)

Note that 1 tip was dropped for all trees in the multiPhylo object and a single row was deleted from the data.table object in the treedata.table object.

td


ropensci/treedata.table documentation built on Sept. 12, 2021, 6:23 p.m.