Getting Started with {phyf}
phyf.Rmd
library(phyf)
#>
#> Attaching package: 'phyf'
#> The following object is masked from 'package:stats':
#>
#> pf
library(ape)
test_tree <- rtree(100)
tree_pf <- pf_as_pf(test_tree)
tree_pf
#> # A tibble: 198 × 3
#> label is_tip phlo
#> <chr> <lgl> <pfc>
#> 1 t65 TRUE ◎── 0.98──→ Node2 ── 0.59──→ No…── 0.76──→ Node6 ── 0.42──→ t65
#> 2 t6 TRUE ◎── 0.98──→ Node2 ── 0.59──→ No… ── 0.76──→ Node6 ── 0.14──→ t6
#> 3 t22 TRUE ◎──0.984──→ Node2 ──0.590──→ No…──0.081──→ Node7 ──0.656──→ t22
#> 4 t19 TRUE ◎──0.984──→ Node2 ──0.590──→ No…──0.602──→ Node8 ──0.657──→ t19
#> 5 t2 TRUE ◎──0.984──→ Node2 ──0.590──→ No… ──0.602──→ Node8 ──0.329──→ t2
#> 6 t64 TRUE ◎── 0.98──→ Node2 ── 0.59──→ No…─ 0.87──→ Node11 ── 0.98──→ t64
#> 7 t40 TRUE ◎── 0.98──→ Node2 ── 0.59──→ No…─ 0.87──→ Node11 ── 0.22──→ t40
#> 8 t100 TRUE ◎── 0.98──→ Node2 ── 0.59──→ No… 0.66──→ Node12 ── 0.39──→ t100
#> 9 t28 TRUE ◎──0.984──→ Node2 ──0.590──→ No…─0.665──→ Node12 ──0.046──→ t28
#> 10 t71 TRUE ◎── 0.98──→ Node2 ── 0.59──→ No…─ 0.62──→ Node13 ── 0.60──→ t71
#> # ℹ 188 more rows
This tibble
is easy to join data by using the
node_names
, which include the tip labels from the phylogeny
as well as ‘NodeXX’ for internal nodes, where XX starts a 1 and goes to
the total number of internal nodes. You can also use
node_nums
to join by the node number, where the node number
uses the traditional ordering of the nodes used in the ape
package in phylo
objects. Usually you will only have data
on the tips, and so when joining to the pf
object (using
e.g. dplyr::left_join()
) the internal node rows will
recieve NA
values. This is the desired behaviour. The
missing values are easy to drop for fitting a model, but are useful
later when making prediction (that is, ancestral state estimates).
Here, we will use one of the built-in pf
datasets in
phyf to show off some of its feature.
data("avonet")
avonet
#> # A tibble: 13,338 × 39
#> label is_tip phlo Species3 Family3 Order3 Total.individuals Female
#> <chr> <lgl> <pfc> <chr> <chr> <chr> <dbl> <dbl>
#> 1 Rhea… TRUE ◎── 24.…ricana Rhea am… Rheidae Rheif… 5 2
#> 2 Rhea… TRUE ◎── 24.…ennata Rhea pe… Rheidae Rheif… 6 3
#> 3 Apte… TRUE ◎── 24.…tralis Apteryx… Aptery… Apter… 6 2
#> 4 Apte… TRUE ◎── 24.…ntelli Apteryx… Aptery… Apter… 4 2
#> 5 Apte… TRUE ◎── 24.…owenii Apteryx… Aptery… Apter… 5 2
#> 6 Apte… TRUE ◎── 24.…aastii Apteryx… Aptery… Apter… 9 6
#> 7 Drom… TRUE ◎── 24.…andiae Dromaiu… Dromai… Casua… 5 2
#> 8 Casu… TRUE ◎── 24.…uarius Casuari… Casuar… Casua… 7 2
#> 9 Casu… TRUE ◎── 24.…nnetti Casuari… Casuar… Casua… 4 1
#> 10 Stru… TRUE ◎── 2…amelus Struthi… Struth… Strut… 8 1
#> # ℹ 13,328 more rows
#> # ℹ 31 more variables: Male <dbl>, Unknown <dbl>, Complete.measures <dbl>,
#> # Beak.Length_Culmen <dbl>, Beak.Length_Nares <dbl>, Beak.Width <dbl>,
#> # Beak.Depth <dbl>, Tarsus.Length <dbl>, Wing.Length <dbl>,
#> # Kipps.Distance <dbl>, Secondary1 <dbl>, `Hand-Wing.Index` <dbl>,
#> # Tail.Length <dbl>, Mass <dbl>, Mass.Source <chr>, Mass.Refs.Other <chr>,
#> # Inference <chr>, Traits.inferred <chr>, Reference.species <chr>, …
First, let’s try plotting the object.