sim_history: Simulate history of discrete-character changes over a...

View source: R/posteriorpredictive_helpr.R

sim_historyR Documentation

Simulate history of discrete-character changes over a bifurcation tree conditional or unconditional on the tip states

Description

Simulate history of discrete-character changes over a bifurcation tree conditional or unconditional on the tip states

Usage

sim_history(
  tree,
  Q,
  Q_ages = NULL,
  root_freq = NULL,
  nsim = 1L,
  conditional = F,
  trait = NULL
)

Arguments

tree

A bifurcation tree of class "phylo"

Q

An instantaneous-rate matrix (or a list of matrices for a piecewise constant geographic model) characterizes the CTMC

Q_ages

Boundaries of time intervals for a piecewise constant geographic model (NULL means a constant model)

root_freq

The vector state frequencies at the root of the tree (that we will draw the root state from); if NULL then it's uniform

nsim

Number of simulations to perform

conditional

Whether condition on the observed states at the tip (i.e., stochastic mapping) or not (i.e., forward simulation)

trait

Name of the discrete trait used in the tree file (e.g., "states")

Value

A phylo and simmap object (or a multiPhylo and multiSimmap object when nsim > 1) that contains the simulated full history

Examples

tree <- ape::rtree(7)
Q <- matrix(c(-1, 1, 1, -1), ncol = 2, byrow = TRUE)
root_freq <- setNames(rep(0.5, 2), c("A", "B"))
one_history <- sim_history(tree, Q, root_freq = root_freq, conditional = FALSE)

jsigao/prioritree documentation built on Jan. 9, 2023, 5:35 a.m.