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

View source: R/posteriorpredictive_functions.R

sim_history_unconditionalR Documentation

Simulate history of discrete-character changes over a bifurcation tree without conditioning on the tip states

Description

Simulate history of discrete-character changes over a bifurcation tree without conditioning on the tip states

Usage

sim_history_unconditional(
  tree,
  Q,
  Q_ages = NULL,
  states,
  root_freq = NULL,
  nsim = 1L
)

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

A vector containing boundaries of time intervals for a piecewise constant geographic model (NULL means a constant model); the length of this vector should be one shorter than the Q-matrix list, sorted from oldest to youngest.

states

States of the discrete character

root_freq

A vector of 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

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 <- list(matrix(c(-1, 1, 1, -1), ncol = 2, byrow = TRUE))
states <- c("A", "B")
root_freq <- setNames(rep(0.5, 2), c("A", "B"))
one_history <- sim_history_unconditional(tree, Q, states = states, root_freq = root_freq)

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