# NOT RUN {
# Also see vignette("Analyzing_rates_of_evolution").
# }
# NOT RUN {
# Generating a tree with 500 species
set.seed(102)
tree <- ape::rtree(n = 500)
tree <- ape::chronopl(tree, lambda = 1, age.min = 1)
### model = 'predictor_BM' ###
sim_data <- simulate_rate(tree,
startv_x = 0, sigma_x = 0.25, a = 1, b = 1, model =
"predictor_BM"
)
head(sim_data$tips)
gls_mod <- rate_gls(
x = sim_data$tips$x, y = sim_data$tips$y,
species = sim_data$tips$species, tree, model = "predictor_BM"
)
gls_mod$param
par(mfrow = c(1, 2))
# Response shown on the standard deviation scale (default):
plot(gls_mod, scale = "SD", cex.legend = 0.8)
# Response shown on the variance scale, where the regression is linear:
plot(gls_mod, scale = "VAR", cex.legend = 0.8)
par(mfrow = c(1, 1))
# Parametric bootstrapping to get the uncertainty of the parameter estimates
# taking the complete process into account.
# (this takes some minutes)
gls_mod_boot <- rate_gls_boot(gls_mod, n = 1000)
gls_mod_boot$summary
### model = 'predictor_gBM' ###
sim_data <- simulate_rate(tree,
startv_x = 1, sigma_x = 1, a = 1, b = 1,
model = "predictor_gBM"
)
head(sim_data$tips)
gls_mod <- rate_gls(
x = sim_data$tips$x, y = sim_data$tips$y, species = sim_data$tips$species,
tree, model = "predictor_gBM"
)
gls_mod$param
plot(gls_mod)
par(mfrow = c(1, 2))
# Response shown on the standard deviation scale (default):
plot(gls_mod, scale = "SD", cex.legend = 0.8)
# Response shown on the variance scale, where the regression is linear:
plot(gls_mod, scale = "VAR", cex.legend = 0.8)
# is linear.
par(mfrow = c(1, 1))
# Parametric bootstrapping to get the uncertainty of the parameter estimates
# taking the complete process into account. (This takes some minutes.)
gls_mod_boot <- rate_gls_boot(gls_mod, n = 1000)
gls_mod_boot$summary
### model = 'recent_evol' ###
sim_data <- simulate_rate(tree,
startv_x = 0, sigma_x = 1, a = 1, b = 1, sigma_y = 1,
model = "recent_evol"
)
head(sim_data$tips)
gls_mod <- rate_gls(
x = sim_data$tips$x, y = sim_data$tips$y, species = sim_data$tips$species,
tree, model = "recent_evol", useLFO = FALSE
)
# useLFO = TRUE is somewhat slower, and although more correct it should give
# very similar estimates in most situations.
gls_mod$param
par(mfrow = c(1, 2))
# Response shown on the standard deviation scale (default):
plot(gls_mod, scale = "SD", cex.legend = 0.8)
# Response shown on the variance scale, where the regression is linear:
plot(gls_mod, scale = "VAR", cex.legend = 0.8)
# linear.
par(mfrow = c(1, 1))
# Parametric bootstrapping to get the uncertainty of the parameter estimates
# taking the complete process into account. Note that x is considered as
# fixed effect. (This takes a long time.)
gls_mod_boot <- rate_gls_boot(gls_mod, n = 1000, useLFO = FALSE)
gls_mod_boot$summary
# }
Run the code above in your browser using DataLab