# NOT RUN {
# Example 1
# Generate tree, with rates evolving under Brownian motion
parameters = list(birth_rate_diffusivity = 1,
min_birth_rate_pc = 1,
max_birth_rate_pc = 2,
death_rate_diffusivity = 0.5,
min_death_rate_pc = 0,
max_death_rate_pc = 1)
simulation = generate_tree_with_evolving_rates(parameters,
rate_model='BM',
max_tips=1000,
include_rates=TRUE)
tree = simulation$tree
Ntips = length(tree$tip.label)
# plot per-capita birth & death rates of tips
plot( x=simulation$birth_rates_pc[1:Ntips],
y=simulation$death_rates_pc[1:Ntips],
type='p',
xlab="pc birth rate",
ylab="pc death rate",
main="Per-capita birth & death rates across tips (BM model)",
las=1)
######################
# Example 2
# Generate tree, with rates evolving under a binary-state model
Q = get_random_mk_transition_matrix(Nstates=2, rate_model="ER", max_rate=0.1)
parameters = list(Nstates = 2,
state_birth_rates = c(1,1.5),
state_death_rates = 0.5,
transition_matrix = Q)
simulation = generate_tree_with_evolving_rates(parameters,
rate_model='Mk',
max_tips=1000,
include_rates=TRUE)
tree = simulation$tree
Ntips = length(tree$tip.label)
# plot distribution of per-capita birth rates of tips
rates = simulation$birth_rates_pc[1:Ntips]
barplot(table(rates)/length(rates),
xlab="rate",
main="Distribution of pc birth rates across tips (Mk model)")
# }
Run the code above in your browser using DataLab