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

Generate a trait from ordinated empirical data #28

Open
TGuillerme opened this issue May 13, 2024 · 0 comments
Open

Generate a trait from ordinated empirical data #28

TGuillerme opened this issue May 13, 2024 · 0 comments
Labels
simulation template Share your simulation template

Comments

@TGuillerme
Copy link
Owner

Generate a trait from ordinated empirical data

This simulation template generates tree with a Brownian Motion trait with a decreasing variance for each trait to look like ordinated data.

What does it do?

What function does it uses? yes/no comments
Uses make.bd.params using crude.bd.est
Uses make.traits
Uses make.modifications
Uses make.events

bd.params

High speciation parameters to create a bushy tree.

## Load empirical data from the dispRity package
library(dispRity)
data(BeckLee_tree)
data(BeckLee_mat99)

## Estimating birth death parameters from an empirical tree
my_bd.params <- crude.bd.est(BeckLee_tree, method = "estimate")

traits

Generating a 97 dimensional process with decreasing variance per dimensions.

## Getting the number of dimensions
n_dimensions <- ncol(BeckLee_mat99)

## Calculating the variance per dimensions
variance_per_dimension <- apply(BeckLee_mat99, 2, var)/max(apply(BeckLee_mat99, 2, var))

## Creating the variance-covariance matrix (no covariance)
scale_matrix <- matrix(0, ncol = n_dimensions, nrow = n_dimensions)
diag(scale_matrix) <- variance_per_dimension

## Creating the 97D brownian motion trait
my_traits <- make.traits(process = BM.process, n = n_dimensions,
                         process.args = list(Sigma = scale_matrix))

A running example

## My favorite seed
set.seed(9)

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

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

## The tree
plot(my_simulation)

## Show the simulated variance
simulated_variance <- apply(my_simulation$data, 2, var)/max(apply(my_simulation$data, 2, var))
plot(simulated_variance, ylab = "scaled_variance")
lines(y = variance_per_dimension, x = 1:97)
legend(x = "topright", pch = c(21, NA), lty = c(NA, 1), legend = c("simulated", "observed"))

Reference

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

  • treats
  • R
@TGuillerme TGuillerme added the simulation template Share your simulation template label May 13, 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