View source: R/posterior_at_nodes.R
posterior_at_nodes | R Documentation |
Group of functions to calculate the posterior probabilities of ancestral host repertoires at internal nodes of the symbiont tree.
posterior_at_nodes(history, tree, host_tree, nodes = NULL, state = c(2))
history |
Data frame with posterior samples of interaction histories returned from
|
tree |
Symbiont tree |
host_tree |
Host tree |
nodes |
Vector of internal nodes for which to calculate the posterior
probability of |
state |
Which state? Default is 2. For analyses using the 3-state model, give |
A list with three elements:
"samples
" An array of samples x nodes x hosts, containing the state of each sample.
"post_states
" An array of nodes x hosts x state containing the posterior probability
for each state.
"post_repertoires
" An array of nodes x hosts x repertoire containing the posterior
probability for 1) the "realized"
repertoire which is defined as state 2, and 2) the
"fundamental"
repertoire which is defined as having any state (usually 1 or 2).
The number of samples is the number of iterations in history
.
# read parasite and host tree
data_path <- system.file("extdata", package = "evolnets")
tree <- read_tree_from_revbayes(paste0(data_path,"/tree_pieridae.tre"))
host_tree <- ape::read.tree(paste0(data_path,"/host_tree_pieridae.phy"))
# read histories sampled during MCMC
history <- read_history(paste0(data_path,"/history_thin_pieridae.txt"), burnin = 0)
# calculate the posterior probability of host repertoires
# at chosen internal nodes of the parasite tree
nodes <- c(129:131)
pp_at_nodes <- posterior_at_nodes(history, tree, host_tree, nodes)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.