| events.conditions | R Documentation |
Inbuilt conditions functions for helping designing events
events.condition(x, condition, ...)
x |
the variable to reach for satisfying a condition (see details) |
condition |
the logical function for triggering the condition (e.g. '<', '==', '!>', etc...). |
... |
any optional argument specific for that condition (see details) |
The following functions allow to design specific conditions for events:
age.condition: a conditional function based on the time x. Typically this can be translated into "when time reaches the value x, trigger a condition" (see make.events). There is no optional argument for the function.
taxa.condition: a conditional function based on the number of taxa x. Typically this can be translated into "when the number of taxa reaches the value x, trigger a condition" (see make.events). This function has one optional argument:
living, a logical argument whether to consider the number of taxa alive when the condition is checked (default: living = TRUE) or whether to consider all the taxa simulated so far (living = FALSE).
trait.condition: a conditional function based on the value x of one or more traits. Typically this can be translated into "when a trait reaches a value x, trigger a condition" (see make.events). This function has three optional argument:
trait, one or more integer or numeric value designating the trait(s) to consider. By default, trait = 1, thus considering only the first trait to trigger the condition.
what, a function designating what to select from the trait values. By default what = max to select the maximal value of the trait when the condition is triggered (but you can use any function like min, mean, sd, etc. or provide your own function).
absolute, a logical designating to consider absolute trait values (TRUE) or not (default; FALSE).
More details about the events functions is explained in the treats manual: http://tguillerme.github.io/treats.
This function outputs a "function" to be passed to make.events.
Thomas Guillerme
treats make.events events.modifications
## 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.