test = FALSE
if(test){
data(InfTemp)
# \donttest{
## Comparison between models
## require(phytools)
data(InfTemp)
set.seed(1)
tree <- pbtree(n=150, scale=67)
tree <- reorder(tree, "postorder")
beta = -0.2 # strengh and direction of the climatic effect
# The (latent) trait is simulated using the function "sim_t_env" (see also ?fit_t_env)
x <- sim_t_env(tree, param=c(0.1, beta), env_data=InfTemp, model="EnvExp", root.value=0,
step=0.001, plot=TRUE)
# Use the "threshState" function to simulate the discrete traits from the continuous one 'x'.
th <- sapply(x, threshState, thresholds = setNames(c(0,Inf), letters[1:2]))
# Fit the climatic model
clim_fit1 <- fit_t_thresh(tree, th, model="Clim", env_data=InfTemp, df=50)
plot(clim_fit1, lty=2)
clim_fit2 <- fit_t_thresh(tree, th, model="Clim", env_data=InfTemp, df=10)
lines(clim_fit2, col="red")
# }
}
Run the code above in your browser using DataLab