Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sequential extinctions removing edges of trait distribution (christmas trees!) #27

Open
TGuillerme opened this issue Apr 10, 2024 · 0 comments
Labels
simulation template Share your simulation template

Comments

@TGuillerme
Copy link
Owner

My simulation

This simulation template generates a tree with one trait and four sequential extinction events that remove each time 25% of the species with the highest and lowest trait values. It also incidentally make it look like a christmas tree!

What does it do?

What function does it uses? yes/no comments
Uses make.bd.params
Uses make.traits
Uses make.modifications
Uses make.events multiple sequential events

bd.params

High speciation parameters to create a bushy tree.

my_bd.params <- make.bd.params(speciation = 1.5, extinction = 0.2)

traits

Default BM trait

my_traits <- make.traits()

events

This event triggers 4 times (every one unit of time) and removes 25% of the extreme valued species

## The triggering conditions (every year)
trigger.year1 <- age.condition(x = 1, condition = `>=`)
trigger.year2 <- age.condition(x = 2, condition = `>=`)
trigger.year3 <- age.condition(x = 3, condition = `>=`)
trigger.year4 <- age.condition(x = 4, condition = `>=`)

## Trimming the tree
trim.the.tree <- function(bd.params, lineage, trait.values) {
    ## Get all the trait values
    parent_traits <- parent.traits(trait.values, lineage,  current = FALSE)

    ## Measure the spread of these values
    boundaries <- sort(range(parent_traits[, 1]))
    spread <- diff(boundaries)
    ## Scale the boundaries to 12.5% each side
    boundaries[1] <- boundaries[1] + spread*0.125
    boundaries[2] <- boundaries[2] - spread*0.125

    ## Select all the nodes that are not the boundary
    selected_nodes <- as.numeric(names(which(!(parent_traits[, 1] <= boundaries[2] & parent_traits[, 1] >= boundaries[1]))))

    ## Make them extinct
    extinct <- which(lineage$parents %in% selected_nodes)
    ## Update the lineage object
    lineage$livings <- lineage$livings[!lineage$livings %in% extinct]
    lineage$n <- length(lineage$livings)
    return(lineage)
}

## Make christmas events
christmas <- make.events(target = "taxa",
                         condition = trigger.year1,
                         modification = trim.the.tree,
                         event.name = "year1")
christmas <- make.events(target = "taxa",
                         condition = trigger.year2,
                         modification = trim.the.tree,
                         event.name = "year2",
                         add = christmas)
christmas <- make.events(target = "taxa",
                         condition = trigger.year3,
                         modification = trim.the.tree,
                         event.name = "year3",
                         add = christmas)
christmas <- make.events(target = "taxa",
                         condition = trigger.year4,
                         modification = trim.the.tree,
                         event.name = "year4",
                         add = christmas)

A running example

## My favorite seed
set.seed(19)

## Some stopping rules
my_stop.rule <- list(max.time = 5)

## The simulation
my_simulation <- treats(stop.rule = my_stop.rule,
                        bd.params = my_bd.params,
                        traits    = my_traits,
                        events    = my_events)

plot(my_simulation)

Reference

If you use this template in a publication, please cite:

  • treats
  • R
@TGuillerme TGuillerme added the simulation template Share your simulation template label Apr 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
simulation template Share your simulation template
Projects
None yet
Development

No branches or pull requests

1 participant