sim_t_env {RPANDA} | R Documentation |
Recursive simulation (root-to-tip) of the environmental model
Description
Simulates datasets for a given phylogeny under the environmental model (see ?fit_t_env)
Usage
sim_t_env(phylo, param, env_data, model, root.value=0, step=0.001, plot=FALSE, ...)
Arguments
phylo |
An object of class 'phylo' (see ape documentation) |
param |
A numeric vector of parameters for the user-defined climatic model. For the EnvExp and EnvLin, there is only two parameters. The first is sigma and the second beta. |
env_data |
Environmental data, given as a time continuous function (see, e.g. splinefun) or a data frame with two columns. The first column is time, the second column is the environmental data (temperature for instance). |
model |
The model describing the functional form of variation of the evolutionary rate |
root.value |
A number specifying the trait value for the ancestor |
step |
This argument describe the length of the segments to simulate across for the phylogeny. The smaller is the segment, the greater is the accuracy of the simulation at the expense of the computation time. |
plot |
If TRUE, the simulated process is plotted. |
... |
Arguments to be passed through. For instance, "col" for plot=TRUE. |
Details
The users defined function is simulated forward in time i.e.: from the root to the tips. The speed of the simulations might depend on the value used for the "step" argument. It's possible to estimate the traits with the MLE from another fitted object (see the example below).
Value
A named vector with simulated trait values for n
species in the phylogeny
Author(s)
J. Clavel
References
Clavel, J. & Morlon, H., 2017. Accelerated body size evolution during cold climatic periods in the Cenozoic. Proceedings of the National Academy of Science, 114(16): 4183-4188.
See Also
plot.fit_t.env
,
likelihood_t_env
Examples
if(test){
data(Cetacea)
data(InfTemp)
set.seed(123)
# define the parameters
param <- c(0.1, -0.5)
# define the environmental function
my_fun <- function(t, env, param){ param[1]*exp(param[2]*env(t))}
# simulate the trait
trait <- sim_t_env(Cetacea, param=param, env_data=InfTemp, model=my_fun, root.value=0,
step=0.001, plot=TRUE)
# fit the model to the simulated trait.
fit <- fit_t_env(Cetacea, trait, env_data=InfTemp, model=my_fun, param=c(0.1,0))
fit
# Then use the results from the previous fit to simulate a new dataset
trait2 <- sim_t_env(Cetacea, param=fit, step=0.001, plot=TRUE)
fit2 <- fit_t_env(Cetacea, trait2, env_data=InfTemp, model=my_fun, param=c(0.1,0))
fit2
# When providing the environmental function:
if(require(pspline)){
spline_result <- sm.spline(x=InfTemp[,1],y=InfTemp[,2], df=50)
env_func <- function(t){predict(spline_result,t)}
t<-unique(InfTemp[,1])
# We build the interpolated smoothing spline function
env_data<-splinefun(t,env_func(t))
# provide the environmental function to simulate the traits
trait3 <- sim_t_env(Cetacea, param=param, env_data=env_data, model=my_fun,
root.value=0, step=0.001, plot=TRUE)
fit3 <- fit_t_env(Cetacea, trait3, env_data=InfTemp, model=my_fun, param=c(0.1,0))
fit3
}
}