events.conditions {treats} | R Documentation |
events.conditions
Description
Inbuilt conditions functions for helping designing events
Usage
events.condition(x, condition, ...)
Arguments
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) |
Details
The following functions allow to design specific conditions for events:
age.condition
: a conditional function based on the timex
. Typically this can be translated into "when time reaches the value x, trigger a condition" (seemake.events
). There is no optional argument for the function.taxa.condition
: a conditional function based on the number of taxax
. Typically this can be translated into "when the number of taxa reaches the value x, trigger a condition" (seemake.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 valuex
of one or more traits. Typically this can be translated into "when a trait reaches a value x, trigger a condition" (seemake.events
). This function has three optional argument:trait, one or more
integer
ornumeric
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 defaultwhat = max
to select the maximal value of the trait when the condition is triggered (but you can use any function likemin
,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.
Value
This function outputs a "function"
to be passed to make.events
.
Author(s)
Thomas Guillerme
See Also
treats
make.events
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)