| make.events {treats} | R Documentation |
make.events
Description
Making events objects for treats
Usage
make.events(
target,
condition,
modification,
add,
test = TRUE,
event.name,
replications = 0,
additional.args
)
Arguments
target |
What to modify, can be |
condition |
A |
modification |
A |
add |
Another |
test |
A |
event.name |
Optional, a |
replications |
A numeric or integer value for repeating the event (by default, the event is not repeated: |
additional.args |
Optional, a named |
Details
target is a character to designate what will be affected by the event. It can be either "taxa", "bd.params", "traits" or "modifiers". This means that the condition and modification functions will target this specific part of the algorithm.
condition must be a function that returns a logical value and intakes any of the following arguments: bd.params, lineage, traits and time. See events.conditions for examples.
modification must be a function that intakes a first argument named "x" an returns any specific type of class that can be handled internally by treats. For example, if target = "bd.params" the modification function should typically return an updated bd.params object (see make.bd.params). See events.modifications for examples.
Value
This function outputs a treats object that is a named list of elements handled internally by the treats function.
Author(s)
Thomas Guillerme
See Also
treats make.bd.params make.traits make.modifiers events.conditions events.modifications
Examples
## Generating a mass extinction
## 80% mass extinction at time 4
mass_extinction <- make.events(
target = "taxa",
condition = age.condition(4),
modification = random.extinction(0.8))
## Set the simulation parameters
stop.rule <- list(max.time = 5)
bd.params <- list(extinction = 0, speciation = 1)
## Run the simulations
set.seed(123)
results <- treats(bd.params = bd.params,
stop.rule = stop.rule,
events = mass_extinction)
## Plot the results
plot(results, show.tip.label = FALSE)
axisPhylo()
## Changing the trait process
## The 95% upper quantile value of a distribution
upper.95 <- function(x) {
return(quantile(x, prob = 0.95))
}
## Create an event to change the trait process
change_process <- make.events(
target = "traits",
## condition is triggered if(upper.95(x) > 3)
condition = trait.condition(3, condition = `>`, what = upper.95),
modification = traits.update(process = OU.process))
## Set the simulation parameters
bd.params <- list(extinction = 0, speciation = 1)
stop.rule <- list(max.time = 6)
traits <- make.traits()
## Run the simulations
set.seed(1)
no_change <- treats(bd.params = bd.params,
stop.rule = stop.rule,
traits = traits)
set.seed(1)
process_change <- treats(bd.params = bd.params,
stop.rule = stop.rule,
traits = traits,
events = change_process)
## Plot the results
oldpar <- par(mfrow = c(1,2))
plot(no_change, ylim = c(-7, 7))
plot(process_change, ylim = c(-7, 7))
par(oldpar)