branch_matrix: Branch matrix

View source: R/branch_matrix.R

branch_matrixR Documentation

Branch matrix


Phylogenetic trees depict the evolutionary relationships between different species. Each branch in a phylogenetic tree represents a period of evolutionary history. Species that are connected to the same branch share the same period of evolutionary history represented by the branch. This function creates a matrix that shows which species are connected with which branches. In other words, it creates a matrix that shows which periods of evolutionary history each species has experienced.


branch_matrix(x, ...)

## Default S3 method:
branch_matrix(x, ...)

## S3 method for class 'phylo'
branch_matrix(x, assert_validity = TRUE, ...)



ape::phylo() tree object.


not used.


logical value (i.e. TRUE or FALSE indicating if the argument to x should be checked for validity. Defaults to TRUE.


Matrix::dgCMatrix sparse matrix object. Each row corresponds to a different species. Each column corresponds to a different branch. Species that inherit from a given branch are indicated with a one.


# load Matrix package to plot matrices

# load data

# generate species by branch matrix
m <- branch_matrix(sim_tree)

# plot data
par(mfrow = c(1,2))
plot(sim_tree, main = "phylogeny")
image(m, main = "branch matrix")

oppr documentation built on Sept. 8, 2022, 5:07 p.m.