Skip to contents

Getting Started With The treedata.table Package

The aim of the treedata.table R package is to allow researchers to access and manipulate phylogenetic data using tools from the data.table package. data.table has many functions for rapidly manipulating data in a memory efficient way.

Using the treedata.table package begins with creating a treedata.table object. The treedata.table matches the tip.labels of the phylogeny to a column of names in your data.frame. This allows you to manipulate the data, and the corresponding tree together.

Importantly, the character matrix must must include a column with the taxa names and should be of class data.frame. The tree must be of class phylo or multiPhylo.

A treedata.table is created using the as.treedata.table function. Here we use the Anolis dataset from treeplyr. Traits in this dataset were randomly generated for a set of 100 species.

##          Thank you for using the {treedata.table} R package!   
## 
##                         🙂Happy coding!!🙂
# Load example data
data(anolis)
#Create treedata.table object with as.treedata.table
td <- as.treedata.table(tree = anolis$phy, data = anolis$dat)
## Tip labels detected in column: X
## Phylo object detected
## All tips from original tree/dataset were preserved

We may inspect our object by calling it by name. You will notice that your data.frame is now a data.table. A data.table is simply an advanced version of a data.frame that, among other, increase speed in data manipulation steps while simplifying syntax.

td
## $phy 
## 
## Phylogenetic tree with 100 tips and 99 internal nodes.
## 
## Tip labels:
##   ahli, allogus, rubribarbus, imias, sagrei, bremeri, ...
## 
## Rooted; includes branch lengths.
## 
## $dat 
##      tip.label      SVL PCI_limbs PCII_head PCIII_padwidth_vs_tail
##         <char>    <num>     <num>     <num>                  <num>
## 1:        ahli 4.039125 -3.248286 0.3722519             -1.0422187
## 2:     allogus 4.040138 -2.845570 0.6001134             -1.0253056
## 3: rubribarbus 4.078469 -2.238349 1.1199779             -1.1929572
## 4:       imias 4.099687 -3.048917 2.3320349              0.1616442
## 5:      sagrei 4.067162 -1.741055 2.0228243              0.1693635
## 6:     bremeri 4.113371 -1.813611 2.6067501              0.6399320
##    PCIV_lamella_num awesomeness  hostility   attitude ecomorph island
##               <num>       <num>      <num>      <num>   <char> <char>
## 1:        -2.414742  -0.2416517 -0.1734769  0.6443771       TG   Cuba
## 2:        -2.463311   0.6244689 -0.5000962  0.7128910       TG   Cuba
## 3:        -2.087433  -0.4277574  0.4800445 -0.9674263       TG   Cuba
## 4:        -2.112606   0.1694260 -0.4108123  0.1963580       TG   Cuba
## 5:        -1.375769  -0.6304338  0.7193130 -1.2228276       TG   Cuba
## 6:        -1.626299  -1.7543006  1.4127184  0.1832345       TG   Cuba

Furthermore, the new data.table has been reordered into the same order as the tip.labels of your tree.

td$phy$tip.label == td$dat$tip.label
##   [1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
##  [16] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
##  [31] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
##  [46] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
##  [61] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
##  [76] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
##  [91] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE

Manipulating Data

Coindexing

Your data table can be indexed in the same way any other data.table object would be. For example, if we wanted to look at our snout-vent length column, we can do that like so.

td$dat[,'SVL']
##           SVL
##         <num>
##   1: 4.039125
##   2: 4.040138
##   3: 4.078469
##   4: 4.099687
##   5: 4.067162
##   6: 4.113371
##   7: 3.901619
##   8: 3.637962
##   9: 3.987147
##  10: 3.952605
##  11: 4.032806
##  12: 3.938442
##  13: 3.877457
##  14: 4.769473
##  15: 3.838376
##  16: 4.154274
##  17: 4.321524
##  18: 4.128612
##  19: 4.482607
##  20: 4.165605
##  21: 3.869881
##  22: 3.886500
##  23: 3.799022
##  24: 4.188105
##  25: 3.820378
##  26: 4.091535
##  27: 4.189820
##  28: 3.874155
##  29: 3.911743
##  30: 3.831810
##  31: 3.916546
##  32: 3.928796
##  33: 3.663932
##  34: 3.588941
##  35: 3.696631
##  36: 3.793899
##  37: 3.657991
##  38: 4.288780
##  39: 3.800471
##  40: 4.097479
##  41: 4.316542
##  42: 4.051111
##  43: 4.121684
##  44: 4.210982
##  45: 3.983003
##  46: 4.242103
##  47: 4.274271
##  48: 4.079485
##  49: 5.053056
##  50: 5.076958
##  51: 5.013963
##  52: 4.128504
##  53: 3.884652
##  54: 4.875012
##  55: 5.003946
##  56: 5.038034
##  57: 5.042349
##  58: 5.036953
##  59: 3.842994
##  60: 3.845670
##  61: 3.657088
##  62: 4.375390
##  63: 4.258991
##  64: 3.757869
##  65: 3.697941
##  66: 3.466860
##  67: 3.701240
##  68: 3.763884
##  69: 3.773967
##  70: 3.682924
##  71: 3.815705
##  72: 3.788595
##  73: 3.802961
##  74: 3.554891
##  75: 3.537439
##  76: 3.758726
##  77: 3.462014
##  78: 3.630161
##  79: 3.526655
##  80: 3.715765
##  81: 3.626206
##  82: 3.971307
##  83: 4.198915
##  84: 4.280547
##  85: 4.802849
##  86: 5.042780
##  87: 5.083473
##  88: 5.035096
##  89: 5.101085
##  90: 5.113994
##  91: 3.770613
##  92: 3.827445
##  93: 3.908550
##  94: 3.859835
##  95: 4.302036
##  96: 4.036557
##  97: 4.057997
##  98: 4.275448
##  99: 4.297965
## 100: 3.663049
##           SVL

You can also use double bracket syntax to directly return column data as a named list.

td[["SVL"]]
##            ahli         allogus     rubribarbus           imias          sagrei 
##        4.039125        4.040138        4.078469        4.099687        4.067162 
##         bremeri quadriocellifer      ophiolepis         mestrei           jubar 
##        4.113371        3.901619        3.637962        3.987147        3.952605 
##      homolechis        confusus           guafe         garmani        opalinus 
##        4.032806        3.938442        3.877457        4.769473        3.838376 
##         grahami     valencienni      lineatopus      reconditus       evermanni 
##        4.154274        4.321524        4.128612        4.482607        4.165605 
##       stratulus           krugi      pulchellus       gundlachi       poncensis 
##        3.869881        3.886500        3.799022        4.188105        3.820378 
##           cooki    cristatellus    brevirostris        caudalis          marron 
##        4.091535        4.189820        3.874155        3.911743        3.831810 
##        websteri       distichus        barbouri         alumina    semilineatus 
##        3.916546        3.928796        3.663932        3.588941        3.696631 
##         olssoni      etheridgei         fowleri       insolitus       whitemani 
##        3.793899        3.657991        4.288780        3.800471        4.097479 
##       haetianus        breslini         armouri         cybotes         shrevei 
##        4.316542        4.051111        4.121684        4.210982        3.983003 
##   longitibialis         strahmi        marcanoi        baleatus       barahonae 
##        4.242103        4.274271        4.079485        5.053056        5.076958 
##        ricordii   eugenegrahami     christophei         cuvieri        barbatus 
##        5.013963        4.128504        3.884652        4.875012        5.003946 
##          porcus  chamaeleonides       guamuhaya   altitudinalis        oporinus 
##        5.038034        5.042349        5.036953        3.842994        3.845670 
##        isolepis        allisoni        porcatus     argillaceus       centralis 
##        3.657088        4.375390        4.258991        3.757869        3.697941 
##         pumilis        loysiana         guazuma        placidus        sheplani 
##        3.466860        3.701240        3.763884        3.773967        3.682924 
##         alayoni     angusticeps        paternus       alutaceus    inexpectatus 
##        3.815705        3.788595        3.802961        3.554891        3.537439 
##       clivicola    cupeyalensis    cyanopleurus         alfaroi      macilentus 
##        3.758726        3.462014        3.630161        3.526655        3.715765 
##       vanidicus     argenteolus          lucius        bartschi    vermiculatus 
##        3.626206        3.971307        4.198915        4.280547        4.802849 
##        baracoae          noblei      smallwoodi    luteogularis       equestris 
##        5.042780        5.083473        5.035096        5.101085        5.113994 
##       monticola   bahorucoensis dolichocephalus      hendersoni     darlingtoni 
##        3.770613        3.827445        3.908550        3.859835        4.302036 
##        aliniger      singularis    chlorocyanus     coelestinus        occultus 
##        4.036557        4.057997        4.275448        4.297965        3.663049

The same functionality can also be accomplished through the extractVector function. Both the double bracket syntax and the extractVector function will return a named vector.

extractVector(td, 'SVL')
##            ahli         allogus     rubribarbus           imias          sagrei 
##        4.039125        4.040138        4.078469        4.099687        4.067162 
##         bremeri quadriocellifer      ophiolepis         mestrei           jubar 
##        4.113371        3.901619        3.637962        3.987147        3.952605 
##      homolechis        confusus           guafe         garmani        opalinus 
##        4.032806        3.938442        3.877457        4.769473        3.838376 
##         grahami     valencienni      lineatopus      reconditus       evermanni 
##        4.154274        4.321524        4.128612        4.482607        4.165605 
##       stratulus           krugi      pulchellus       gundlachi       poncensis 
##        3.869881        3.886500        3.799022        4.188105        3.820378 
##           cooki    cristatellus    brevirostris        caudalis          marron 
##        4.091535        4.189820        3.874155        3.911743        3.831810 
##        websteri       distichus        barbouri         alumina    semilineatus 
##        3.916546        3.928796        3.663932        3.588941        3.696631 
##         olssoni      etheridgei         fowleri       insolitus       whitemani 
##        3.793899        3.657991        4.288780        3.800471        4.097479 
##       haetianus        breslini         armouri         cybotes         shrevei 
##        4.316542        4.051111        4.121684        4.210982        3.983003 
##   longitibialis         strahmi        marcanoi        baleatus       barahonae 
##        4.242103        4.274271        4.079485        5.053056        5.076958 
##        ricordii   eugenegrahami     christophei         cuvieri        barbatus 
##        5.013963        4.128504        3.884652        4.875012        5.003946 
##          porcus  chamaeleonides       guamuhaya   altitudinalis        oporinus 
##        5.038034        5.042349        5.036953        3.842994        3.845670 
##        isolepis        allisoni        porcatus     argillaceus       centralis 
##        3.657088        4.375390        4.258991        3.757869        3.697941 
##         pumilis        loysiana         guazuma        placidus        sheplani 
##        3.466860        3.701240        3.763884        3.773967        3.682924 
##         alayoni     angusticeps        paternus       alutaceus    inexpectatus 
##        3.815705        3.788595        3.802961        3.554891        3.537439 
##       clivicola    cupeyalensis    cyanopleurus         alfaroi      macilentus 
##        3.758726        3.462014        3.630161        3.526655        3.715765 
##       vanidicus     argenteolus          lucius        bartschi    vermiculatus 
##        3.626206        3.971307        4.198915        4.280547        4.802849 
##        baracoae          noblei      smallwoodi    luteogularis       equestris 
##        5.042780        5.083473        5.035096        5.101085        5.113994 
##       monticola   bahorucoensis dolichocephalus      hendersoni     darlingtoni 
##        3.770613        3.827445        3.908550        3.859835        4.302036 
##        aliniger      singularis    chlorocyanus     coelestinus        occultus 
##        4.036557        4.057997        4.275448        4.297965        3.663049

Multiple traits can also be extracted using extractVector.

extractVector(td, 'SVL','ecomorph')
## $SVL
##            ahli         allogus     rubribarbus           imias          sagrei 
##        4.039125        4.040138        4.078469        4.099687        4.067162 
##         bremeri quadriocellifer      ophiolepis         mestrei           jubar 
##        4.113371        3.901619        3.637962        3.987147        3.952605 
##      homolechis        confusus           guafe         garmani        opalinus 
##        4.032806        3.938442        3.877457        4.769473        3.838376 
##         grahami     valencienni      lineatopus      reconditus       evermanni 
##        4.154274        4.321524        4.128612        4.482607        4.165605 
##       stratulus           krugi      pulchellus       gundlachi       poncensis 
##        3.869881        3.886500        3.799022        4.188105        3.820378 
##           cooki    cristatellus    brevirostris        caudalis          marron 
##        4.091535        4.189820        3.874155        3.911743        3.831810 
##        websteri       distichus        barbouri         alumina    semilineatus 
##        3.916546        3.928796        3.663932        3.588941        3.696631 
##         olssoni      etheridgei         fowleri       insolitus       whitemani 
##        3.793899        3.657991        4.288780        3.800471        4.097479 
##       haetianus        breslini         armouri         cybotes         shrevei 
##        4.316542        4.051111        4.121684        4.210982        3.983003 
##   longitibialis         strahmi        marcanoi        baleatus       barahonae 
##        4.242103        4.274271        4.079485        5.053056        5.076958 
##        ricordii   eugenegrahami     christophei         cuvieri        barbatus 
##        5.013963        4.128504        3.884652        4.875012        5.003946 
##          porcus  chamaeleonides       guamuhaya   altitudinalis        oporinus 
##        5.038034        5.042349        5.036953        3.842994        3.845670 
##        isolepis        allisoni        porcatus     argillaceus       centralis 
##        3.657088        4.375390        4.258991        3.757869        3.697941 
##         pumilis        loysiana         guazuma        placidus        sheplani 
##        3.466860        3.701240        3.763884        3.773967        3.682924 
##         alayoni     angusticeps        paternus       alutaceus    inexpectatus 
##        3.815705        3.788595        3.802961        3.554891        3.537439 
##       clivicola    cupeyalensis    cyanopleurus         alfaroi      macilentus 
##        3.758726        3.462014        3.630161        3.526655        3.715765 
##       vanidicus     argenteolus          lucius        bartschi    vermiculatus 
##        3.626206        3.971307        4.198915        4.280547        4.802849 
##        baracoae          noblei      smallwoodi    luteogularis       equestris 
##        5.042780        5.083473        5.035096        5.101085        5.113994 
##       monticola   bahorucoensis dolichocephalus      hendersoni     darlingtoni 
##        3.770613        3.827445        3.908550        3.859835        4.302036 
##        aliniger      singularis    chlorocyanus     coelestinus        occultus 
##        4.036557        4.057997        4.275448        4.297965        3.663049 
## 
## $ecomorph
##            ahli         allogus     rubribarbus           imias          sagrei 
##            "TG"            "TG"            "TG"            "TG"            "TG" 
##         bremeri quadriocellifer      ophiolepis         mestrei           jubar 
##            "TG"            "TG"            "GB"            "TG"            "TG" 
##      homolechis        confusus           guafe         garmani        opalinus 
##            "TG"            "TG"            "TG"            "CG"            "TC" 
##         grahami     valencienni      lineatopus      reconditus       evermanni 
##            "TC"            "TW"            "TG"             "U"            "TC" 
##       stratulus           krugi      pulchellus       gundlachi       poncensis 
##            "TC"            "GB"            "GB"            "TG"            "GB" 
##           cooki    cristatellus    brevirostris        caudalis          marron 
##            "TG"            "TG"             "T"             "T"             "T" 
##        websteri       distichus        barbouri         alumina    semilineatus 
##             "T"             "T"             "U"            "GB"            "GB" 
##         olssoni      etheridgei         fowleri       insolitus       whitemani 
##            "GB"             "U"             "U"            "TW"            "TG" 
##       haetianus        breslini         armouri         cybotes         shrevei 
##            "TG"            "TG"            "TG"            "TG"            "TG" 
##   longitibialis         strahmi        marcanoi        baleatus       barahonae 
##            "TG"            "TG"            "TG"            "CG"            "CG" 
##        ricordii   eugenegrahami     christophei         cuvieri        barbatus 
##            "CG"             "U"             "U"            "CG"             "U" 
##          porcus  chamaeleonides       guamuhaya   altitudinalis        oporinus 
##             "U"             "U"             "U"            "TC"            "TC" 
##        isolepis        allisoni        porcatus     argillaceus       centralis 
##            "TC"            "TC"            "TC"             "U"             "U" 
##         pumilis        loysiana         guazuma        placidus        sheplani 
##             "U"             "T"            "TW"            "TW"            "TW" 
##         alayoni     angusticeps        paternus       alutaceus    inexpectatus 
##            "TW"            "TW"            "TW"            "GB"            "GB" 
##       clivicola    cupeyalensis    cyanopleurus         alfaroi      macilentus 
##            "GB"            "GB"            "GB"            "GB"            "GB" 
##       vanidicus     argenteolus          lucius        bartschi    vermiculatus 
##            "GB"             "U"             "U"             "U"             "U" 
##        baracoae          noblei      smallwoodi    luteogularis       equestris 
##            "CG"            "CG"            "CG"            "CG"            "CG" 
##       monticola   bahorucoensis dolichocephalus      hendersoni     darlingtoni 
##             "U"            "GB"            "GB"            "GB"            "TW" 
##        aliniger      singularis    chlorocyanus     coelestinus        occultus 
##            "TC"            "TC"            "TC"            "TC"            "TW"

However, there’s a couple aspects that are unique to [[.treedata.table() and extractVector(). First, [[.treedata.table() has an extra exact argument to enable partial match (i.e. when target strings and those in the treedata.table object match partially). Second, extractVector() can extract multiple columns and accepts non-standard evaluation (i.e. names are treated as string literals).

The real power in treedata.table is in co-indexing the tree and table. For example, in the below command, we use data.table syntax to take the first representative from each ecomorph. We retain all data columns. If you examine the tree object, you will see that it has had all the tips absent from the resultant data.table.

 td[, head(.SD, 1), by = "ecomorph"]
## $phy 
## 
## Phylogenetic tree with 7 tips and 6 internal nodes.
## 
## Tip labels:
##   ahli, ophiolepis, garmani, opalinus, valencienni, reconditus, ...
## 
## Rooted; includes branch lengths.
## 
## $dat 
##    ecomorph   tip.label      SVL  PCI_limbs  PCII_head PCIII_padwidth_vs_tail
##      <char>      <char>    <num>      <num>      <num>                  <num>
## 1:       TG        ahli 4.039125 -3.2482860  0.3722519             -1.0422187
## 2:       GB  ophiolepis 3.637962  0.7915117  1.4585760             -1.3152005
## 3:       CG     garmani 4.769473 -0.7735264  0.9371249              0.2594994
## 4:       TC    opalinus 3.838376 -1.7794371 -0.3245381              1.5569939
## 5:       TW valencienni 4.321524  2.9424139 -0.8846007              1.8543308
## 6:        U  reconditus 4.482607 -2.7270416 -0.2104066             -2.3534242
##    PCIV_lamella_num awesomeness   hostility    attitude      island
##               <num>       <num>       <num>       <num>      <char>
## 1:       -2.4147423 -0.24165170 -0.17347691  0.64437708        Cuba
## 2:       -2.2377514  0.35441877  0.05366142 -0.09389530        Cuba
## 3:        0.1051149  0.16779131  0.67675600 -0.69460080 Puerto Rico
## 4:        0.9366501  1.48302162 -0.90826653  0.72613483     Jamaica
## 5:        0.1288233 -0.08837008  0.46528679 -0.56754896     Jamaica
## 6:       -0.7992905  0.26096544 -0.27169792  0.01367143     Jamaica

We could also do the same operation with multiple columns:

td[, head(.SD, 1), by = .(ecomorph, island)]
## $phy 
## 
## Phylogenetic tree with 23 tips and 22 internal nodes.
## 
## Tip labels:
##   ahli, ophiolepis, garmani, opalinus, grahami, valencienni, ...
## 
## Rooted; includes branch lengths.
## 
## $dat 
##    ecomorph      island   tip.label      SVL  PCI_limbs  PCII_head
##      <char>      <char>      <char>    <num>      <num>      <num>
## 1:       TG        Cuba        ahli 4.039125 -3.2482860  0.3722519
## 2:       GB        Cuba  ophiolepis 3.637962  0.7915117  1.4585760
## 3:       CG Puerto Rico     garmani 4.769473 -0.7735264  0.9371249
## 4:       TC     Jamaica    opalinus 3.838376 -1.7794371 -0.3245381
## 5:       TC Puerto Rico     grahami 4.154274 -2.3056535 -1.9139369
## 6:       TW     Jamaica valencienni 4.321524  2.9424139 -0.8846007
##    PCIII_padwidth_vs_tail PCIV_lamella_num awesomeness   hostility   attitude
##                     <num>            <num>       <num>       <num>      <num>
## 1:             -1.0422187       -2.4147423 -0.24165170 -0.17347691  0.6443771
## 2:             -1.3152005       -2.2377514  0.35441877  0.05366142 -0.0938953
## 3:              0.2594994        0.1051149  0.16779131  0.67675600 -0.6946008
## 4:              1.5569939        0.9366501  1.48302162 -0.90826653  0.7261348
## 5:              1.6852579        1.0144193  0.41064280 -0.11746257  0.7022959
## 6:              1.8543308        0.1288233 -0.08837008  0.46528679 -0.5675490

Tail is also implemented

 td[, tail(.SD, 1), by = "ecomorph"]
## $phy 
## 
## Phylogenetic tree with 7 tips and 6 internal nodes.
## 
## Tip labels:
##   marcanoi, loysiana, equestris, monticola, hendersoni, coelestinus, ...
## 
## Rooted; includes branch lengths.
## 
## $dat 
##    ecomorph   tip.label      SVL   PCI_limbs  PCII_head PCIII_padwidth_vs_tail
##      <char>      <char>    <num>       <num>      <num>                  <num>
## 1:       TG    marcanoi 4.079485 -2.84448243 -2.7864415             -0.8020303
## 2:       GB  hendersoni 3.859835  1.28963045 -2.0630985             -3.4656535
## 3:       CG   equestris 5.113994  1.05461517  0.7072039              0.7108046
## 4:       TC coelestinus 4.297965 -0.02721683  0.3687537              1.6364316
## 5:       TW    occultus 3.663049  7.92078444 -0.1901397              2.4922819
## 6:        U   monticola 3.770613 -3.25118016  0.1559934             -2.2390082
##    PCIV_lamella_num awesomeness  hostility   attitude      island
##               <num>       <num>      <num>      <num>      <char>
## 1:      -1.04842823   1.1823433 -0.1671936  0.5827900  Hispaniola
## 2:       2.58336718   0.3854544 -0.7133164 -0.3959792  Hispaniola
## 3:       1.66043194   1.0805662 -1.2666114  0.6673026        Cuba
## 4:       1.02571762   0.2909266 -0.6209660  1.2803335  Hispaniola
## 5:      -0.09577977  -1.1916870  1.2153014  0.0324486 Puerto Rico
## 6:       0.13156827   0.6289893  0.1468777 -0.4409775  Hispaniola

Columns in the treedata.table object can also be operated on using general data.table syntax. In the below example, the tree is pruned to those tips that occur in Cuba. This is the data.table equivalent of dplyr’s filter. Then, a new column is created in the data.table, assigned the name “Index”, and assigned the value of the SVL + the hostility index. This enables concurrent manipulation of the phylogeny, and the calculation of a new index for only those tips we would actually like to use.

td[island == "Cuba",.(Index=SVL+hostility)]
## $phy 
## 
## Phylogenetic tree with 47 tips and 46 internal nodes.
## 
## Tip labels:
##   ahli, allogus, rubribarbus, imias, sagrei, bremeri, ...
## 
## Rooted; includes branch lengths.
## 
## $dat 
##       Index
##       <num>
## 1: 3.865649
## 2: 3.540042
## 3: 4.558514
## 4: 3.688875
## 5: 4.786475
## 6: 5.526089

Running functions on treedata.table objects

In the below command, we extract one vector from our data.table and use geiger’s continuous model fitting to estimate a Brownian motion model for the data using the tdt function.

tdt(td, geiger::fitContinuous(phy, extractVector(td, 'SVL'), model="BM", ncores=1))
## Phylo object detected. Expect a single function output
## GEIGER-fitted comparative model of continuous data
##  fitted 'BM' model parameters:
##  sigsq = 0.136160
##  z0 = 4.065918
## 
##  model summary:
##  log-likelihood = -4.700404
##  AIC = 13.400807
##  AICc = 13.524519
##  free parameters = 2
## 
## Convergence diagnostics:
##  optimization iterations = 100
##  failed iterations = 0
##  number of iterations with same best fit = 100
##  frequency of best fit = 1.000
## 
##  object summary:
##  'lik' -- likelihood function
##  'bnd' -- bounds for likelihood search
##  'res' -- optimization iteration summary
##  'opt' -- maximum likelihood parameter estimates

Dropping and extracting taxa from treedata.table objects

We can also drop tips directly from the tree, and have those tips drop concurrently from the data.table. In the example below, we remove two taxa by name.

dt <- droptreedata.table(tdObject=td, taxa=c("chamaeleonides" ,"eugenegrahami" ))
## 2 taxa were dropped from the treedata.table object

We can check if A. chamaeleonides and A. eugenegrahami are still in the tree

c("chamaeleonides" ,"eugenegrahami" ) %in% dt$phy$tip.label
## [1] FALSE FALSE

And we can do the same with the data in the treedata.table object

c("chamaeleonides" ,"eugenegrahami" ) %in% dt$dat$X
## [1] FALSE FALSE

When you’re done, the data.table and tree can both be extracted from the object:

df <- pulltreedata.table(td, "dat")
tree <- pulltreedata.table(td, "phy")

The table

df
##            tip.label      SVL   PCI_limbs   PCII_head PCIII_padwidth_vs_tail
##               <char>    <num>       <num>       <num>                  <num>
##   1:            ahli 4.039125 -3.24828599  0.37225191             -1.0422187
##   2:         allogus 4.040138 -2.84557021  0.60011341             -1.0253056
##   3:     rubribarbus 4.078469 -2.23834859  1.11997785             -1.1929572
##   4:           imias 4.099687 -3.04891725  2.33203488              0.1616442
##   5:          sagrei 4.067162 -1.74105547  2.02282431              0.1693635
##   6:         bremeri 4.113371 -1.81361138  2.60675012              0.6399320
##   7: quadriocellifer 3.901619 -2.26789400  0.99092075              0.3553405
##   8:      ophiolepis 3.637962  0.79151174  1.45857603             -1.3152005
##   9:         mestrei 3.987147 -2.60261906  1.27568612              0.4640379
##  10:           jubar 3.952605 -2.22414593  0.94489985              0.6600716
##  11:      homolechis 4.032806 -2.74499346  0.87926009              0.8679694
##  12:        confusus 3.938442 -2.49591732  0.16823269              0.1551290
##  13:           guafe 3.877457 -2.61408710  0.65608676              0.6071245
##  14:         garmani 4.769473 -0.77352640  0.93712494              0.2594994
##  15:        opalinus 3.838376 -1.77943710 -0.32453812              1.5569939
##  16:         grahami 4.154274 -2.30565354 -1.91393689              1.6852579
##  17:     valencienni 4.321524  2.94241389 -0.88460072              1.8543308
##  18:      lineatopus 4.128612 -2.43081291 -3.12552390             -1.7564495
##  19:      reconditus 4.482607 -2.72704156 -0.21040657             -2.3534242
##  20:       evermanni 4.165605 -2.52899245  0.12548098              1.8824633
##  21:       stratulus 3.869881 -1.62264165 -0.52957490              2.2166952
##  22:           krugi 3.886500 -1.68879533 -0.83128181             -1.2588892
##  23:      pulchellus 3.799022  0.16238151 -2.33846103             -1.5906715
##  24:       gundlachi 4.188105 -2.64936274 -0.56251604             -2.2852265
##  25:       poncensis 3.820378  0.52782664  1.24062035             -1.6249761
##  26:           cooki 4.091535 -2.22079009  0.05979850             -0.1092647
##  27:    cristatellus 4.189820 -3.33026331 -0.62225189              1.2175309
##  28:    brevirostris 3.874155 -3.28900081  1.38425488              2.4070756
##  29:        caudalis 3.911743 -1.78270839  1.90870776              1.7530966
##  30:          marron 3.831810 -2.84709341 -0.12032028              1.6898101
##  31:        websteri 3.916546 -2.50870054  0.97482786              2.9024438
##  32:       distichus 3.928796 -3.84343343  0.83890749              2.4922170
##  33:        barbouri 3.663932 -0.87536237  1.34009434             -2.6138245
##  34:         alumina 3.588941  0.72166993  1.52514444             -2.6721669
##  35:    semilineatus 3.696631  0.18403236 -0.13872022             -2.8957227
##  36:         olssoni 3.793899  0.81682668  3.87442813             -2.4337310
##  37:      etheridgei 3.657991 -3.81065955 -0.75340900             -2.0659201
##  38:         fowleri 4.288780 -1.03667003  1.50383762             -1.7589251
##  39:       insolitus 3.800471  5.03062671  0.24137669              0.9139707
##  40:       whitemani 4.097479 -2.54584901 -3.25974024             -1.9200701
##  41:       haetianus 4.316542 -3.40402925 -3.78444664             -1.7798344
##  42:        breslini 4.051111 -2.97497529 -3.34153375             -1.8978249
##  43:         armouri 4.121684 -3.16993598 -4.08620441             -0.8883209
##  44:         cybotes 4.210982 -3.11637922 -2.99620854             -0.8299057
##  45:         shrevei 3.983003 -2.25952607 -3.55788235             -1.3884348
##  46:   longitibialis 4.242103 -3.52243048 -1.61670439             -1.6182845
##  47:         strahmi 4.274271 -3.87340303 -1.01635836             -0.9366696
##  48:        marcanoi 4.079485 -2.84448243 -2.78644148             -0.8020303
##  49:        baleatus 5.053056  0.73766495  1.79646028             -0.5409516
##  50:       barahonae 5.076958  0.90731040  2.33222342             -0.6158464
##  51:        ricordii 5.013963  0.58940470  1.34670464             -0.8626956
##  52:   eugenegrahami 4.128504 -4.21209140  4.83351955              1.0228151
##  53:     christophei 3.884652 -2.70596332  1.70527559             -0.1725921
##  54:         cuvieri 4.875012 -1.18955124 -0.71983364             -1.0167340
##  55:        barbatus 5.003946  2.25020229 -3.30818172              1.3476390
##  56:          porcus 5.038034  3.50614537 -2.98667964              0.7500647
##  57:  chamaeleonides 5.042349  2.95597428 -3.69231889              1.3297304
##  58:       guamuhaya 5.036953  3.10947396 -4.07973423             -0.1820287
##  59:   altitudinalis 3.842994  2.86751469 -6.12805047              2.3331196
##  60:        oporinus 3.845670  3.05888289 -2.91565342              2.2875989
##  61:        isolepis 3.657088  3.05697642 -4.34018373              2.4409248
##  62:        allisoni 4.375390  2.03597967 -3.74252815              0.5203703
##  63:        porcatus 4.258991  1.93193251 -3.82953305              0.9781194
##  64:     argillaceus 3.757869 -0.11307851 -1.48944374              2.3710815
##  65:       centralis 3.697941  0.73073876 -0.41683597              1.7586477
##  66:         pumilis 3.466860  0.55404946 -0.42584152              2.1572563
##  67:        loysiana 3.701240  0.31536951 -1.08038145              2.7442074
##  68:         guazuma 3.763884  8.16566506 -0.60605865              1.7597408
##  69:        placidus 3.773967  7.38332866  0.53958973              2.7042981
##  70:        sheplani 3.682924 10.27389091  2.27784409              1.6981742
##  71:         alayoni 3.815705  3.40888624 -1.78335850              2.2084510
##  72:     angusticeps 3.788595  4.58711071 -1.97673831              1.1594671
##  73:        paternus 3.802961  2.90637723 -0.95846093              0.9491115
##  74:       alutaceus 3.554891  1.17338999 -0.61493813             -1.6539883
##  75:    inexpectatus 3.537439  2.50607244 -0.52340367             -2.8057449
##  76:       clivicola 3.758726 -1.05114421 -0.58903393             -1.2178042
##  77:    cupeyalensis 3.462014  2.72419698  0.48960424             -2.4795271
##  78:    cyanopleurus 3.630161  0.43328510  0.98930100             -2.8189997
##  79:         alfaroi 3.526655  2.58175921  0.77876335             -2.4463337
##  80:      macilentus 3.715765  3.15177391  3.26626613             -3.7238293
##  81:       vanidicus 3.626206  4.04436760  1.08716320             -2.4921192
##  82:     argenteolus 3.971307 -2.92797328  2.61964493              0.9791727
##  83:          lucius 4.198915 -4.38139803  1.25981123              2.1899604
##  84:        bartschi 4.280547 -3.25502168  0.80565652              1.1234288
##  85:    vermiculatus 4.802849  0.22783467  1.41411087             -1.8467441
##  86:        baracoae 5.042780  0.76817392  0.06987127              0.1805891
##  87:          noblei 5.083473 -0.09337994 -0.96088851              0.8905492
##  88:      smallwoodi 5.035096 -0.13770527 -1.15140405              0.4296432
##  89:    luteogularis 5.101085  0.39614254  0.73584435              1.0058546
##  90:       equestris 5.113994  1.05461517  0.70720387              0.7108046
##  91:       monticola 3.770613 -3.25118016  0.15599344             -2.2390082
##  92:   bahorucoensis 3.827445 -0.04747332 -2.55694724             -3.0896949
##  93: dolichocephalus 3.908550  2.60131528 -2.59530770             -4.1439327
##  94:      hendersoni 3.859835  1.28963045 -2.06309845             -3.4656535
##  95:     darlingtoni 4.302036  4.06703170 -1.49378979             -0.2002259
##  96:        aliniger 4.036557  0.12323898 -1.67467041              2.3871336
##  97:      singularis 4.057997  0.36326789 -0.95422871              1.6562154
##  98:    chlorocyanus 4.275448  0.43906343  1.35403450              1.9531470
##  99:     coelestinus 4.297965 -0.02721683  0.36875369              1.6364316
## 100:        occultus 3.663049  7.92078444 -0.19013968              2.4922819
##            tip.label      SVL   PCI_limbs   PCII_head PCIII_padwidth_vs_tail
##      PCIV_lamella_num  awesomeness    hostility    attitude ecomorph
##                 <num>        <num>        <num>       <num>   <char>
##   1:      -2.41474228 -0.241651698 -0.173476906  0.64437708       TG
##   2:      -2.46331106  0.624468879 -0.500096224  0.71289104       TG
##   3:      -2.08743282 -0.427757376  0.480044450 -0.96742634       TG
##   4:      -2.11260585  0.169425977 -0.410812337  0.19635800       TG
##   5:      -1.37576941 -0.630433775  0.719312962 -1.22282764       TG
##   6:      -1.62629939 -1.754300558  1.412718374  0.18323450       TG
##   7:      -2.10505922 -0.257638879  0.462708058 -0.27127944       TG
##   8:      -2.23775137  0.354418772  0.053661422 -0.09389530       GB
##   9:      -1.19666399 -0.228920131  0.820920959 -0.73929564       TG
##  10:      -1.65749549  2.145582200 -0.993730897  1.05775273       TG
##  11:      -1.56665822 -0.085375433  0.092602997 -0.08130904       TG
##  12:      -1.39796407  0.496114209 -0.544543392  1.36010631       TG
##  13:      -1.48220834 -0.139145550 -0.310434629 -0.50480610       TG
##  14:       0.10511495  0.167791307  0.676756002 -0.69460080       CG
##  15:       0.93665013  1.483021624 -0.908266532  0.72613483       TC
##  16:       1.01441926  0.410642801 -0.117462571  0.70229589       TC
##  17:       0.12882327 -0.088370075  0.465286788 -0.56754896       TW
##  18:      -1.43952303  0.800931449  0.170290172  0.33555714       TG
##  19:      -0.79929053  0.260965443 -0.271697917  0.01367143        U
##  20:       1.92392086  1.871367582 -2.029729624  1.02877511       TC
##  21:       0.94622231 -0.314853533  0.515229477 -0.40828716       TC
##  22:       0.24029913  0.972494741 -0.371866585  1.46109470       GB
##  23:       0.68180888  0.978157532 -0.810754596  1.39277529       GB
##  24:      -2.48420519 -0.426336538  0.613014449 -0.69318262       TG
##  25:      -0.94924727 -0.289982852  0.510241609 -0.18543914       GB
##  26:      -0.50826932  1.277956446 -1.082760383  1.37721870       TG
##  27:      -1.21819703  0.830658098 -0.007447027  0.39061232       TG
##  28:      -0.82666991 -1.538338585  1.633533660 -1.24247895        T
##  29:      -1.44378878 -0.601304152  0.216500950  0.85182003        T
##  30:      -1.57063776 -2.149486418  2.413050748 -2.14378229        T
##  31:      -1.53259879  0.025584758  0.124044450  0.11758642        T
##  32:      -1.03972507  1.973200862 -1.608003643  0.91461500        T
##  33:      -4.30147185  1.788945648 -0.913725183  0.64025272        U
##  34:       1.23487950 -1.253724344  1.308419442 -0.96110895       GB
##  35:       0.92280509 -0.612226281  0.807322377 -0.82943161       GB
##  36:       0.62906887 -1.391771586  1.210221860 -0.29186894       GB
##  37:      -0.74890866  0.848149691 -0.960258609  0.18291181        U
##  38:      -1.71914111  1.456935239 -1.448418148  0.07531334        U
##  39:      -0.42075245  0.066715596 -0.290651288  0.07286240       TW
##  40:      -2.41993928 -1.457775289  1.096071557 -0.87393333       TG
##  41:      -2.20379012  0.721747833 -0.969190196  0.74101761       TG
##  42:      -2.16718706 -1.944082859  2.147925602 -2.07465046       TG
##  43:      -2.02129909 -0.158605136 -0.369246555 -0.26866597       TG
##  44:      -2.09049464  0.905454434 -0.262630999  0.68467864       TG
##  45:      -2.19082487  0.257277082  0.029600473  0.39422885       TG
##  46:      -2.67106616  2.537213358 -1.420542767  1.71562944       TG
##  47:      -1.57843390  0.340077411 -0.690011247  2.11135720       TG
##  48:      -1.04842823  1.182343323 -0.167193617  0.58279004       TG
##  49:      -0.16220546  2.727286255 -2.487661729  2.78477616       CG
##  50:      -0.19473780  1.831370900 -1.331616706  1.70626854       CG
##  51:       0.03516802 -0.456651495  0.663302028 -0.64625837       CG
##  52:       1.66539278  2.155800992 -2.494661307  1.11438687        U
##  53:       0.64693336 -0.266699615  0.220410336  1.46547483        U
##  54:      -0.02153073 -0.115917120  0.281153377 -0.97876663       CG
##  55:      -1.64780456  2.156287540 -2.094147109  1.97196598        U
##  56:      -1.19909229  0.158971414 -0.350187677  0.45987065        U
##  57:      -1.51973745 -1.193993760  1.858148718 -1.43308743        U
##  58:      -0.10748930 -0.137962568  0.119982369  0.04203987        U
##  59:       0.68195498  1.164592168 -0.865462260  0.63326685       TC
##  60:      -0.08659903  0.573048475 -0.985921965  0.88025286       TC
##  61:      -0.07418779 -0.194644197  0.001671326  0.16264659       TC
##  62:       2.05565172 -0.132309870  0.464556617 -0.54956842       TC
##  63:       2.88538479 -0.074646660  0.148259194 -0.57178426       TC
##  64:       0.33264142  0.007554828 -0.259421287 -0.62559912        U
##  65:      -1.13869021 -0.620236225  0.330225203 -0.71777358        U
##  66:      -1.12208954  0.459254083 -0.162682657 -0.47694819        U
##  67:      -0.52657687  2.153959487 -1.198967281  1.51422456        T
##  68:       1.55102509 -0.015197500 -0.020516523  0.08678021       TW
##  69:      -0.31778878  0.078986096  0.504242392 -0.40436325       TW
##  70:      -0.25962432 -0.431283305  0.321955192 -0.80553288       TW
##  71:       0.94969689 -0.259032167  0.127344278  0.29597325       TW
##  72:       0.38835687  1.713217290 -1.884387903  0.92471752       TW
##  73:       1.80146660 -0.299550789  0.846263466 -0.96311064       TW
##  74:       1.41160228  0.325807029 -0.523648505  0.50405157       GB
##  75:       1.68036114  0.244666550 -0.307162858  0.06937286       GB
##  76:      -0.55865998  0.340444764 -0.599034616  1.78969146       GB
##  77:      -0.03297035  1.327984163 -0.994951781  0.04668455       GB
##  78:       0.87176931  0.413447859  0.073949884 -0.50654925       GB
##  79:       0.70036608 -0.462062012  0.178370302 -0.01958915       GB
##  80:       1.21810218  0.868463721 -0.287882420  0.69946303       GB
##  81:       0.18942396 -1.287008036  1.023037680 -0.67591746       GB
##  82:       2.94194227  0.490363636 -0.505416684 -0.20254651        U
##  83:       1.75435972  0.126135253  0.545903248 -0.58505782        U
##  84:       1.74943703 -1.189744988  1.025075387  0.25994625        U
##  85:       0.71173422  0.159291276 -0.024230945 -0.31575501        U
##  86:       2.66309134  1.821981086 -1.522244645  2.17591511       CG
##  87:       2.09456880 -0.974406590  1.602507741 -0.42228829       CG
##  88:       2.44067497 -0.018317012 -0.366531140  1.59163441       CG
##  89:       1.98043577  0.194610912  0.713343825 -0.56222110       CG
##  90:       1.66043194  1.080566180 -1.266611407  0.66730260       CG
##  91:       0.13156827  0.628989307  0.146877669 -0.44097752        U
##  92:       1.56271877  2.553879072 -2.337986521  2.47075117       GB
##  93:       3.67023402  0.739483022 -0.989799476  1.09191365       GB
##  94:       2.58336718  0.385454354 -0.713316425 -0.39597920       GB
##  95:       0.31138087  1.718720076 -1.690079016  1.02145675       TW
##  96:       0.58486431  0.006869282  0.144815367  0.29376432       TC
##  97:       1.00756926  1.592083294 -1.701052660  1.45313446       TC
##  98:       1.80512493 -1.065610146  0.920097708 -0.93721735       TC
##  99:       1.02571762  0.290926638 -0.620965953  1.28033350       TC
## 100:      -0.09577977 -1.191686980  1.215301402  0.03244860       TW
##      PCIV_lamella_num  awesomeness    hostility    attitude ecomorph
##           island
##           <char>
##   1:        Cuba
##   2:        Cuba
##   3:        Cuba
##   4:        Cuba
##   5:        Cuba
##   6:        Cuba
##   7:        Cuba
##   8:        Cuba
##   9:        Cuba
##  10:        Cuba
##  11:        Cuba
##  12:        Cuba
##  13:        Cuba
##  14: Puerto Rico
##  15:     Jamaica
##  16: Puerto Rico
##  17:     Jamaica
##  18:     Jamaica
##  19:     Jamaica
##  20: Puerto Rico
##  21: Puerto Rico
##  22: Puerto Rico
##  23: Puerto Rico
##  24: Puerto Rico
##  25: Puerto Rico
##  26: Puerto Rico
##  27: Puerto Rico
##  28:  Hispaniola
##  29:  Hispaniola
##  30:  Hispaniola
##  31:  Hispaniola
##  32:  Hispaniola
##  33:  Hispaniola
##  34:  Hispaniola
##  35:  Hispaniola
##  36:  Hispaniola
##  37:  Hispaniola
##  38:  Hispaniola
##  39:  Hispaniola
##  40:  Hispaniola
##  41:  Hispaniola
##  42:  Hispaniola
##  43:  Hispaniola
##  44:  Hispaniola
##  45:  Hispaniola
##  46:  Hispaniola
##  47:  Hispaniola
##  48:  Hispaniola
##  49:  Hispaniola
##  50:  Hispaniola
##  51:  Hispaniola
##  52:  Hispaniola
##  53:  Hispaniola
##  54: Puerto Rico
##  55:        Cuba
##  56:        Cuba
##  57:        Cuba
##  58:        Cuba
##  59:        Cuba
##  60:        Cuba
##  61:        Cuba
##  62:        Cuba
##  63:        Cuba
##  64:        Cuba
##  65:        Cuba
##  66:        Cuba
##  67:        Cuba
##  68:        Cuba
##  69:  Hispaniola
##  70:  Hispaniola
##  71:        Cuba
##  72:        Cuba
##  73:        Cuba
##  74:        Cuba
##  75:        Cuba
##  76:        Cuba
##  77:        Cuba
##  78:        Cuba
##  79:        Cuba
##  80:        Cuba
##  81:        Cuba
##  82:        Cuba
##  83:        Cuba
##  84:        Cuba
##  85:        Cuba
##  86:        Cuba
##  87:        Cuba
##  88:        Cuba
##  89:        Cuba
##  90:        Cuba
##  91:  Hispaniola
##  92:  Hispaniola
##  93:  Hispaniola
##  94:  Hispaniola
##  95:  Hispaniola
##  96:  Hispaniola
##  97:  Hispaniola
##  98:  Hispaniola
##  99:  Hispaniola
## 100: Puerto Rico
##           island

and the corresponding tree

tree
## 
## Phylogenetic tree with 100 tips and 99 internal nodes.
## 
## Tip labels:
##   ahli, allogus, rubribarbus, imias, sagrei, bremeri, ...
## 
## Rooted; includes branch lengths.