processBranchData: processBranchData

View source: R/processBranchData.R

processBranchDataR Documentation

processBranchData

Description

processBranchData

Usage

processBranchData(
  tree,
  dat,
  burnin = 0.25,
  parnames = c("avg_lambda", "avg_mu", "num_shifts"),
  summary = "median",
  net_div = FALSE
)

Arguments

tree

(treedata object; no default) a phylogenetic tree in the treedata format, or a list of lists of a single tree data object, such as the output of readTrees().

dat

(data.frame or list; no default) a data frame, or a list (of length 1) of a data frame, with branch specific data, such as the output of readTrace().

burnin

(numeric; 0.25) fraction of the markov-chain to discard

parnames

(character vector; c("avg_lambda", "avg_mu", "num_shifts")) Names of parameters to process

summary

(character; "median") function to summarize the continuous parameter. Typically mean or median

net_div

(logical; FALSE) Calculate net diversification?

Value

a treedata file with attached branch-specific data

Examples



# download the example dataset to working directory
url_rates <-
  "https://revbayes.github.io/tutorials/intro/data/primates_BDS_rates.log"
dest_path_rates <- "primates_BDS_rates.log"
download.file(url_rates, dest_path_rates)

url_tree <-
  "https://revbayes.github.io/tutorials/divrate/data/primates_tree.nex"
dest_path_tree <- "primates_tree.nex"
download.file(url_tree, dest_path_tree)

# to run on your own data, change this to the path to your data file
treefile <- dest_path_tree
logfile <- dest_path_rates

branch_data <- readTrace(logfile)
tree <- readTrees(paths = treefile)

annotated_tree <- processBranchData(tree, branch_data, summary = "median")

# you can plot this output
p <- plotTree(tree = annotated_tree,
              node_age_bars = FALSE,
              node_pp = FALSE,
              tip_labels = FALSE,
              color_branch_by = "avg_lambda",
              line_width = 0.8) +
     ggplot2::theme(legend.position=c(.1, .9));p
# remove files
# WARNING: only run for example dataset!
# otherwise you might delete your data!
file.remove(dest_path_tree, dest_path_rates)


RevGadgets documentation built on May 29, 2024, 10:03 a.m.