make.trait.model.Rd
Create a model that dictates how a discrete or continuous trait evolves and affects the diversification of the phylogeny. This function creates a list that dictates how the trait affects hybridizations, how the trait is changes over time, and how the trait is inherited across speciation and hybridization events.
make.trait.model(
initial_states,
hyb.event.fxn,
hyb.compatibility.fxn,
time.fxn = NULL,
spec.fxn = NULL
)
the initial state on the phylogeny. if simulating networks with twolineages=TRUE
then a vector of length two will be required.
A function that describes how the trait changes after hybridization events. See Details for more information
A function that describes whether hybridization events can occur between taxa based on their trait values. See Details for more information
A function that describes how trait values changes over time. See Details for more information
A function that describes how trait values change at speciation events. See Details for more information
A model for trait evolution to be used as the trait.model
argument in a `sim.bdh function``
hyb.event.fxn
is a function that denotes the trait value of a hybrid child after a hybridization event. The function should have the argument parent_states
, a vector with the trait states of the two parents to the hybrid child and inheritance
. parent_states
is vector with the states of the hybrid parents while inheritance
is the inheritance probability of the first lineage denoted in parent_states
. The function should return a single value for the trait state of the hybrid child.
hyb.compatibility.fxn
describes when hybridization events can occur between two taxa based on their trait values. The function should have the arguments parent_states
. The function should return TRUE
for when a hybridization event is allowed to proceed and FALSE
otherwise.
time.fxn
is a function that describes how trait values change over time. The function should have the arguments trait_states
and timestep
in that order. trait_states
is a vector containing the ploidy of all taxa while timestep
is the amount of time given for ploidy evolution. The function should return a vector with the updated ploidy states of all taxa.
The default value of NULL
indicates that trait values will not evolve within a lineage over time. NOTE: Values can still change at speciation or hybridization events if allowed.
spec.fxn
is a function that describes how trait values change at speciation events. The function should have the argument tip_state
which has the state of the lineage just before speciation. The function should return a vector with two values, one denoting the trait of each of the two new species after the event.
The default value of NULL
causes the two children lineage to inherit the same trait value as the parental lineage
initial_val<-2 ## The root starts off at 2N
###function for what happens at hybridization event
hyb_e_fxn <- function(parent_states,inheritance){
##For allopolyploidy we add the ploidy of both parents
return(sum(parent_states))
}
##Function for determining whether hybridization occurs
hyb_c_fxn <-function(parent_states,hybrid_state){
##Hybridization occurs only when the ploidy is the same
return(parent_states[1]==parent_states[2])
}
##Function for how the trait changes over time
t_fxn <- function(trait_states,timestep){
##We assume that autopolyploidy occur exponentially with rate lambda
lambda<- 2 ##Rate of autopolyploidy
##The number of autopolyploidy events that occur on each lineage over the timestep
nevents<-rpois(length(trait_states),timestep)
##each event doubles the ploidy
new_states<- trait_states * (2^nevents)
return(new_states)
}
##Function for how the trait changes at speciation events
s_fxn <-function(tip_state){
##Ploidy doesn't change at speciation events.
##Both daughter lineages have the same ploidy as the parent
return(c(tip_state,tip_state))
}
trait_model<-make.trait.model(initial_states = initial_val,
hyb.event.fxn = hyb_e_fxn,
hyb.compatibility.fxn = hyb_c_fxn,
time.fxn = t_fxn,
spec.fxn = s_fxn)